Flash CS3 - Drag And Drop (Simple Game)
Download DragAndDrop.zip
Paste this code in your AS panel . You dont need to create anything on the stage
import fl.transitions.Tween;
import fl.transitions.easing.*;
stage.frameRate=30;
var TargetCircle = CreateCircle(0x00FF00,100);
TargetCircle.x=250;
TargetCircle.y=200;
addChild(TargetCircle);
var SmallCircle = CreateCircle(0xFF6600,10);
SmallCircle.x=50;
SmallCircle.y=200;
SmallCircle.buttonMode = true;
SmallCircle.addEventListener(MouseEvent.MOUSE_DOWN,DOWNHandler);
SmallCircle.addEventListener(MouseEvent.MOUSE_UP,UPHandler);
addChild(SmallCircle);
function DOWNHandler(e:MouseEvent) {
e.target.startDrag();
}
function UPHandler(e:MouseEvent) {
e.target.stopDrag();
if (SmallCircle.hitTestObject(TargetCircle)==false) {
TweenHandler();
}
}
function CreateCircle(color:Number,radius:Number):MovieClip {
var circle:MovieClip = new MovieClip;
circle.graphics.beginFill(color,1);
circle.graphics.drawCircle(0,0,radius);
circle.graphics.endFill();
return circle;
}
function TweenHandler() {
var tweenX = new Tween(SmallCircle,"x",Regular.easeInOut,SmallCircle.x,50,1,true);
var tweenY = new Tween(SmallCircle,"y",Regular.easeInOut,SmallCircle.y,200,1,true);
}
Comments
Work from home India