A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS2 to AS3?

  1. #1
    Member
    Join Date
    Sep 2008
    Posts
    36

    Arrow AS2 to AS3?

    I think I'm quite good with AS2 now, and I want to learn AS3.
    I know AS3 only works on the main timeline, but here is a code I'd like to see in AS3. I hope it isn't too complicated.

    Code:
    onClipEvent (load) {
    	var mousecontrol:Boolean = false;
    }
    onClipEvent (mouseDown) {
    	mousecontrol = true;
    }
    onClipEvent (mouseUp) {
    	mousecontrol = false;
    }
    onClipEvent (mouseMove) {
    	this._rotation = Math.atan2 (_root._ymouse - this._y, _root._xmouse - this._x) * 57.2;
    }
    onClipEvent (enterFrame) {
    	if (mousecontrol == true) {
    		if (Math.sqrt ((_root._xmouse - this._x) * (_root._xmouse - this._x) + (_root._ymouse - this._y) * (_root._ymouse - this._y)) > 50) {
    			this._x += 2 * Math.cos (this._rotation / 57.2);
    			this._y += 2 * Math.sin (this._rotation / 57.2);
    		}
    	} else {
    		if (Key.isDown (Key.LEFT) && Key.isDown (Key.UP)) {
    			this._rotation = -135;
    			this._x--;
    			this._y--;
    		} else if (Key.isDown (Key.LEFT) && Key.isDown (Key.DOWN)) {
    			this._rotation = 135;
    			this._x--;
    			this._y++;
    		} else if (Key.isDown (Key.RIGHT) && Key.isDown (Key.UP)) {
    			this._rotation = -45;
    			this._x++;
    			this._y--;
    		} else if (Key.isDown (Key.RIGHT) && Key.isDown (Key.DOWN)) {
    			this._rotation = +45;
    			this._x++;
    			this._y++;
    		} else if (Key.isDown (Key.LEFT)) {
    			this._rotation = 180;
    			this._x -= 2;
    		} else if (Key.isDown (Key.RIGHT)) {
    			this._rotation = 0;
    			this._x += 2;
    		} else if (Key.isDown (Key.UP)) {
    			this._rotation = -90;
    			this._y -= 2;
    		} else if (Key.isDown (Key.DOWN)) {
    			this._rotation = 90;
    			this._y += 2;
    		}
    	}
    }

  2. #2
    Senior Member
    Join Date
    Nov 2005
    Posts
    192
    for Key.isDown, see this post

    http://board.flashkit.com/board/showthread.php?t=798096

    as for the mouse/EnterFrame events, look up addEventListener in the documentation.

    basically you do

    Code:
    objectThatListens.addEventListener(EventName, functionToRun, false, 0, true)
    The extra parameters are an extra precaution for memory leaks when you remove the listener.

    Code:
    public function functionToRun(e:Event){
    ...
    }
    replace e:Event with the type of Event you are listening for. All of this is listed in the documentation.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center