Selecting a Flex viewstack by canvas name / id

Posted on 12 August 2008

A helpful tip for those who are writing more loosely coupled code these days.

We all understand how selecting a viewstack by index can be a problem later on down the road when you decide to add new stacks or reorganize them. Doing so causes a chain reaction of refactoring MXML and AS to match your new stack order.

The following little snippet can help alleviate this:

[code lang=”actionscript”]viewstack1.selectedIndex = viewstack1.getChildIndex(viewstack1.getChildByName(“one”));[/code]

This selects the viewstack canvas by the matching id property of “one”, assuming your viewstack is named “viewstack1”.

Enjoy.


Responses are closed for this post.

Recent Posts

Tag Cloud

3D Printing Aanval App Apple Badger Mt. Beef book Calf Cattle Cows development Eclipse F-250 F-450 Flex Builder Ford Gaming Horse House Hunting IDS iPad iPhone John Deere King Ranch mac Moses Family Moses Ranch off-grid Offgrid Outback Property Ranch Reining Riding Security Snort Snow Storm Tractor Trailer Truck VFX Weather Xcode

Meta

Loyal Moses is proudly powered by WordPress and the SubtleFlux theme.

Copyright © Loyal Moses