Actionscript 3.0拖动Loader图像,但收到无法转换为动画片段的错误

我有一个脚本将外部图像加载到舞台上(我在其他地方有
addChild()
脚本)但我不断收到一条错误消息:   TypeError:错误#1034:类型强制失败:无法转换   flash.display :: Loader @ b1b7101到flash.display.MovieClip。在   project1_fla :: MainTimeline /阻力()
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()语句中而被加载。可能是因为图像没有被加载,所以它不能是一个动画片段吗? )     
已邀请:
以下行有几个错误。
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;
  }
    
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;
}
    

要回复问题请先登录注册