PDA

View Full Version : ActionScript 2 to 3. Please help!


highway81
05-14-2008, 10:51 PM
hey,

i have just started studying actionscript 3 at college and need some help migrating some script from 2 to 3. any help would be greatly appreciated:


ryu_mc.step=15;
ryu_mc.attack = false;
ryu_mc.stance= 1;
ryu_mc.crouch=false;


this.onEnterFrame = function()
{
if(ryu_mc.attack==false)
{
if (Key.isDown (Key.RIGHT) )
{
ryu_mc._xscale = 100;
ryu_mc.stance=1;
ryu_mc._x+=ryu_mc.step;
ryu_mc.gotoAndStop("walking");
}
else if (Key.isDown (Key.LEFT) )
{
ryu_mc._xscale = -100;
ryu_mc.stance=0;
ryu_mc._x-=ryu_mc.step;
ryu_mc.gotoAndStop("walking");
}
}
}


it is simply script in AS2 to ajke a character move left and right on the key getting pressed. any help igrating this to AS3 would be appreciated.

thanks

TomMalufe
05-15-2008, 02:47 AM
The great thing about AS3 that you should start to practice right away is custom classes.

I'm assuming that you will link your Ryu MovieClip to the class Ryu. I've just rewritten your AS2 code as an AS3 class:

package {
import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Keyboard;

public class Ryu extends MovieClip {
protected var step:Number;
protected var attack:Boolean;
protected var stance:int;
protected var crouch:Boolean;

public function Ryu() {
step = 15;
attack = false;
stance = 1;
crouch = false;

this.addEventListener(KeyboardEvent.KEY_DOWN, KeyDownHandler);
}

protected var KeyDownHandler(event:KeyboardEvent):void {
if(!attack){
if(event.keyCode == Keyboard.RIGHT) {
this.scaleX = 1;
this.stance = 1;
this.x += step;
this.gotoAndStop("walking");
} else if (event.keyCode == Keyboard.LEFT) {
this.scaleX = -1;
this.stance = 0;
this.x -= step;
this.gotoAndStop("walking");
}
}
}
}
}

And there you go. I really shouldn't do so much for people... I'm only hurting your learning curve by doing this for you.

TomMalufe
05-15-2008, 02:53 AM
You know, the re-write of the code I just gave you is going to have a little bug in the movement of your character...

Check out this tutorial I wrote on my home page: http://www.clickpopmedia.com/2008/04/04/spring-animation-with-actionscript-3/
It covers all the basics for making a little game with no objective.

highway81
05-15-2008, 09:38 AM
thank you very much pal thats very much appreciated