10/9/2010 9:40:47 AM
Title:
View States problem
hello everyone, I am new in Flex and i am using it in my academic project.
My problem is related with the vies states...
I have read various online materials to define view states at the root of an application or at the root of a custom component and switch the states accordingly. But i need to change the view state defined at the root of an application via the controls defined in a custom component...
I have defined 5 view states and 3 of the states contains the custom component. I need to switch the view state from the controls (button in my case) defined in the custom component.
I am badly stuck with this problem. If there is any solution or alternatives, please let me know...
10/10/2010 10:21:50 AM
you can change the state at root of application using following syntax from anywhere of the application
Application.application.currentState='StateName';
10/11/2010 9:27:06 AM
Gt_ebuddy-->did that worked, Manoj?
10/11/2010 11:24:49 AM
@ Mr. Rex
As you suggested, I wrote my button click handling code as:
click = "Application.application.currentState='StateName';"
but it generates an error : Access of undefined property Application
Did I write the code in a right way ? if yes, what does the error signifies ? Do i have to write additional code to somewhere else ?
Your kind suggestions are always appreciated...
10/11/2010 8:58:41 PM
which compiler are you using Flex3 or Flex4 , the above code is for flex3 compiler for flex4 you need to write
FlexGlobals.topLevelApplication.currentState='StateName';
10/12/2010 1:14:00 AM
Here is an example..
It may help u much better
<fx:Script>
<![CDATA[
protected function buttonClickHander(event:MouseEvent):void
{
mainStack.selectedIndex=1;
}
]]>
</fx:Script>
<!--change the selectedindex as per ur req-->
<mx:ViewStack id="mainStack" selectedIndex="0">
<s:NavigatorContent>
<s:Panel id="panel1"/>
</s:NavigatorContent>
<s:NavigatorContent>
<!-- custom component in viewstack-->
<comp:Component1 id="comp1"/>
</s:NavigatorContent>
</mx:ViewStack>
and here is the code of component1 with button
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
protected function goButton_clickHandler(event:MouseEvent):void
{
FlexGlobals.topLevelApplication.buttonClickHander(event);
}
]]>
</fx:Script>
<s:Button id="button1" click="goButton_clickHandler(event)"/>
So, it will contact the function of main Class and change the property
10/12/2010 5:22:12 AM
@ Mr. Rex and Shrikumar
Now, my code works properly.
Thank you very very much...
I didn't use the concept of ViewStack. Rather, I managed this problem by writing the following simple code in my custom component.
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
private function gotoLoginState():void
{
FlexGlobals.topLevelApplication.currentState='LoginState';
}
private function gotoSignupState():void
{
FlexGlobals.topLevelApplication.currentState='SignupState';
}
]]>
</fx:Script>
<s:Button label="Login"
x="189" y="11"
width="82" height="26"
click="gotoLoginState()" />
<s:Button label="Sign up"
x="329" y="10"
width="82" height="26"
click="gotoSignupState()" />