Drag and drop 2

Code Actionscript 2.0

Instance action

on (press) {
this.startDrag(true);
}
on (release) {
stopDrag();
if (eval(this._droptarget) == _root.whitesquare) {
this._visible = false;
// go to the big square:
_root.gotoAndPlay(10);
}
}

Code Actionscript 3.0

square.addEventListener(MouseEvent.MOUSE_DOWN, press); square.addEventListener(MouseEvent.MOUSE_UP, release); big.visible = false; stop(); function press(e:MouseEvent) { e.target.startDrag(true); } function release(e:MouseEvent) { e.target.stopDrag(); var drop = e.target.dropTarget; if (drop != null && drop.parent.name == "whitebox") { e.target.visible = false; gotoAndStop(10); } } big.visible = true;

Description

The black square will change its appearance if it is dragged and released over the white square. In Actionscript 2, the expression eval(this._droptarget) evaluates the name of the object, over which the black square is released. In Actionscript 3 e.target.dropTarget designates the same object. A big square will appear as the movie playhead goes to frame 10.

related to: Drag and drop

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share