Copy link to clipboard
Copied
Hello to everyone!
I have a timer and a random number (var myNumber: Number = Math.ceil(Math.random() * 5);).
I need to repeat the last random number, eg: 3 3, 4 4, 1 1, etc.
Any suggestions?
Thanks.
use:
kglad wrote:
use:
var myNum: Number;
Copy link to clipboard
Copied
use the myNumber reference without re-executing that line of code you showed.
Copy link to clipboard
Copied
Thank you very much kglad.
I think it is better to see all the script.
I'm trying to repeat the random sequence switching between odd and even.
The only think that doesn't work is the line 16 that give "NaN"
Any hint?
Copy link to clipboard
Copied
i can't determine what you're trying to do, but you should never nest named functions and myNum serves no (shown or explained) purpose.
var myNum: Number
Copy link to clipboard
Copied
Thank you kglad!
I'm trying the purpose of my first question.
1) to have a counter;
2) for the first second to get a random number;
3) for the next second to have te same random number (without use Math.random), and so on ...
I try to do this with odd and even numbers;
1) If the number of the counter is odd I create a random number;
2) "else" if the number is even, I repeat the same random number, but in my script doesn't work ...
Copy link to clipboard
Copied
use:
var myNum_odd: Number;var myNum_even: Number
- var mySound: Sound = new Click();
- var mySound2: Sound = new Sound2();
- var fl_TimerInstance: Timer = new Timer(1000, 30);
- fl_TimerInstance.addEventListener(TimerEvent.TIMER, fl_TimerHandler);
- Count_It.addEventListener(MouseEvent.CLICK, Count_It);
- function Contalo(event: MouseEvent): void {
- myNum_odd = Math.ceil(Math.random() * 8);
- myNum_even = Math.ceil(Math.random() * 8);
- fl_TimerInstance.reset();
- fl_TimerInstance.start();
- }
- function fl_TimerHandler(event: TimerEvent): void {
- if (event.currentCount % 2) {
- trace(myNum_odd);
- mySound.play();
- } else {
- mySound2.play();
- trace(myNum_even);
- }
- }
Copy link to clipboard
Copied
Thank you again kglad.
With your script I get this error message:
Scene 1 level 'Actions', Frame 1, line 16, column 12, 1119: Access to an undefined property currentCount through a reference with static type flash.events:TimerEvent.
Copy link to clipboard
Copied
my error, that should be
event.currentTarget.currentCount,
not event.currentCount
Copy link to clipboard
Copied
You are very kind and now the script work better, and I suppose to be to one step from my purpose.
The script now give me, in the output window with the trace function, something like this:
1
3
1
3
1
3
and so on for the 30 steps of the timer.
But my purpose was to have, with only one click, for the 30 steps of the timer, something like this:
3
3
//random
5
5
//random
2
2
and so on for the 30 steps of the timer.
Every number must be at distance of one second (1000 in the timer): like this 3 3, 5 5 etc.
I'm sorry but it is my fault. I don't have explain well it from my first message.
Thank you again.
Copy link to clipboard
Copied
use:
kglad wrote:
use:
var myNum: Number;
Copy link to clipboard
Copied
Thank you so much kglad!!!!
You are my hero
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now