Skip to main content
New Participant
September 19, 2015
Answered

backward movement animation in flash with as3

  • September 19, 2015
  • 1 reply
  • 419 views

hi, first of let me say that I very new to action scripting and with some tutorial I was able to learn a few things. With that being said, I was charged to make an animation using only action scripting, no motion tween in flash all on one frame. The idea was to move an object along the four corners of the stage. But I have a problem, I figured out how to move the object towards the right and down, but I can't get it to move left and up. here's what I have....and yes I know it's a mess.

import flash.events.Event;

addEventListener(Event.ENTER_FRAME,ballgo)
function ballgo(e:Event):void{
pacmanMc.x += 10;
}
stage.addEventListener(Event.ENTER_FRAME,dontmove);


       function dontmove(e:Event):void{

         if(pacmanMc.x>500){
       pacmanMc.x=500
     }


if(pacmanMc.x>490){
  pacmanMc.y+=10;
}
}
   
stage.addEventListener(Event.ENTER_FRAME,freeze);
      
    function freeze(e:Event):void{
     if(pacmanMc.y>335){
      pacmanMc.y=335
     }
    }

If anyone could help me before Sunday night it will be greatly appreciated.

This topic has been closed for replies.
Correct answer kglad

if pacmanMc has reg point at the upper left use:

import flash.events.Event;

var leg:int = 1;

addEventListener(Event.ENTER_FRAME, pacmanGo);


function pacmanGo(e:Event):void{

if(leg==1){

pacmanMc.x+=10;

if(pacmanMc.x>=stage.stageWidth-pacmanMc.width){

leg=2;

pacmanMc.x=stage.stageWidth-pacmanMc.width;

}

} else if(leg==2){

pacmanMc.y+=10;

if(pacmanMc.y>=stage.stageHeight-pacmanMc.height){

pacmanMc.y=stage.stageHeight-pacmanMc.height;

leg=3;

}

} else if(leg==3){

pacmanMc.x-=10;

if(pacmanMc.x<=0){

pacmanMc.x=0;

leg=4;

}

} else if(leg==4){

pacmanMc.y-=10;

if(pacmanMc.y<=0){

pacmanMc.y=0;

removeEventListener(Event.ENTER_FRAME, pacmanGo);

}

}

}

1 reply

kglad
kgladCorrect answer
Community Expert
September 19, 2015

if pacmanMc has reg point at the upper left use:

import flash.events.Event;

var leg:int = 1;

addEventListener(Event.ENTER_FRAME, pacmanGo);


function pacmanGo(e:Event):void{

if(leg==1){

pacmanMc.x+=10;

if(pacmanMc.x>=stage.stageWidth-pacmanMc.width){

leg=2;

pacmanMc.x=stage.stageWidth-pacmanMc.width;

}

} else if(leg==2){

pacmanMc.y+=10;

if(pacmanMc.y>=stage.stageHeight-pacmanMc.height){

pacmanMc.y=stage.stageHeight-pacmanMc.height;

leg=3;

}

} else if(leg==3){

pacmanMc.x-=10;

if(pacmanMc.x<=0){

pacmanMc.x=0;

leg=4;

}

} else if(leg==4){

pacmanMc.y-=10;

if(pacmanMc.y<=0){

pacmanMc.y=0;

removeEventListener(Event.ENTER_FRAME, pacmanGo);

}

}

}

New Participant
September 19, 2015

Thank you very much. But the code I have moves pacmanMc from the upper left to the upper right and then lower right. The problem is moving him from the lower right to the lower left and then to the upper left.

kglad
Community Expert
September 19, 2015

use the code i suggested.

it's easy to understand and does exactly that.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)