如何startdrag()阶段中的任何对象?

时间:2011-01-18 06:30:25

标签: actionscript-3 adobe flash-cs5

我想开始拖动位于舞台上的对象。舞台上还有一些影片剪辑也包含了很多对象。当我点击任何一个对象时,它应该是startdraged ..你有什么解决方案吗?

addEventListener(MouseEvent.MOUSE_UP, targetMC);
function targetMC(MouseEvent:Event):void
{
    var curinstance = MouseEvent.target.valueOf();
    curinstance.startDrag();
}

3 个答案:

答案 0 :(得分:0)

您可以将侦听器分配给保存其他资源的MC / Sprite或Root

root.addEventListener(MouseEvent.MOUSE_DOWN, targetMC);

你可以添加一个全局变量来查看正在移动的对象或遍历所有对象以阻止它们在鼠标上移动

或使用hypeframework调整器:

http://www.hypeframework.org/02_examples/adjuster/content/01_adjuster/

答案 1 :(得分:0)

这是答案

package 
{

    import flash.utils.getTimer;
    import flash.display.MovieClip;
    import flash.net.URLLoader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.events.ProgressEvent;
    import flash.text.GridFitType;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import fl.transitions.Tween;
    import fl.transitions.*;
    import fl.transitions.easing.*;
    import flash.text.TextField;
    import flash.geom.Rectangle;
    import flash.sampler.NewObjectSample;
    import fl.controls.DataGrid;
    import fl.controls.dataGridClasses.DataGridColumn;
    import fl.data.DataProvider;
    import fl.controls.ScrollPolicy;

    public class Main extends MovieClip
    {


        public function Main():void
        {
            var mc:MovieClip = new MovieClip();
            var mc_arr:Object = new Object();
            addChild(mc);
            for (var j:int=0; j<10; j++)
            {
                var clips:Array = [];


    var mcm:MovieClip = new MovieClip();
    mcm.graphics.drawRect(10*j,100,40,40);
    mcm.graphics.beginFill(0x000000);
    mcm.name = "mc" + j;
    addChild(mcm);



            }

        }

        public function onDown(evt:MouseEvent):void
        {
            evt.target.startDrag();
        }
        public function onUp(evt:MouseEvent):void
        {
            evt.target.stopDrag();
        }
    }

}

答案 2 :(得分:0)

这是答案..........

package 
{

    import flash.utils.getTimer;
    import flash.display.MovieClip;
    import flash.net.URLLoader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.events.ProgressEvent;
    import flash.text.GridFitType;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import fl.transitions.Tween;
    import fl.transitions.*;
    import fl.transitions.easing.*;
    import flash.text.TextField;
    import flash.geom.Rectangle;
    import flash.sampler.NewObjectSample;
    import fl.controls.DataGrid;
    import fl.controls.dataGridClasses.DataGridColumn;
    import fl.data.DataProvider;
    import fl.controls.ScrollPolicy;

    public class Main extends MovieClip
    {


        public function Main():void
        {
            var mc:MovieClip = new MovieClip();
            var mc_arr:Object = new Object();
            addChild(mc);
            for (var j:int=0; j<10; j++)
            {
                var clips:Array = [];


    var mcm:MovieClip = new MovieClip();
    mcm.graphics.drawRect(10*j,100,40,40);
    mcm.graphics.beginFill(0x000000);
    mcm.name = "mc" + j;
    addChild(mcm);



            }

        }

        public function onDown(evt:MouseEvent):void
        {
            evt.target.startDrag();
        }
        public function onUp(evt:MouseEvent):void
        {
            evt.target.stopDrag();
        }
    }

}