Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving difficulty in understanding ActionScript 3 Timer class
    primarykey
    data
    text
    <p>I'm trying to make a dice game in Flash/ActioScript 3. I did all the essentials and it works smoothly. Now I want to improve the user experience. For instance, when it's computer's turn (to roll and do things according to die value) I want to animate the die. The die has 6 keyframes. So, for, say, 2 seconds the die will loop those 6 frames then it will stop on a value (depending on random generator). Somehow I can't do it as I want. How can I write a function(s) so that when I say,</p> <p>animateDice()</p> <p>it will do nothing but just animate the dice for a specified interval?</p> <p>Update:</p> <pre><code>var timer:Timer = new Timer(10, 50); myButton.addEventListener(MouseEvent.CLICK, onClick); timer.addEventListener(TimerEvent.TIMER, animateDice); function onClick(event: Event):void { timer.start(); } function animateDice(event: Event):void { dice.play(); } </code></pre> <p>For instance, I don't understand why the above code doesn't work properly. It does work properly on first click, but not there after.</p> <p>Update 2: I guess I'm still having problems. How do I suspend the running code until the timer stops? (Yes there is a work around---putting timer handlers inside other timers, etc. Is there an easy way?</p> <p>Maybe, this will help:</p> <p>First we see the die rolling (and a message box informs the user that the game will decide whom starts). Then it's either Human's or Computer's turn. When it's computer's turn, first we see the rolling die again for, say, 1 second. Then it stops and and we see the outcome. I'm a beginner and I nay be missing something, but from what I see it seems that all these simple steps (just showing the die rolling for some time) means lots and lots of lines.</p> <p>If I use a simple timer for die animation, the script continues and the whole show goes away.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload