Log in

View Full Version : Auto increment problem?



Mark__G
11-03-2008, 06:21 PM
I am ashamed that I can't seem to figure this out. I just need AS code that sets a variable starting at 1 and then auto increments to 7 then resets back to 1.

Medyman
11-03-2008, 06:58 PM
var num:Number = 1;
function increaseByOne() {
if(num > 7) {
num = 1;
}
else {
num++;
}
}

Mark__G
11-03-2008, 07:22 PM
How do I get the function to loop and then call the variable

e.g.

gotoAndStop(num);

Mark__G
11-05-2008, 11:17 PM
Please advise on why this is not working?



var num:Number = 1;
function increaseByOne() {
if(num > 7) {
num = 1;
}
else {
num++;
}
}

i = num;
increaseByOne(i);
_root.partners.logos.gotoAndStop(i);

Medyman
11-06-2008, 12:18 AM
Please explain what you're trying to do in exact terms. I can't make sense of the extra code you've posted.

Mark__G
11-06-2008, 12:38 AM
I have a mc that just has a fade in, pause, then fade out...

Within this mc I have 7 frames, each with a different logo.

I am trying to just direct the mc to that logo and do it sequentially from frame 1 (logo 1).

Medyman
11-06-2008, 03:31 PM
Alright...try this:

var frame:Number = 1;
function playNext() {
if(frame > 7) {
gotoAndStop(1); // or gotoAndPlay(), whatever you need
}
else {
frame++;
gotoAndStop(frame)
}
}

Then, call playNext() wherever/however you're going to the next frame. If you want it on a timer, use setInterval.

Mark__G
11-06-2008, 09:09 PM
This is doing the same thing that I already had? If I place the AS in my mc tween area and then call the function within an onEnterFrame function it doesn't work. If I do the same from the mc itself that contains all my logos it just rapidly cycles through the logos without any sort of fade in/out tween.

Medyman
11-07-2008, 12:30 AM
You shouldn't be calling this with an onEnterFrame. That calls the function once per frame -- overkill!

Use setInterval to have a continuous loop.