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

查看:145
本文介绍了在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的用户名和密码字段。

一系列的问题:


  1. 另一个标签在哪里?是否有可能使用错误的文件?

  2. 哪条线路出现故障?是obj.password还是它可能是obj.currentState(一个范围问题)?
  3. 当你跟踪(OBJ);


    1. 当你跟踪(getQualifiedClassName(obj))时会发生什么?(记得首先导入flash.utils.getQualifiedClassName) / em>。
      第二个跟踪应该和import语句完全一样。
    2. 当你跟踪(obj.numChildren)时,你会得到你的数字期望?

    3. 当你跟踪(obj.getChildAt(0))时,你会得到一个Canvas吗?


      1. 当你跟踪(Canvas(obj.getChildAt(0)).getChildAt(0))时,你会得到另一个Canvas吗?

      2. 当您追踪(Object(obj.getChildAt(0)).getChildAt(0).getChildren());


    4. 有点不同的想法 - 这是一个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:

      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. 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. When you trace( Canvas( obj.getChildAt( 0 ) ).getChildAt( 0 ) ), do you get another Canvas?
          2. When you trace( Object( obj.getChildAt( 0 ) ).getChildAt( 0 ).getChildren() );

      4. 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屋!

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