Actionscript 3.0 拖动加载程序图像但出现无法将其转换为影片剪辑的错误

发布于 2024-10-01 04:39:48 字数 677 浏览 7 评论 0原文

我有一个将外部图像加载到舞台中的脚本(我在其他地方有 addChild() 脚本),但我不断收到错误消息:

TypeError:错误#1034:类型强制失败:无法转换 flash.display::Loader@b1b7101 到 flash.display.MovieClip。在 project1_fla::MainTimeline/drag()

var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://i54.tinypic.com/anom5d.png"));
my_loader.addEventListener(MouseEvent.MOUSE_DOWN, drag);

function drag(event:MouseEvent):void{
 var my_loader:MovieClip = MovieClip(event.target);
 my_loader.startDrag()
 my_loader.scaleX = my_loader.scaleY = .95;

我该怎么做才能使图像可拖动? *(当swf启动时图像会加载,但图像不会加载,因为我将addChild()放在if()语句中。是否因为图像未加载,所以它不能是影片剪辑? )

I have a script that loads an external image into the stage(I have the addChild() script somewhere else) but I keep getting an error that says:

TypeError: Error #1034: Type Coercion failed: cannot convert
flash.display::Loader@b1b7101 to flash.display.MovieClip. at
project1_fla::MainTimeline/drag()

var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://i54.tinypic.com/anom5d.png"));
my_loader.addEventListener(MouseEvent.MOUSE_DOWN, drag);

function drag(event:MouseEvent):void{
 var my_loader:MovieClip = MovieClip(event.target);
 my_loader.startDrag()
 my_loader.scaleX = my_loader.scaleY = .95;

What I do to make the image draggable?
*(The image is loaded when the swf starts but the image won't because I put the addChild() in a if() statement. Could it be that since the image isn't loaded, it can't be a movieclip?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦初醒的夏天 2024-10-08 04:39:48

以下行有几个错误。

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

首先,事件目标是 Loader 类型,因此您无法将其强制转换为 MovieClip。其次,您通常会在加载 swf 时执行这种类型的强制转换,但您正在加载 png!

 var container:Sprite = new Sprite();
 addChild( container);

 my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadingComplete);
 my_loader.load(new URLRequest("http://i54.tinypic.com/anom5d.png"));

 function onLoadingComplete(event:Event):void
 {
    container.addChild( event.currentTarget.loader.content );
    container.addEventListener(MouseEvent.MOUSE_DOWN, drag);
    //remove the listener here
 }

 function drag(event:MouseEvent):void{
     container.startDrag()
     container.scaleX =  0.95;
     container.scaleY = 0.95;
  }

There are a couple of errors with the following line.

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

Firstly , the event target is of type Loader so you won't be able to coerce it into a MovieClip. Secondly, you would typically do this type of coercion when loading a swf , but you're loading a png!

 var container:Sprite = new Sprite();
 addChild( container);

 my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadingComplete);
 my_loader.load(new URLRequest("http://i54.tinypic.com/anom5d.png"));

 function onLoadingComplete(event:Event):void
 {
    container.addChild( event.currentTarget.loader.content );
    container.addEventListener(MouseEvent.MOUSE_DOWN, drag);
    //remove the listener here
 }

 function drag(event:MouseEvent):void{
     container.startDrag()
     container.scaleX =  0.95;
     container.scaleY = 0.95;
  }
离笑几人歌 2024-10-08 04:39:48
var my_loader:Loader = new Loader();
addChild(my_loader);
my_loader.addEventListener(MouseEvent.MOUSE_DOWN, drag);
my_loader.load(new URLRequest("http://i54.tinypic.com/anom5d.png"));
function drag(event:MouseEvent):void{
 my_loader.startDrag()
 my_loader.scaleX =  0.95;
 my_loader.scaleY = 0.95;
}
var my_loader:Loader = new Loader();
addChild(my_loader);
my_loader.addEventListener(MouseEvent.MOUSE_DOWN, drag);
my_loader.load(new URLRequest("http://i54.tinypic.com/anom5d.png"));
function drag(event:MouseEvent):void{
 my_loader.startDrag()
 my_loader.scaleX =  0.95;
 my_loader.scaleY = 0.95;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文