Search code examples
actionscript-3flashflash-cs6

how to create a infinite scrolling animation in action script3


im creating a fish tank..so what i want to do is my fish should be infinite scrolling..i'm using action script 3..this is the code i used..but it's not working..

var scrollSpeed:uint = 5;

//This adds two instances of the movie clip onto the stage.



//This positions the second movieclip next to the first one.
f1.x = 0;
f2.x = f1.width;

//Adds an event listener to the stage.
stage.addEventListener(Event.ENTER_FRAME, moveScroll); 

//This function moves both the images to left. If the first and second 
//images goes pass the left stage boundary then it gets moved to 
//the other side of the stage. 
function moveScroll(e:Event):void{
f1.x -= scrollSpeed;  
f2.x -= scrollSpeed;  

if(f1.x < +f1.width){
f1.x = f1.width;
}else if(f2.x < +f2.width){
f2.x = f2.width;
}
}

f1 and f2 is my fish instance name


Solution

  • Your problem lines are at the bottom.

    if (f1.x < f1.width) {
        f1.x = stage.stageWidth - f1.width // f1.width;
    } // Removed else
    
    if (f2.x < f2.width) {
        f2.x = f1.width;
    }