基本的ActionScript帮助?

时间:2009-07-31 19:05:33

标签: actionscript

我有一个MXML文件和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");
        }


    }
}

3 个答案:

答案 0 :(得分:0)

您可以使用mxml-component的'id'来调用它...例如username.text = "whatever";

答案 1 :(得分:0)

你需要让mxml和as3类文件互相认识。 在myClass文件中,您需要引用'id =“username”'的TextInput。 怎么样?我应该将loginCheck函数访问propoerty从“private”更改为“public”:

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帮助

答案 2 :(得分: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");
    }


}
}