PDA

View Full Version : Control looping



DDD
July 15th, 2008, 12:38 PM
I need a timeline to play only 3 times. I know it involves a counter of some sort. But not sure how to code that. Can someone kindly help out or point me to a resource?

Thanks

saxx
July 15th, 2008, 12:43 PM
Wooo what i posted was completly retarded

*waits for senocular*

sekasi
July 15th, 2008, 01:02 PM
Put this at the end of the timeline anim;



dispatchEvent(new Event("TIMELINE_DONE"));


Then just listen to that event.


var cnt:uint = 0;
TIMELINEOBJECT.addEventListener("TIMELINE_DONE", mo);

function mo(e:Event):void {
cnt++;
cnt > 2 ? e.target.stop() : null;
};


above example is with timeline code, so move it in to whatever class you are using. Timeline code is not awesome.

DDD
July 15th, 2008, 01:48 PM
uuuhhh...hmmm.....class...um yea.....well....do not know how to use classes :P
This is just a flash ad banner. Is there anyway it can all be self contained in the flash file? Maybe on the timeline.

But thank you for the help thus far.

senocular
July 15th, 2008, 01:55 PM
such a hard, simple question.

Throw this in the last frame of the timeline and it should work


var loopCount:int = 3; // how many times do you want to play?
var counter:int; // used by the if check to see how many times already played

counter++; // we're at the last frame so up the play counter
// now check to see if we need to stop
if (counter >= loopCount) stop();

The one thing to take note is that counter is not given an assigned value. Why not? because if you assign it a value, it will be set to that value every time this frame is entered. Instead we want it to continuously update when this frame is entered. So we'll rely on the int type declaration to give the variable an initial value of 0 and then ++ it up from there.

There are ways to work around this... but just doing what I've done above makes it easy and compact.

sekasi
July 15th, 2008, 01:55 PM
yeah dude, you can just use the code I pasted :P

Here, I'll attach a quick FLA example

sekasi
July 15th, 2008, 01:56 PM
Oh the maaaain timeline.. Sorry :/ Thought you meant a timeline inside a child. :/

DDD
July 15th, 2008, 02:25 PM
You guys are my favs....thanks a bunch. I promise to learn AS by the time they get to AS5

lunatic
July 15th, 2008, 02:34 PM
Sen that's awesome - simple and easy to understand.

*feels brain getting a little bit bigger*

DDD
August 6th, 2008, 02:26 PM
Sorry to res this, but I was wondering if some kind soul wouldnt mind helping with a AS2/1 version of thiswonderful looping control?

Thanks in advance

Anogar
August 6th, 2008, 02:37 PM
Sure thing:



var loopCount:Number = 3; // how many times do you want to play?
var counter:Number; // used by the if check to see how many times already played

counter++; // we're at the last frame so up the play counter
// now check to see if we need to stop
if (counter >= loopCount) stop();

int is not supported in AS3.

DDD
August 6th, 2008, 02:39 PM
You sir are a gentleman and a scholar. :D

DDD
August 6th, 2008, 03:52 PM
hmmm, that doesnt seem to work as Sen's did. It doesnt seem to loop. Is there something missing I need to add?

I really appreciate the help

BTW I am using CS3, but exporting as as2 flash 8. I also tried as1.

senocular
August 6th, 2008, 05:14 PM
Try this:



var loopCount:Number = 3;
this.counter = (this.counter == undefined) ? 1 : this.counter + 1;

if (this.counter >= loopCount) stop();

DDD
August 6th, 2008, 05:43 PM
Sen thanks man, that works.!!!