2009-07-31 20 views
0

Ich habe eine MXML-Datei und ActionScript-Klasse ...Grundlegende ActionScript-Hilfe?

Jetzt habe ich eine Komponente textInput in meinem MXML, wie würde ich dies in meiner ActionScript-Klasse nennen.

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

Actionscript-Klasse ..

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"); 
     } 


    } 
} 

Antwort

0

Sie können es nennen, indem Sie die 'id' der mxml-Komponente ... so zum Beispiel username.text = "whatever";

0

Sie brauchen Lassen Sie mxml und as3 Klassendatei einander kennen. in myClass-Datei, benötigen Sie einen Verweis auf die TextInput, die 'ID = "Benutzername"'. wie? Ich sollte loginCheck Funktion Zugang propoerty von "privat" zu "public":

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

und in MXML-Datei sollten Sie es auf

... 
<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"/> 
... 

Link would Hilfe

0

MXML mod:

<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"); 
    } 


} 
}