2009-04-27 26 views
0

我想加载一个图像使用加载程序,然后我想让它可拖动。加载是通过从tilelist中选择,如下所示,但我不知道在AS3中拖放,任何人都可以帮助我吗?我想让它尽可能简单。制作加载图像可拖动动作3

这里是我的代码加载图像:

var charge1:Loader = new Loader(); 
addChild(charge1); 
this.addChildAt(charge1, getChildIndex(bg)); 
charge1.x = 280; 
charge1.y = 270; 

... 

function setCharge1(e:Event):void{ 
    trace(e.target.selectedItem.source); 

    this.charge1.load(new URLRequest(e.target.selectedItem.source));  
    this.charge1.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete); 
} 

回答

2

欲哭正沿着正确的路线去,但你想要做的就是让的LoaderInfo的内容,这实际上是在东西装像

private function onComplete(event : Event) : void 
{ 
    var loadedClip : MovieClip = LoaderInfo(event.target).content; 

    loadedClip.addEventListener(MouseEvent.MOUSE_DOWN, function(event : MouseEvent) 
    { 
    loadedClip.startDrag(); 
    }); 

    stage.addEventListener(MouseEvent.MOUSE_UP, function(event : MouseEvent) 
    { 
     loadedClip.stopDrag(); 
    }); 

} 
剪辑。
0

装载机是雪碧的子类,所以你可以使用的startDrag和stopDrag方法。

例如:

charge1.addEventListener("mouseDown", function() { 
    charge1.startDrag(); 
}); 

stage.addEventListener("mouseUp", function() { 
    charge1.stopDrag(); 
}); 
+0

恐怕没有,因为到Adobe文档 继承:\t装载机 - >级DisplayObjectContainer - > InteractiveObject - 要>的DisplayObject - >此事件 - >对象 和你的代码给了我这样的: 错误#1069:在flash.display.Loader中找不到属性stopDrag,并且没有默认值。 – Dungeo 2009-04-27 08:07:15

+0

对不起,我在DisplayObject和Sprite之间感到困惑。希望詹姆斯海的回答可以帮助你:) – yuku 2009-04-27 08:27:25

1

使用下面的代码:

this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie); 
this.addEventListener(MouseEvent.MOUSE_UP, dropMovie); 
this.buttonMode = true; 
private function dragMovie(event:MouseEvent):void 
{ 
    this.startDrag(); 
} 

private function dropMovie(event:MouseEvent):void 
{ 
    this.stopDrag(); 
} 
2

这是最简单的方法给我...

/* Load Image */ 

var myLoader:Loader = new Loader(); 
imageContainer.addChild(myLoader); 
var url:URLRequest = new URLRequest("photo.jpg"); 
myLoader.load(url); 

/* Drag and Drop */ 

imageContainer.addEventListener(MouseEvent.MOUSE_DOWN, pickUp); 
function pickUp(event:MouseEvent):void 
{ 
imageContainer.startDrag(); 
} 
stage.addEventListener(MouseEvent.MOUSE_UP, dopIt); 

function dopIt(event:MouseEvent):void 
{ 
imageContainer.stopDrag(); 
}