0

我想使用 Loader 将图像加载到舞台,然后我想让它可拖动。加载是通过从 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);
}
4

4 回答 4

2

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();
  });

}
于 2009-04-27T08:22:43.463 回答
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();
}
于 2011-03-03T14:57:34.693 回答
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();
}
于 2009-04-27T13:22:10.763 回答
0

Loader 是 Sprite 的子类,因此您可以使用 startDrag 和 stopDrag 方法。

例如:

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

stage.addEventListener("mouseUp", function() {
    charge1.stopDrag();
});
于 2009-04-27T08:01:32.970 回答