在 ActionScript 类中调用 MXML [英] Calling MXML inside ActionScript class
本文介绍了在 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.
推荐答案
好的,系列问题:
- 另一个标签在哪里?是否有可能以某种方式使用了错误的文件?
- 哪条线路有故障?是 obj.password 还是 obj.currentState(范围问题)?
- 跟踪时会发生什么( obj );
- Where is the other tag? Is it possible that somehow the wrong file is being used?
- What line has the failure? Is it obj.password or could it be obj.currentState (a scoping issue)?
- What happens when you trace( obj );
- 当你追踪(getQualifiedClassName(obj))时会发生什么?(记得先导入flash.utils.getQualifiedClassName).
第二个跟踪应该与导入语句完全相同. - 当你追踪(obj.numChildren)时,你得到了你期望的数字吗?
- 当你追踪(obj.getChildAt(0))时,你得到一个Canvas吗?
- 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. - When you trace( obj.numChildren ), do you get the number you expect?
- When you trace( obj.getChildAt( 0 ) ), do you get a Canvas?
- 当你追踪( Canvas( obj.getChildAt( 0 ) ).getChildAt( 0 ) ) 时,你得到另一个 Canvas 吗?
- 当你追踪( Object( obj.getChildAt( 0 ) ).getChildAt( 0 ).getChildren() );
这些是我要开始的调试命令.如果得到意外结果,请在设置状态之前跟踪所有内容.如果您仍然遇到问题,请告诉我.
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屋!
查看全文