user1819941
user1819941

Reputation: 13

actionscript scrolling

In AS3 I am trying to have my background scroll horizontally when the mouse is on the right side of the stage. (My background instance is called "bp".)

This isn't working:

while (mouseX > 600)
  {bp.x -= 2;}

Upvotes: 0

Views: 304

Answers (1)

Jason Sturges
Jason Sturges

Reputation: 15955

Flash user interface is updated frame-by-frame, and should not be blocking such as your while loop implementation.

Every frame, you can test mouseX position and determine how much to scroll your background.

Here's an example implementation:

import flash.events.Event;

addEventListener(Event.ENTER_FRAME, frameHandler);

function frameHandler(event:Event):void
{
    var d:Number = (stage.stageWidth >> 1) - stage.mouseX;
    bg.x -= d * 0.1;
}

Upvotes: 3

Related Questions