Question

stage.addEventListener(Event.ENTER_FRAME, loop, false);
function loop(e:Event): void
{

if(scene.x <= -10 && scene.x >= -9200)
    scene.x -= (this.mouseX - 490) * speed;

{
    if(scene.x > -10) scene.x = -10;
    if(scene.x < -9200) scene.x = -9200;
}

}

So this is all the code that starts the Parallax event running. I'm using code from layersmagazine.com by Lee Brimelow.

The parallax effect scrolls along nicely when you move the mouse left or right of the stage, but what I would like it to do is start the Parallax effect automatically on load, scroll along for a bit then stop and switch to being controlled by the mouse.

MouseOver events aren't really effective as the scroll doesn't work well with it.

Was it helpful?

Solution

Create a timer to switch from automatic to mouse scrolling. Add an event listener to the Enter Frame event that adjusts the scroll a little bit each frame. When the timer reaches its time, remove the Enter Frame event listener, and start the mouse scroll code.

Something like...

stage.addEventListener(Event.ENTER_FRAME, intro, false);
var myTimer:Timer = new Timer(5000, 1); // 5 seconds (5000 milliseconds)
myTimer.addEventListener(TimerEvent.TIMER, switchToMouse);
myTimer.start();
function intro(e:Event):void
{
    scene.x += 15; // Or whatever value scrolls nicely.
}
function switchToMouse(e:Event):void
{
    stage.removeEventListener(Event.ENTER_FRAME, intro);
    stage.addEventListener(Event.ENTER_FRAME, loop);
}
function loop(e:Event): void
{
    // mouse code here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top