尝试使用加载外部文件夹图像的xml加载图像进行拖放,但是当尝试拖动时,AS3中会出现错误

时间:2016-01-09 09:54:43

标签: actionscript-3

我正在尝试使用加载外部文件夹图像的xml加载图片进行拖放,但是当尝试拖动时,AS3中会出现错误

public function startDragging(evt:MouseEvent):void
        {
            //var ob_ldr = assets[evt.target.name]. @ OBJECT;
            var ob_ldr = Loader(evt.target.loader);
            ob_ldr.startDrag(true);

            /*var theImage:Bitmap = evt.currentTarget.content as Bitmap;
            var mc:MovieClip = new MovieClip();
            mc.addChild(theImage);
                        mc.startDrag();*/
            //  theImage.star
            // assign properties and listeners to the MovieClip here

            //base.addChild(mc);

            //var obj_mc:MovieClip = new MovieClip();
            //obj_mc = MovieClip(ob_ldr)
            //trace("ob_ldr::"+mc.name);
            //startDrag(true);
            //trace(typeof(ob_ldr));
        }

1 个答案:

答案 0 :(得分:0)

这几乎都是错的:

public function startDragging(evt:MouseEvent):void
        {
            //var ob_ldr = assets[evt.target.name]. @ OBJECT;
            var ob_ldr = Loader(evt.target.loader); //This evt targeting MouseEvent 
//u cant target loader from here.
            ob_ldr.startDrag(true);
//also before dragging u need add ur obj to stage.
    }

我相信您的代码应该是这样的。

var loadedMC:Sprite = new Sprite();
loader.addEventListener(Event.COMPLETE, onLoadCompleteFunction);
function onLoadCompleteFunction(e:Event):void
{
    loadedMC = e.target.data;
    this.addChild(loadedMC);
    loadedMC.addEventListener(MouseEvent.MOUSE_DOWN, onMDown);
    loadedMC.addEventListener(MouseEvent.MOUSE_UP, onMUp);
}
function onMDown(e:MouseEvent):void
{
    e.currentTarget.startDrag(true);
}
function onMUp(e:MouseEvent):void
{
    e.currentTarget.stopDrag();
}

如果你需要更多帮助。在此下输入。我将尝试检查此评论:)