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

Aanval App Apple Blackberry book Cocoa Coda Conference development Eclipse Expose Facebook Flash Builder Flex Builder Gaming IDS iPad iPhone IVNUA Objective-C OS X Press publishing Security Snort snow leopard Speaking Xcode

Meta

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

Copyright © Loyal Moses