-
how to use stopDrag() metod in particular area..
hello.....all
i have four movie clip blueMc,redMc and blueMcTarget ,redMcTarget....|
blueMcTarget ,redMcTarget are fixed MovieClip on stage ..
i want that when i drag my blueMc movieclip on blueMcTarget its stop..
if i drag these movie clip anywhere in stage then return the clip to its original
position ......(and want same condition with redMc)
[blueMc] [redMcTarget]
[redMc] [blueMcTarget]
-
Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var props:Dictionary;
var currObj:DisplayObject;
function init():void {
props = new Dictionary();
props[redMc]={goal:redMcTarget,bX:redMc.x,bY:redMc.y};
props[blueMc]={goal:blueMcTarget,bX:blueMc.x,bY:blueMc.y};
redMc.addEventListener(MouseEvent.MOUSE_DOWN, doDown, false, 0, true);
blueMc.addEventListener(MouseEvent.MOUSE_DOWN, doDown, false, 0, true);
}
function doDown(e:Event):void {
currObj=DisplayObject(e.currentTarget);
currObj.removeEventListener(MouseEvent.MOUSE_DOWN, doDown);
stage.addEventListener(MouseEvent.MOUSE_UP, doUp, false, 0, true);
e.currentTarget.startDrag(true);
}
function doUp(e:Event):void {
stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, doUp);
if (!currObj.hitTestObject(props[currObj].goal)) {
var myTweenX:Tween=new Tween(currObj,"x",Elastic.easeOut,currObj.x,props[currObj].bX,.5,true);
var myTweenY:Tween=new Tween(currObj,"y",Elastic.easeOut,currObj.y,props[currObj].bY,.5,true);
myTweenX.addEventListener(TweenEvent.MOTION_FINISH, inPlace, false, 0, true);
myTweenY.addEventListener(TweenEvent.MOTION_FINISH, inPlace, false, 0, true);
} else {
trace("ok");
}
}
function inPlace(e:Event):void {
e.currentTarget.removeEventListener(TweenEvent.MOTION_FINISH, inPlace);
if (e.currentTarget.obj.x==props[e.currentTarget.obj].bX&&e.currentTarget.obj.y==props[e.currentTarget.obj].bY) {
e.currentTarget.obj.addEventListener(MouseEvent.MOUSE_DOWN, doDown, false, 0, true);
}
}
init();
Last edited by dawsonk; 11-08-2010 at 12:06 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|