【问题标题】:Not allowing me to add a property to a MovieClip?不允许我向 MovieClip 添加属性?
【发布时间】:2013-05-20 05:31:21
【问题描述】:
var menuButton:Array = new Array(3);    //the overarching menu buttons, these lead to a submenu

        for (i = 0; i <= 3; i++)
        {
            menuButton[i] = new BattleActionButton();   //creates the button

            menuButton[i].buttonID = i;
            if (i != 0) //if there is a previous button then it positions itself under it
            {
                menuButton[i].y = menuButton[i - 1].y + menuButton[i - 1].height;
            }
            else    //otherwise it positions itself under the lowest friendlyFrame
            {
                menuButton[i].y = friendlyFrame[4].y + friendlyFrame[4].height;
            }

            menuButton[i].addEventListener(MouseEvent.CLICK, addSubMenu);

            stage.addChild(menuButton[i]);
        }

我正在尝试为这些按钮添加一个属性,以便稍后使用 EventListener 识别它们,但我不断收到此错误:

ReferenceError:错误 #1056:无法在 BattleActionButton 上创建属性 buttonID。

在 Main/createBattleGUI()

在 Main()

感谢任何帮助。

【问题讨论】:

    标签: actionscript-3 actionscript properties movieclip


    【解决方案1】:

    您可以将 buttonID 属性添加到常规 MovieClip,因为 MovieClip 是一个动态类。如果你让你的类动态,上面的代码就可以工作,但值得注意的是,这并不理想。对于一个简单的场景,您可以侥幸成功,但它会在更大范围内影响性能。

    我建议将公共 buttonID 属性添加到您的 BattleActionButton 或使用 buttonID getter/setter 的私有属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-11
      • 2014-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多