actionscript-3 - 为什么我在这里出现错误1118?

标签 actionscript-3 compiler-errors

在下面的代码中,我有几个都是TheBeetle()的MovieClip。它们位于另一个名为gamelevel的MovieClip中,并且也被推送到一个名为bArray的数组中。以前我已经在游戏级别为它们建立了索引,但是在调用事件侦听器之后,我无法再为它们建立索引并收到错误“1118:静态类型为Object的值隐式强制转换为可能不相关的类型flash.display:DisplayObject。”当用户单击它们时,它们死亡(并更改框架),并且尸体位于其他有生命的尸体之下,这就是我需要在它们死时将它们索引为1的原因。我了解错误说明了什么,但是我该怎么做呢?
该代码可以正常工作,但是不能在我提到的两行中使用,所以请看一下:

public function clicked (event:MouseEvent)
    {
        if (event.target is TheBeetle && event.target.currentFrame <= 2)
        {
            var mc:Object = event.target

            // TheBeetle is actually a MovieClip but i cannot write: var mc:MovieClip = event.target, if i do i receive 1118


                if (mc.currentFrame == 1)
                {
                    mc.gotoAndStop (Math.floor(Math.random() * 3 + 4));
                }
                else
                {
                    mc.gotoAndStop (3);
                }
                mc.filters = null;

                // Here i need to index the TheBeetle as i did before like gamelevel.setChildIndex(mc,1) but i'd receive 1118!

                bArray.splice (bArray.indexOf(mc),1);

                if (bArray.length == 0)
                {
                    removeEventListener (Event.ENTER_FRAME,frameHandler);
                    waveTimer.removeEventListener (TimerEvent.TIMER_COMPLETE, changeLocation);
                }
        }
    }

最佳答案

您需要将目标显式转换为MovieClip类:

var mc:MovieClip = MovieClip(event.target);

您可能需要在检查目标的currentFrame的行之前执行此操作,因为“Object”没有currentFrame方法。

关于actionscript-3 - 为什么我在这里出现错误1118?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22804716/

相关文章:

c# - 将字符串与 IEnumerable<string> 连接时会发生什么

c++ - gcc8.2 和 (intel) icc19.0.1 之间的 constexpr 差异

actionscript-3 - 对象主时间轴,对象舞台和as3中的root有什么区别?

actionscript-3 - 我如何用两个表达式(案例)在 Flex 中编写内联条件语句?

actionscript-3 - 将 MovieClip 拖动到一个圆圈

actionscript-3 - 如何从 ActionScript 中的给定字符串中检测并删除 "\n"?

c# - 在 C++ 中允许的函数在 C# 中不允许?

c++ - Visual Studio 2012 中的模板类实例化错误

java - java自动机的简单枚举

apache-flex - 如何在 AS3 中从文本创建粒子结构?