Reputation: 451
I'm wondering how I would pass a value to "SelectedChild" in ViewStack:
In the example below, I am trying to set a public property in a form called "register" after I have navigated there from another form called "login".
The result I get seems to be a compilation error:
Error: Access of possibly undefined property pagename through a reference
with static type mx.core:INavigatorContent.
vsMain.selectedChild.pagename = "register page";
Any idea what the solution would be? Thank you.
<mx:Panel x="0" y="0" width="285" height="221"
layout="absolute" title="ViewStack Basic ">
<mx:ViewStack x="0" y="0" id="vsMain" width="100%" height="100%">
<mx:Canvas id="cnvLogin" label="Login" width="100%" height="100%">
<mx:Script>
public function myClick():void {
vsMain.selectedChild=cnvRegister;
vsMain.selectedChild.pagename = "register page";
}
</mx:Script>
<mx:Label x="10" y="10" text="Login Page" fontWeight="bold"/>
<mx:Label x="10" y="36" text="Username:"/>
<mx:TextInput x="85" y="34" id="txtLoginUser"/>
<mx:Label x="10" y="62" text="Password:"/>
<mx:TextInput x="85" y="60" id="txtLoginPass"/>
<mx:Button x="10" y="100" label="Login" id="butLogin"/>
<mx:LinkButton x="126" y="100" label="Need to Register?" enabled="true"
click="myClick()"/>
</mx:Canvas>
<mx:Canvas id="cnvRegister" label="Register" width="100%" height="100%">
<mx:Script>
[Bindable]
public var pagename:String;
</mx:Script>
<mx:Label x="10" y="10" text="{name}" fontWeight="bold"/>
<mx:Label x="10" y="36" text="uname"/>
<mx:TextInput x="107" y="34" id="txtRegUser" width="138"/>
<mx:Label x="10" y="62" text="Password:"/>
<mx:TextInput x="107" y="60" id="txtRegPass" width="138"/>
<mx:Label x="10" y="90" text="Password Again:"/>
<mx:TextInput x="107" y="88" id="txtRegPassAgain" width="138"/>
<mx:Button x="10" y="141" label="Register" id="butRegister"/>
<mx:LinkButton x="107" y="141" label="Already Registered?" enabled="true"
click="{vsMain.selectedChild=cnvLogin}"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Panel>
</mx:Application>
Upvotes: 0
Views: 1049
Reputation: 12847
If I'm reading it correctly, what you're trying to do is just pass data from one view in the viewstack to another view? What you should do is have a bindable data model at on the same level as the viewstack:
<fx:Script>
<![CDATA[
// Just a class with public variables where you save/bind data
[Bindable] private var _model:SomeModel;
]]>
</fx:Script>
<mx:ViewStack>
<!-- You need to create a public variables 'dataProvider' in both there views -->
<View1 dataProvider="{this._model}" />
<View2 dataProvider="{this._model}" />
</mx:ViewStack>
If you change the data in the first view, the second view will be able to see it when it gets instantiated.
Upvotes: 0
Reputation: 13327
You should move the declaration to the top element to make the variable public for the ViewStack components:
<mx:Script>
[Bindable]
public var pagename:String;
</mx:Script>
<mx:Panel x="0" y="0" width="285" height="221"
layout="absolute" title="ViewStack Basic ">
<mx:ViewStack x="0" y="0" id="vsMain" width="100%" height="100%">
...
Upvotes: 1