actionscript-3apache-flexflex4flex3viewstack

Issue getting viewState's selected child's id in flex 4


I'm transitioning a flex 3 application to flex 4. There was AS code in the flex 3 app that worked:

var myCurrentSelectedChild:String = myViewStack.selectedChild.id;

Now, in flash builder and flex 4.5, it throws the error - "-1119: Access of possibly undefined property id through a reference with static type mx.core:INavigatorContent". I'm trying to get the viewStack's selected child's id.


Solution

  • Try to cast the myViewStack.selectedChild to some UI Object type. core:INavigatorContent has no ID property.

    So use:

    (myViewStack.selectedChild as Container).id