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

172p Aanval App Apple Blackberry boeing book cessna Cocoa Coda Conference DEFCON development Eclipse Expose Facebook final cut pro Flash Builder flex Flex Builder flight Gaming hacking IDS ios iPad iPhone IVNUA m-audio Objective-C OS X packt paine performance Press publishing Security Snort snow leopard Speaking syslog tactical flex tune-up video Xcode

Meta

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

Copyright © Loyal Moses