制作加载的图像拖动操作订阅3
-
16-09-2019 - |
题
我想将图像加载到使用加载器的舞台上,然后我想使其拖动。如下所示,通过从Tilelist中进行选择来完成加载,但是我不知道在AS3中拖放,有人可以帮助我吗?我想让它尽可能简单。
这是我的代码加载图像:
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);
}
解决方案
Yuku沿着正确的线路行驶,但是您想做的是获得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();
});
}
其他提示
这是对我来说最简单的方法...
/* 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();
}
使用以下代码:
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();
}
Loader是Sprite的子类,因此您可以使用StartDrag和Stopdrag方法。
例如:
charge1.addEventListener("mouseDown", function() {
charge1.startDrag();
});
stage.addEventListener("mouseUp", function() {
charge1.stopDrag();
});
不隶属于 StackOverflow