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.