Skip to main content
TDRonline
Known Participant
May 9, 2013
Answered

Issue with overlap looping background animation

  • May 9, 2013
  • 1 reply
  • 849 views

I recently found a great snippet AC code which allows for a smooth looping animation.

The only problem is that the looping animation will sometimes show on top of all my other layers even though the layer it in the middle. Since this is an Action Script I'm safe to assume that I need something in here to tell it to stay near the middle, somehow.

I've tried to correct this but continue to receive random pausing and figured I would ask the community.

This is my current setup

Starts on Scene1, then goes to next Scene 2 after 25 frames

  • Presentation Layer (25 frames long)
  • Looping Grid (Action Script Below) *Overlaping all layers
  • Static Background (Never moves) *Needing the animation just above this layer

//The speed of the scroll movement.

var scrollSpeed:uint = 2;

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

var s1:ScrollBg = new ScrollBg();

var s2:ScrollBg = new ScrollBg();

addChild(s1);

addChild(s2);

//This positions the second movieclip next to the first one.

s1.x = 0;

s2.x = s1.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{

s1.x -= scrollSpeed; 

s2.x -= scrollSpeed; 

if(s1.x < -s1.width){

s1.x = s1.width;

}else if(s2.x < -s2.width){

s2.x = s2.width;

}

}

If anyone could help me figure out why this is happening, I would be most greatful and appreciative.

If I need to show my work I can provide a link if requested.

Thank you,

TDR

This topic has been closed for replies.
Correct answer kglad

one way to do what you want is to place a dummy movieclip on the layer where you want your bg's to appear.  assign it an instance name (eg, bgParent) and use:

bgParent.addChild(s1);

bgParent.addChild(s2);

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 9, 2013

one way to do what you want is to place a dummy movieclip on the layer where you want your bg's to appear.  assign it an instance name (eg, bgParent) and use:

bgParent.addChild(s1);

bgParent.addChild(s2);

TDRonline
TDRonlineAuthor
Known Participant
May 9, 2013

Wouldn't the (s1), (s2) cause an issue?

kglad
Community Expert
Community Expert
May 9, 2013

not as long as they're defined and created before trying to add them.  ie, replace your addChild() code with the code i showed.