How to startdrag() any of the objects in the stage?
I would like to start drag objects which is located in stage.There is movie clips in the stage which also encloses so many objects.when i click on any of the object it should be startdraged..Do u have any solution?
addEventListener(MouseEvent.MOUSE_UP, targetMC);
function targetMC(MouseEvent:Event):void
{
var curinstance = Mouse开发者_如何学PythonEvent.target.valueOf();
curinstance.startDrag();
}
you can assign the listener to the MC/Sprite or Root that holds the other resource
root.addEventListener(MouseEvent.MOUSE_DOWN, targetMC);
you can add a global var to see what object is being moved or iterate through all objects to stop them from draging on mouse up
or use hypeframework adjuster:
http://www.hypeframework.org/02_examples/adjuster/content/01_adjuster/
here is the answer
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();
}
}
}
this is the answer..........
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();
}
}
}
精彩评论