Community

Simple As3 Help?

Posted Oct 31, '09 at 11:09pm

AdventGames

AdventGames

5 posts

Gold - Serf

I sort of just started messing around with as3 and i'm trying to get movement down but i'm having a problem with two things, for some reason the basic standing animation want play when i run it, and the speedup animation in which i tried to play want work either, both just stop at the first frame of the animation and want play anymore, both are movieclips on a frame inside a movieclip, can somebody help please? and by the way i put key.isdown because i'm using the KeyObject for as3 which allows you to  :)
Here's my code:

sonic.gotoAndStop('stand');
var Key:KeyObject = new KeyObject(stage);
stage.addEventListener(Event.ENTER_FRAME ,onkey);
var sonicspeed:Number = 0;
var friction:Number = .6
//movement
function onkey(e:Event):void{
sonic.x += sonicspeed;
if (sonic.x > 550){
sonic.x = 0;
}else if(sonic.x < 0){
sonic.x = 550;
}if (Key.isDown(Key.LEFT)){
sonic.scaleX=1;
sonicspeed -= 1.5;
sonic.gotoAndStop('run');
}else if (Key.isDown(Key.RIGHT)){
sonic.scaleX=-1;
sonicspeed += 1.5;
sonic.gotoAndStop('run');
}else{
sonic.gotoAndStop('walk');
sonicspeed *= friction;
}
//speed properties
if (sonicspeed > 40){
sonicspeed = 40;
sonic.gotoAndStop('speeding');
}if (sonicspeed < -40){
sonicspeed = -40;
[b]sonic.gotoAndStop('speeding');
[/b]
}if (Math.abs(sonicspeed)< 0.001){
sonic.gotoAndStop('slowing');
}
if (Math.abs(sonicspeed)< 0.00009){
sonic.gotoAndStop('stand');
sonicspeed = 0;
}
}

Posted Oct 31, '09 at 11:11pm

AdventGames

AdventGames

5 posts

Gold - Serf

sorry i messed up a little :)

sonic.gotoAndStop('stand');
var Key:KeyObject = new KeyObject(stage);
stage.addEventListener(Event.ENTER_FRAME ,onkey);
var sonicspeed:Number = 0;
var friction:Number = .6
//movement
function onkey(e:Event):void{
sonic.x += sonicspeed;
if (sonic.x > 550){
sonic.x = 0;
}else if(sonic.x < 0){
sonic.x = 550;
}if (Key.isDown(Key.LEFT)){
sonic.scaleX=1;
sonicspeed -= 1.5;
sonic.gotoAndStop('run');
}else if (Key.isDown(Key.RIGHT)){
sonic.scaleX=-1;
sonicspeed += 1.5;
sonic.gotoAndStop('run');
}else{
sonic.gotoAndStop('walk');
sonicspeed *= friction;
}
//speed properties
if (sonicspeed > 40){
sonicspeed = 40;
sonic.gotoAndStop('speeding');
}if (sonicspeed < -40){
sonicspeed = -40;
sonic.gotoAndStop('speeding');

}if (Math.abs(sonicspeed)< 0.001){
sonic.gotoAndStop('slowing');
}
if (Math.abs(sonicspeed)< 0.00009){
sonic.gotoAndStop('stand');
sonicspeed = 0;
}
}

 

Posted Nov 1, '09 at 1:33am

AdventGames

AdventGames

5 posts

Gold - Serf

nevermind :) i got it

 
Reply to Simple As3 Help?

You must be logged in to post a reply!