Set interval with random numbers in Adobe Animate cc

1.1k Views Asked by At

I'm trying to generate random numbers every 5 seconds and to output in a dynamic text box using Animate Canvas.In the canvas, I have a dynamic text box named numberOutput.

So far, I have:

var max = 225;
var min = 70;
this.numberOutput.text=[Math.floor(Math.random() * (max - min + 1) ) + min];

This works but with no interval.

How do I put the interval so the dynamic text generates a random number every 5 seconds?

Thanks.

1

There are 1 best solutions below

0
On

You have two options:

  1. Create a blank MovieClip of duration 5 seconds and add your code on the last frame in Actions panel. Or,

  2. Simply put this code inside a function and call that function via setInterval() with 5 second interval.

    function updateText() { var max = 225, min = 70; var random = Math.floor(Math.random() * (max - min + 1)) + min; this.numberOutput.text = random; } setInterval(updateText.bind(this), 5000);

Just make sure to change 'this' to exportRoot or as appropriate.