在视图堆栈中的页面之间发送数据

时间:2010-02-22 14:22:02

标签: flex

我的语言不是最好的,所以试着去理解我。

我有一个登录页面(工作正常),如果细节正确,我想转到欢迎页面,并显示用户的名字和最后一个。

可以访问另一页中的标签,我该怎么做 请?

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

 <mx:Script>
  <![CDATA[

   import mx.rpc.events.ResultEvent;
   import mx.rpc.events.FaultEvent;
   import mx.controls.Alert;

   [Bindable] public var user:User;
   private function resultHandler(event:ResultEvent):void
   {
    // Is corroect to that :
    welLabel.text ="Hello "+ event.result.firstName +" "+ event.result.lastName + ", Welcome to BSRM";
    myApp.selectedChild=welcomePage;

   }

   private function faultHandler(event:FaultEvent):void
   {
    myApp.selectedChild=errorPage;
   }

  ]]>
 </mx:Script>

 <mx:RemoteObject id="ro" destination="loginService" fault="faultHandler(event)">
  <mx:method name="Login" result="resultHandler(event)"/>
 </mx:RemoteObject>
<mx:VBox label="Login Page" width="325" height="220" x="210" y="157">
 <mx:ViewStack id="myApp" height="206" width="100%">
  <mx:Canvas label="Login Page" width="100%" height="100%">
   <mx:Label text="User Name" fontWeight="bold"  x="24" y="44"/>
   <mx:Button label="Login" id="login" width="76"  x="202" y="124" click="ro.Login(userName.text,password.text)"/>
   <mx:TextInput id="userName"  x="118" y="42"/>
   <mx:Label text="Password" fontWeight="bold"  x="31" y="83"/>
   <mx:TextInput id="password"  width="160" x="118" y="81"/>
   <mx:LinkButton x="54.5" y="124" label="Forget my password" click="myApp.selectedChild=forgetPassword;"/>
   <mx:LinkButton x="206" y="163" label="New user" click="myApp.selectedChild=registerPage;"/>
  </mx:Canvas>

  <mx:Canvas id="forgetPassword" label="forgetPassword" width="100%" height="100%">
   <mx:Label x="2" y="76" text="your email" fontWeight="bold" textAlign="center"/>
   <mx:TextInput x="74" y="74" width="241"/>
   <mx:Text x="50.5" y="23" text="Forget My Password" fontWeight="bold" color="#F19114" width="224" height="26" fontSize="18"/>
   <mx:Button x="252" y="104" label="Send" color="#F9AD0B"/>

  </mx:Canvas>

  <mx:Canvas id="welcomePage" label="Welcome Page" width="100%" height="100%">
   <mx:Label id="welLabel" x="116" y="81"/>
  </mx:Canvas>

  <mx:Canvas id="errorPage" label="Error Page" width="100%" height="100%">
   <mx:Label text="Invalid user name or password"  x="82" y="85"/>
  </mx:Canvas>

  <mx:Canvas id="registerPage" label="Register Page" width="100%" height="100%">
   <mx:TextInput x="140" y="29"/>
   <mx:TextInput x="140" y="59"/>
   <mx:TextInput x="140" y="89"/>
   <mx:TextInput x="140" y="119"/>
   <mx:TextInput x="140" y="149"/>
   <mx:Label x="50" y="33" text="User name:"/>
   <mx:Label x="50" y="61" text="Password :"/>
   <mx:Label x="50" y="91" text="User name:"/>
   <mx:Label x="50" y="121" text="First name:"/>
   <mx:Label x="50" y="151" text="Last name:"/>
   <mx:Button x="140" y="176" label="Send"/>
  </mx:Canvas>

 </mx:ViewStack>
</mx:VBox> 
</mx:Application>

1 个答案:

答案 0 :(得分:1)

只需提供您要访问ID的标签:

<mx:Label text="User Name" fontWeight="bold"  x="24" y="44" id="lblUName/>

然后您可以在应用的任何其他部分访问它:

<mx:Label id="welLabel" x="116" y="81" text="{lblUName.text}"/>