on (press) {
this.swapDepths(_root.getNextHighestDepth());
this.startDrag();
}
on (release) {
stopDrag();
if (eval(this._droptarget) == _parent.target4) {
this._x = _parent.target4._x;
this._y = _parent.target4._y;
this._xscale = 100;
this._yscale = 100;
this.enabled = false;
_parent.success++;
if (_parent.success == _parent.no_piece) {
_root.gotoAndPlay("completed");
}
} else {
this._x = random(230)+380;
this._y = random(320)+80;
}
}
-
- on (press) {
- this.swapDepths(_root.getNextHighestDepth());
- this.startDrag();
- }
- on (release) {
- stopDrag();
- if (eval(this._droptarget) == _parent.target4) {
- this._x = _parent.target4._x;
- this._y = _parent.target4._y;
- this._xscale = 100;
- this._yscale = 100;
- this.enabled = false;
- _parent.success++;
- if (_parent.success == _parent.no_piece) {
- _root.gotoAndPlay("completed");
- }
- } else {
- this._x = random(230)+380;
- this._y = random(320)+80;
- }
- }
-
Instead of using on(press) and on(release) you would want to add an event listener and listen for the MouseEvent.MOUSE_DOWN and MouseEvent.MOUSE_UP events and then create functions for each like so:
this.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
this.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
function onMouseDown(e:MouseEvent):void
{
//put on(press) code here
}
function onMouseUp(e:MouseEvent):void
{
//put on(release) code here
}
-
- this.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
- this.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
-
- function onMouseDown(e:MouseEvent):void
- {
- //put on(press) code here
- }
-
- function onMouseUp(e:MouseEvent):void
- {
- //put on(release) code here
- }
-
Also if you want to be completely in AS3.0 you can get rid of all of the preceding underscores so:
_x = x (example: this._x now should be this.x)
_y = y
_parent = parent
_root = root
the _droptarget, _xscale, and _yscale I am unfamiliar with but I assume it follows the same guidelines.
The random(n) function should now use Math.random() which returns a random number between 0 and 1 which can be scaled from there by multiplying it by a number which would give you your range. This returns a decimal number however and would need to be rounded to give you an integer.
I believe the rest should work.