Timgerr, your code is assigning the value "vsTop.selectedChild =
register" to the String _runStackChild, but the expression statement
_runStackChild;
doesn't cause this string to execute... it simply causes the Player to
evaluate this (trivial) expression, which doesn't accomplish anything.
It's like writing
var s:String = "Hello";
s;
Alex showed you one approach, but it's probably a more complicated
solution than you need. Rather than specifying things like
which-viewstack and which-state by name, you should be specifying them
using object references. For example, you could simply write
<mx:Button id="btnOne" click="vsTop.selectedChild = register"/>
or, if you really want a helper method like ChangeState(), do this
<mx:Button id="btnOne" click="ChangeState(vsTop, register)"/>
public function ChangeState(vs:ViewStack, state:Container):void
{
vs.selectedChild = state;
}
Also, you seem to be using instance vars needlessly when you could
simply use local vars.
Gordon Smith
Adobe Flex SDK Team
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Tuesday, April 15, 2008 11:00 PM
To: [email protected]
Subject: RE: [flexcoders] Pass Variables and then run a command
We're not an interpreted language and don't have eval(). The best you
can probably do is something like:
this[_stackName].selectedChild = this[_stateName]
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of timgerr
Sent: Tuesday, April 15, 2008 8:16 PM
To: [email protected]
Subject: [flexcoders] Pass Variables and then run a command
Hey all, I am new with flex, coming from JavaScript and perl.
I am writing an application that will have lots of MXML components
like a login component, register component and many more. The problem
is I am trying to have all the components talk to each other, I am
having trouble doing that. This is my problem, I have a viewStack and
I created a method like this
private var _stackName:String;
private var _stateName:String;
private var _runStackChild:String;
public function ChangeState(stackName:String, stateName:String)void
{
_stackName = stackName;
_stateName = stateName;
_runStackChild = _stackName + ".selectedChild = " + _stateName ;
_runStackChild;
}
<mx:Button id="btnOne" click="ChangeState('vsTop','register');
So when I click the button the mothod ChangeState is called and passed
are the 2 variables. At the end ChangeState should run the command
vsTop.selectedChild = register;
If I clear the method and just add vsTop.selectedChild = register;,
the stack is changed, but when I run _runStackChild; nothing hapends.
What am I missing???
Thanks,
Timgerr