在 ActionScript 类中调用 MXML [英] Calling MXML inside ActionScript class

查看:23
本文介绍了在 ActionScript 类中调用 MXML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 ActionScript 类中调用 MXML 组件.

How can i call MXML components inside my ActionScript Class.

//文件名.mxml

<mx:Canvas x="181" y="180" width="333">
    <mx:Button styleName="LoginButton" id="loginButton" click="checkLogin();" x="160" y="261"/>
    <mx:TextInput styleName="loginTextInput" id="username" x="160" y="161"/>
    <mx:TextInput styleName="loginTextInput" id="password" displayAsPassword="true" x="160" y="191"/>
</mx:Canvas>

//main.as [类文件]

// main.as [ Class File ]

var obj:filename= new filename();
private function label_link(evt:TextEvent):void 
{
    obj.currentState = "defaultindex";
    obj.username.text = "";
    obj.password.text = "";
}

目标

我需要在 ActionScript 类中访问 MXML 的用户名和密码字段.

I need to access the username and password fields of MXML in my ActionScript Class.

推荐答案

好的,系列问题:

  1. 另一个标签在哪里?是否有可能以某种方式使用了错误的文件?
  2. 哪条线路有故障?是 obj.password 还是 obj.currentState(范围问题)?
  3. 跟踪时会发生什么( obj );
  1. Where is the other tag? Is it possible that somehow the wrong file is being used?
  2. What line has the failure? Is it obj.password or could it be obj.currentState (a scoping issue)?
  3. What happens when you trace( obj );
  1. 当你追踪(getQualifiedClassName(obj))时会发生什么?(记得先导入flash.utils.getQualifiedClassName).
    第二个跟踪应该与导入语句完全相同.
  2. 当你追踪(obj.numChildren)时,你得到了你期望的数字吗?
  3. 当你追踪(obj.getChildAt(0))时,你得到一个Canvas吗?
  1. What happens when you trace( getQualifiedClassName( obj ) )?( remember to import flash.utils.getQualifiedClassName first ).
    The second trace should be exactly the same as the import statement.
  2. When you trace( obj.numChildren ), do you get the number you expect?
  3. When you trace( obj.getChildAt( 0 ) ), do you get a Canvas?
  1. 当你追踪( Canvas( obj.getChildAt( 0 ) ).getChildAt( 0 ) ) 时,你得到另一个 Canvas 吗?
  2. 当你追踪( Object( obj.getChildAt( 0 ) ).getChildAt( 0 ).getChildren() );

  • 换个思路——这是一个 MXML Flex 项目还是一个 Actionscript Flex 项目?(我已经看到这改变了 MXML 的处理方式).
  • 这些是我要开始的调试命令.如果得到意外结果,请在设置状态之前跟踪所有内容.如果您仍然遇到问题,请告诉我.

    These are the debugging commands I would start with. If you get unexpected results, trace everything before setting the state. Let me know if you're still stuck.

    这篇关于在 ActionScript 类中调用 MXML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆