Mx - counter

hi, does anyone know if there is a piece of code that will count from 0 through 9 and then just keep repeating over and over?

if there is would there be a way of controlling the spped of the count - so it could go really fast or quite slow??

i tried
[AS]onClipEvent (load) {

	myValue = 0;

}
onClipEvent (enterFrame) {

	if (myValue < 100) {
            myValue++; 
    }

} {[/AS]

but alas i think i’m well off the mark

wilma

Use the modulo [font=courier new]%[/font] operator.

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary010.html

var val = 0;
function count() {
val = ++val%10;
trace(val);
}
this.onEnterFrame = count;

To control the speed, you can use the [font=courier new]setInterval[/font] function.

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary646.html

var val = 0;
function count() {
val = ++val%10;
trace(val);
}
var interval = setInterval(count, 1000/48);

:stuck_out_tongue:

that gives me output Kode, but how do i actually get the number on screen to change.

say if i type the number ‘2’ on a layer how do i get that number to change constantly to a value between 0 and 9??

wilma

Create a text field and you could either assign the variable to it, or assign the value of the variable through its [font=courier new]text[/font] property.

var my_var = 2;
this.createTextField("my_txt", 0, 0, 0, 0, 0);
my_txt.autoSize = true;
my_txt.variable = "my_var";
function count() {
	my_var = ++my_var%10;
}
this.onEnterFrame = count;
//
var my_var = 2;
this.createTextField("my_txt", 0, 0, 0, 0, 0);
my_txt.autoSize = true;
function count() {
	my_var = ++my_var%10;
	my_txt.text = my_var;
}
this.onEnterFrame = count;

nice one.

presumably i can control the text style by adding code to that?

Yep. The [font=courier new]TextFormat[/font] object will help you with that. :stuck_out_tongue:

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary788.html