Actionscript 3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下行有几个错误。
首先,事件目标是 Loader 类型,因此您无法将其强制转换为 MovieClip。其次,您通常会在加载 swf 时执行这种类型的强制转换,但您正在加载 png!
There are a couple of errors with the following line.
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!