【问题标题】:AS3: Type Coercion failed: cannot convert flash.display::MovieClipAS3:类型强制失败:无法转换 flash.display::MovieClip
【发布时间】:2011-09-19 12:10:31
【问题描述】:

更新:

现在我收到此错误:

TypeError:错误 #1034:类型强制失败:无法转换 flash.display::MovieClip

来自这个班级:

package com.George.MegaAmazingApp.Components
{
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.MouseEvent;

    public class Wheel extends MovieClip
    {

        public function Wheel(area:MovieClip, diagram:MovieClip)
        {
            area.addEventListener(MouseEvent.CLICK, clickHandler);
        }
        private function clickHandler(event:MouseEvent):void
        {
            trace("wheel clicked");
            trace("this is diagram");
        }

    }

}

还有这个脚本:

import com.George.MegaAmazingApp.Components.*;

var wheel:Wheel = new Wheel(this.wheel,this.car);

调试给出:

Attempting to launch and connect to Player using URL C:/Documents and Settings/reithg/My Documents/Classes/com/GeorgesMegaAmazingApp-app.xml
[SWF] GeorgesMegaAmazingApp.swf - 51681 bytes after decompression
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@2968e51 to com.George.MegaAmazingApp.Components.Wheel.
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()
    at GeorgesMegaAmazingApp_fla::MainTimeline()
    at runtime::ContentPlayer/loadInitialContent()
    at runtime::ContentPlayer/playRawContent()
    at runtime::ContentPlayer/playContent()
    at runtime::AppRunner/run()
    at ADLAppEntry/run()
    at global/runtime::ADLEntry()

GeorgesMegaAmazingApp-app.xml 在该目录中不存在,但我不知道它为什么会在那里寻找,它不是 fla 所在的位置。

【问题讨论】:

  • 您是否尝试说import com.George.MegaAmazingApp.Components.Wheel 而不是com.George.MegaAmazingApp.Components.*
  • @Eugeny89 问题在于第一个字母的大写,因为我将文件保存为全小写...但现在我有一个新错误,正在更新第一篇文章。
  • 它没有说出现这样的弹出窗口:TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@2963e51 to com.George.MegaAmazingApp.Components.Wheel。在 flash.display::Sprite/constructChildren() 在 flash.display::Sprite() 在 flash.display::MovieClip() 在 GeorgesMegaAmazingApp_fla::MainTimeline() 在运行时::ContentPlayer/loadInitialContent() 在运行时::ContentPlayer /playRawContent() at runtime::ContentPlayer/playContent() at runtime::AppRunner/run() at ADLAppEntry/run() at global/runtime::ADLEntry()

标签: flash actionscript-3 actionscript


【解决方案1】:

this.wheelthis.car 都不是 MovieClip。您还可以在“文件”>“发布设置”中打开调试吗?然后,您将收到更好的错误消息,因为如果没有更多信息,您的错误可能几乎无处不在。

编辑:

尝试将 var wheel 重命名为其他名称,因为 Flash 似乎与您的两个轮子对象混淆了。例如,尝试:

var wheelObject:Wheel = new Wheel(this.wheel,this.car);

【讨论】:

  • [object MovieClip] [object MovieClip]trace(this.wheel); trace(this.car); 的结果
  • 好的,但到目前为止,我们所知道的是,在某处,在一条未知的线路上,某些东西不是 MovieClip。如果您打开调试,您将获得行号,并且会确切地知道您的错误在哪里(并且可能不需要询问 SO)。
  • 这些是整部电影中唯一的台词...用调试更新第一篇文章
【解决方案2】:

Wheel.as 是否在 com/George/MegaAmazingApp/Components 目录中? (区分大小写) 是源路径目录中的“com”目录吗?

【讨论】:

  • 是的,代码提示在我的其他文件中工作,所以当我输入 wheel 时,它会告诉我代码提示中需要一个区域和一个图表。
  • 没关系 w 是小写导致它失败,但是出现了一个新错误,你能看看吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-04
相关资源
最近更新 更多