Skip to main content
Known Participant
March 19, 2009
Question

Endlessly Looping Animation

  • March 19, 2009
  • 7 replies
  • 893 views
I'd like to create an endlessly looping movie that loads 3 images, then fades out each one using a tween to reveal the image just beneath it. As soon as the third image fades, I'd like for the animation to start over and just keep repeating. I'm trying to use a timer to do this but need some serious help. I would imagine that a "for" loop would be used to repeat the animation but I can't determine how to make loop more than a select number of times.

Below is the code I have. Can somebody lend a hand?

Thanks so much.
This topic has been closed for replies.

7 replies

Ned Murphy
Legend
March 20, 2009
You're welcome.
Ned Murphy
Legend
March 20, 2009
PS - I used the 1 because that's how you had your images named, and that variable is used to identify them.

["image"+String(imgCount)+"_mc"]
Known Participant
March 20, 2009
Go it. Thanks a million.
Ned Murphy
Legend
March 19, 2009
Those would have been my words (on many occasions in these forums, unfortunately some folks can't get past bring a pole with them).
Known Participant
March 20, 2009
Aha! Nailed it!

http://www.savagepixels.com/photoAnimation.html

If you're still out there Ned ... why did you use "uint" instead of "int" or even just giving the variable "imgCount' a value of "1"?

I was also curious why the timer was assigned "0" repetitions.

Thanks Ned.
Ned Murphy
Legend
March 20, 2009
Using uint is primarily a measure of economy--waste not want not. Since it's not going to go negative, no need providing for it.

As far as the zero goes, do a little fishing in the Timer class for the repeatCount property
Ned Murphy
Legend
March 19, 2009
PS - You should check out your other posting below for this as well. There might be some info offered there that will help.
Ned Murphy
Legend
March 19, 2009
You might need to have something that lights up the next image after the tween completes. If you add an event listener to the tween, you can use that to set the next image to alpha = 1.

There are probably a couple of things your scenario could use, but I'd rather you battle it in the brain a bit than give you a complete solution.
Known Participant
March 19, 2009
quote:

Originally posted by: NedWebs
I'd rather you battle it in the brain a bit than give you a complete solution.


Give a man a fish, and feed him for one meal ... teach him to fish, and feed him for the rest of his life.

I hear you ... thanks for your time Ned!
Known Participant
March 19, 2009
Thanks Ned! That's genius, and I never would have thought to do it that way. Thanks.

The only glitch is the animation gets a little weird after the first time through. The images start to just appear very briefly. They continue looping just fine, but they are not staying on screen for the entire 5 seconds. Do you have any idea what's happening?

Here's my test URL: http://www.savagepixels.com/photoAnimation.html

and the code:

var image1_mc:mcImage1 = new mcImage1();
var image2_mc:mcImage2 = new mcImage2();
var image3_mc:mcImage3 = new mcImage3();

addChild(image1_mc);
addChild(image3_mc);
addChild(image2_mc);
addChild(image1_mc);

var imgCount:uint = 1;

var myTimer:Timer = new Timer(5000, 0);
myTimer.addEventListener(TimerEvent.TIMER, fadeImage);

myTimer.start();

function fadeImage (e:TimerEvent):void
{
new Tween(this["image"+String(imgCount)+"_mc"], "alpha", Strong.easeOut, 1, 0, 3, true);
imgCount +=1;
if(imgCount == 4)
{
imgCount = 1;
}
}
Ned Murphy
Legend
March 19, 2009
You will probably save some code if you take a different approach. Have a counter that keeps track of which image is to be tweened (1,2,3), setting it back to 1 after it processes 3.

Then just have your Timer run continuously:

var imgCount:uint = 1;

var myTimer:Timer = new Timer(5000, 0);
myTimer.addEventListener(TimerEvent.TIMER, fadeImage);

myTimer.start();

function fadeImage (e:TimerEvent):void
{
new Tween(this["image"+String(imgCount)+"_mc"], "alpha", .....etc

imgCount +=1;

if(imgCount == 4){ imgCount = 1; }
}