Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : Creating a counter


Parp!
5/5/2004 10:07:48 PM
Hello,
I'd like to create a counter in a movie that will simply counts up. When it
reaches n I will create an instance of a movie on the stage which will fade up
and out then remove itself from the stage, kind of like a partlce generator if
you like. So can anyone tell me where I would create the counter variable,
update it, and generally how to go about it?

Ideally I'd have a one frame movie that looped, and some action script like...

myVar++;
if(myVar > 100)
{
// Add movie here
myVar = 0; // Start again
}

Can anyone, help? I've obviously tried it already and my counter just does
nothing. I get the feeling that the counter isn't updating...any suggestions?

Many thanks in advance.
Jez.
Jack.
5/5/2004 10:40:23 PM
for a 1 frame movie loop, use onEnterFrame,

this.onEnterFrame = function(){
myVar++;
trace(myVar);
if(myVar > 100){
// Add movie here
myVar = 0; // Start again
}
};

Parp!
5/5/2004 10:48:12 PM
Brilliant, that looks kinda readable...I'm a C++ coder but this Flash thing
does things kinda weird :O) Where would I create and initialise the variables?
Would I need to embed a movie in another say have the variables declared in the
root movie then have a second movie with the function attached?

Many thanks
Jez.
Jack.
5/5/2004 11:10:06 PM
[quoted text, click to view]

in the example posted,
the variable myVar is created within the function

[quoted text, click to view]

if you are going in that direction, use _global functions
and variables, the Help Files describe them as :

Unlike Timeline-declared or locally-declared variables and
functions, global variables and functions are visible to every
Timeline and scope in the Flash movie, provided they are not
obscured by identifiers with the same names in inner scopes.

hth
Parp!
5/6/2004 7:40:18 PM
Thanks for your help Jack. That sounds doable.
Much appreciated.
AddThis Social Bookmark Button