Drag and drop

Code Actionscript 2.0

Instance action

on (press) {
this.startDrag(true);
}
on (release) {
stopDrag();
if (eval(this._droptarget) == _root.whitesquare) {
this._visible = false;
}
}

Code Actionscript 3.0

square.addEventListener(MouseEvent.MOUSE_DOWN, press); square.addEventListener(MouseEvent.MOUSE_UP, release); 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; } }

Description

The black square will disappear 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. If this is the white square, its visibility is turned off.

related to: Collision

Download

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


Share