2009-07-31 7 views
0

MXML 파일과 ActionScript 클래스가 있습니다.기본 ActionScript 도움말?

이제 MXML에 textInput 구성 요소가 있습니다.이 클래스를 ActionScript 클래스에서 호출하는 방법은 무엇입니까?

<mx:TextInput styleName="loginTextInput" id="username" x="160" y="161"/> 
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"); 
     } 


    } 
} 

답변

0

당신은 MXML 구성 요소의 '아이디'를 사용하여 호출 할 수 있습니다 ... 당신이 필요로하는

0

예를 username.text = "whatever"; 위해 이렇게 mxml과 as3 클래스 파일이 서로를 알게하십시오. myClass 파일에서 'id = "username"'이라는 TextInput에 대한 참조가 필요합니다. 어떻게? 나는 "개인"에서 "공공"에서 loginCheck 기능 액세스 propoerty을 변경해야합니다 :

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

및 MXML 파일에서 당신은

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

이 링크 would 도움으로 MOD한다

0

MXML :

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

:

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


} 
}