Skip navigation
jjfossey
Currently Being Moderated

Is there an AS3 script for scrolling parallax background?

May 19, 2010 9:00 AM

I want to create a parallax scrolling effect using 3 PNG images that are 950px x 335px. One image is the foreground, another is the background and the third is the "middle" image. What I want to do is automatically scroll each image horizontally at different speeds, but I can't figure out how to do that using AS3. All the parallax examples I've seen so far requires the user to scroll the background using their mouse or keyboard, and that's not what I want to do. I want it to automatically start scrolling when the user loads the page. Can this be done with AS3? If so, can someone give me a script or tell me where to find one?

 

Thanks.

 
Replies
  • Currently Being Moderated
    May 19, 2010 9:17 AM   in reply to jjfossey

    You should try searching Google using "AS3 parallax tutorial"

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2010 9:40 AM   in reply to jjfossey

    Did you checked this tutorial at gotoAndLearn?

     

    http://www.gotoandlearn.com/play?id=96

     

    Hope it helps...

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2010 12:40 PM   in reply to jjfossey

    Your best bet will be to scroll one image first.  Once you have that done, you should be able to make it happen a couple more times for the other two images.

     

    In AS3 you could use an Event.ENTER_FRAME event handler function to continuously increment the x property of an image's movieclip.  If you want it seamless, then you need to have two such objects, each taking turns tailing the other--as one moves out of view it moves all the way to the other end of the one tailing it.  Using the ENTER_FRAME event will make things happen without any need for interaction with a mouse or keyboard.

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2010 1:36 PM   in reply to jjfossey

    If you're going to go with AS2 you should resume your posting in the AS2 forum.

     

    As far as the code you show, if that's all in the same timeline then your speed value will be the same as whatever the last value you assign to it.  You should have three different speed variables (speed1, speed2, etc).

     

    Regardless of what else I offered, if you managed to get something moving, then you are likely on the path to achieving what you want, so I suggest you continue on that path and expect a little head scratching and frustration along the way.  I believe that suffering this stuff is the best way to learn it.

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2010 6:04 PM   in reply to Ned Murphy

    If you are publishing to an AS3 document and Flash 10 (I think) you can easily use the z property of objects to fake parallax.

     

    Set up a movieclip to contain your scene. And then set up your movieclips for the various depths (near, mid-range, far, very far, what have you) and give each one of them a depth with higher numbers for the further away slower moving parts.You can then just tween the parent/scene clip and Flash will do the math.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points