2009-07-31 9 views
0

J'ai un fichier MXML et une classe ActionScript ...Aide de base ActionScript?

Maintenant, j'ai un composant textInput dans mon MXML, comment je l'appelle dans ma classe ActionScript.

<mx:TextInput styleName="loginTextInput" id="username" x="160" y="161"/> 

classe ActionScript ..

package myClasses 
{ 

    import mx.controls.Alert; 
    import mx.events.ValidationResultEvent; 
    public class CheckLogin 
    { 
     public function CheckLogin() 
     { 
     } 

     private function loginCheck():void { 
      // I need to call the TextInput down here. 
     Alert.show("loginCheck Done"); 
     } 


    } 
} 

Répondre

0

Vous pouvez l'appeler en utilisant le 'id' MXML composants ... Ainsi, par exemple username.text = "whatever";

0

dont vous avez besoin Laissez les fichiers de classe mxml et as3 se connaître. dans le fichier myClass, vous avez besoin d'une référence à la TextInput qui 'id = "nom d'utilisateur"'. comment? Je devrais changer NVJ d'accès aux fonctions loginCheck de "privée" au "public":

public function loginCheck(username:TextInput):void 
{ 
    // trace(username.text); 
    // do some thing you like to do. 
    Alert.show("loginCheck Done"); 
} 

et dans le fichier MXML devrait-il mod

... 
<fx:Script> 
     <![CDATA[ 
     public function callme(e:MouseEvent):void 
     { 
      var checker:myClass = new myClass(); 
      checker.loginCheck(username); 
     } 


     ]]> 
    </fx:Script> 
     <mx:TextInput styleName="loginTextInput" id="username" x="160" y="161"/> 
     <s:Button label="check" click="callme"/> 
... 

ce lien would aide

0

MXML:

<mx:TextInput styleName="loginTextInput" id="username" text="@{model.username}" x="160" y="161"/> 

AS:

package myClasses 
{ 

import mx.controls.Alert; 
import mx.events.ValidationResultEvent; 
public class CheckLogin 
{ 

    private var _username:String; 

    [Bindable] 
    public function get userName():String { 
     return this._username; 
    } 

    public function set userName(value:String):void { 
     this._username = value; 
    } 

    public function CheckLogin() 
    { 
    } 

    private function loginCheck():void { 
     // I need to call the TextInput down here. 
     // access the Textinput by using this._username 
    Alert.show("loginCheck Done"); 
    } 


} 
}