# Mx - counter

**URL:** https://forum.kirupa.com/t/mx-counter/33524
**Category:** Uncategorized
**Created:** [October 20, 2003, 6:41pm UTC](https://forum.kirupa.com/t/mx-counter/33524 "2003-10-20T18:41:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![wilma](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@wilma](https://forum.kirupa.com/u/wilma)
#### Post date: [October 20, 2003, 6:41pm UTC](https://forum.kirupa.com/t/mx-counter/33524/1 "2003-10-20T18:41:23Z")

</div>

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 &lt; 100) {
            myValue++; 
    }

```

} {[/AS]

but alas i think i’m well off the mark

wilma

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 20, 2003, 6:56pm UTC](https://forum.kirupa.com/t/mx-counter/33524/2 "2003-10-20T18:56:56Z")

</div>

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

[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary010.html](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary010.html)

```auto
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](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary646.html)

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

```

😛

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 20, 2003, 7:02pm UTC](https://forum.kirupa.com/t/mx-counter/33524/3 "2003-10-20T19:02:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 20, 2003, 7:12pm UTC](https://forum.kirupa.com/t/mx-counter/33524/4 "2003-10-20T19:12:45Z")

</div>

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.

```auto
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;

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 20, 2003, 7:24pm UTC](https://forum.kirupa.com/t/mx-counter/33524/5 "2003-10-20T19:24:05Z")

</div>

nice one.

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 20, 2003, 7:26pm UTC](https://forum.kirupa.com/t/mx-counter/33524/6 "2003-10-20T19:26:39Z")

</div>

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

[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary788.html](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary788.html)
