在ActionScript类中调用MXML [英] Calling MXML inside ActionScript class
本文介绍了在ActionScript类中调用MXML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// filename.mxml
<$ p $ 如何在我的ActionScript类中调用MXML组件p>
< mx:Canvas x =181y =180width =333>
< mx:Button styleName =LoginButtonid =loginButtonclick =checkLogin(); x =160y =261/>
< mx:TextInput styleName =loginTextInputid =usernamex =160y =161/>
< mx:TextInput styleName =loginTextInputid =passworddisplayAsPassword =truex =160y =191/>
< / mx:Canvas>
// 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的用户名和密码字段。
- 另一个标签在哪里?是否有可能使用错误的文件?
- 哪条线路出现故障?是obj.password还是它可能是obj.currentState(一个范围问题)?
- 当你跟踪(OBJ);
- 当你跟踪(getQualifiedClassName(obj))时会发生什么?(记得首先导入flash.utils.getQualifiedClassName) / em>。
第二个跟踪应该和import语句完全一样。
- 当你跟踪(obj.numChildren)时,你会得到你的数字期望?
- 当你跟踪(obj.getChildAt(0))时,你会得到一个Canvas吗?
- 当你跟踪(Canvas(obj.getChildAt(0)).getChildAt(0))时,你会得到另一个Canvas吗?
- 当您追踪(Object(obj.getChildAt(0)).getChildAt(0).getChildren());
- 有点不同的想法 - 这是一个MXML Flex项目还是一个ActionScript脚本项目? (我已经看到了MXML处理方式的变化)。
$ b这些是我开始的调试命令。如果您得到意外的结果,请在设置状态之前跟踪所有内容。让我知道如果你仍然卡住。
How can i call MXML components inside my ActionScript Class.
// filename.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 [ Class File ]
var obj:filename= new filename(); private function label_link(evt:TextEvent):void { obj.currentState = "defaultindex"; obj.username.text = ""; obj.password.text = ""; }
Objective
I need to access the username and password fields of MXML in my ActionScript Class.
解决方案Ok, series of questions:
- 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 );
- 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?
- When you trace( Canvas( obj.getChildAt( 0 ) ).getChildAt( 0 ) ), do you get another Canvas?
- When you trace( Object( obj.getChildAt( 0 ) ).getChildAt( 0 ).getChildren() );
- What happens when you trace( getQualifiedClassName( obj ) )?( remember to import flash.utils.getQualifiedClassName first ).
- On a bit of a different line of thought -- is this an MXML Flex project or an Actionscript Flex project? (I've seen that change how MXML is handled).
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屋!
- 当你跟踪(getQualifiedClassName(obj))时会发生什么?(记得首先导入flash.utils.getQualifiedClassName) / em>。
查看全文