Skip to main content
Known Participant
August 21, 2011
Answered

Help with a Endless Scrolling Background AS

  • August 21, 2011
  • 1 reply
  • 1461 views

I've been trying to recreate the tutorial in the link below.

http://www.pixelhivedesign.com/tutorials/Endless+Scrolling+Background/

And believe I've followed the instruction, but my actionscript only generates 1 movieclip rather than the 2 required to create the desired effect.

Below is the action script that I typed on in AS2 on the first frame as instructed in the tutorial.

Could someone look this over and explain what I've done incorrectly?

animator = createEmptyMovieClip('animator',1);
bg_1 = animator.attachMovie('bg_mc','bg_1',1);
bg_2 = animator.attachMovie('bg_mc','bg_2',2);
bg_1._x = -bg_1.width/2;
bg_2._x = bg_2.width/2;
speed = 1;
cloudWidth = 380;
animator.onEnterFrame = function () {
    bg_1._x -= speed;
    bg_2._x -= speed;
    if (bg_1._x <= -bg_1._width) bg_1._x = cloudWidth;
    if (bg_2._x <= -bg_2._width) bg_2._x = cloudWidth;
   
}

This topic has been closed for replies.
Correct answer kglad

there's no width property in a2.  use _width:


animator = createEmptyMovieClip('animator',1);
bg_1 = animator.attachMovie('bg_mc','bg_1',1);
bg_2 = animator.attachMovie('bg_mc','bg_2',2);
bg_1._x = -bg_1._width/2;
bg_2._x = bg_2._width/2;

speed = 1;
cloudWidth = 380;
animator.onEnterFrame = function () {
    bg_1._x -= speed;
    bg_2._x -= speed;
    if (bg_1._x <= -bg_1._width) bg_1._x = cloudWidth;
    if (bg_2._x <= -bg_2._width) bg_2._x = cloudWidth;
   
}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 21, 2011

there's no width property in a2.  use _width:


animator = createEmptyMovieClip('animator',1);
bg_1 = animator.attachMovie('bg_mc','bg_1',1);
bg_2 = animator.attachMovie('bg_mc','bg_2',2);
bg_1._x = -bg_1._width/2;
bg_2._x = bg_2._width/2;

speed = 1;
cloudWidth = 380;
animator.onEnterFrame = function () {
    bg_1._x -= speed;
    bg_2._x -= speed;
    if (bg_1._x <= -bg_1._width) bg_1._x = cloudWidth;
    if (bg_2._x <= -bg_2._width) bg_2._x = cloudWidth;
   
}

Known Participant
August 21, 2011

Thanks you so much!

kglad
Community Expert
Community Expert
August 21, 2011

you're welcome.