PDA

View Full Version : passing values from one mxml to another mxml


vijayakumar
06-30-2008, 12:21 PM
Dear All,

I have two mxml files in my flex sample. Login page (MXML Application) and Welcome Page (MXML Component). I need to transfer the values from login page to welcome page.

For Eg if i type the user name in the login page i need to access the username in the welcome page. How its possible. If possible please send me a sample code also.


Thanks in Advance.

I am waiting for your results.

Regards,
Vijayakumar B

drkstr
06-30-2008, 05:22 PM
If your data is simple and you just want a quick solution, you can try binding the variables from one to another

<com:LoginPage id="idLoginPage" />
<com:WelcomePage id="idWelcomePage" userName="{idLoginPage.userName}" />

Which assumes both LoginPage and WelcomePage is a custom component with the following code:


private var myUserName:String;

[Bindable]
public function get userName(): String {
return myUserName;
}

public function set userName( data:String ): void {
myUserName = data;
}

If in the LoginPage component you set this.userName = 'blah', it will automatically populate in the WelcomePage as well.

Also check out the MVC design pattern.


Best Regards,
~Aaron