Skip to main content
Participant
February 20, 2018
Answered

Multiple actions

  • February 20, 2018
  • 2 replies
  • 226 views

I have an animate screen on which I have 6 actions I want to choose from randomly rather than in sequence, a This Else This situation. How do I go about this?

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

    What do exactly you need to randomize? Movie Clip frame or name, scene names...? In AS3 or JavaScript (HTML5)?

    You could, for example, create two really simple functions to return a random value and use it for whatever you want. Like this:

    AS3:

    function randomize(value:int):int

    {

        return Math.round(Math.random() * value);

    }

    trace(randomize(6));

    JavaScript (HTML5):

    this.randomize = function(value)

    {

        return Math.round(Math.random() * value);

    }

    console.log(this.randomize(6));

    Please let us know if it helps.

    Regards,

    JC

    2 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    February 20, 2018

    Hi.

    What do exactly you need to randomize? Movie Clip frame or name, scene names...? In AS3 or JavaScript (HTML5)?

    You could, for example, create two really simple functions to return a random value and use it for whatever you want. Like this:

    AS3:

    function randomize(value:int):int

    {

        return Math.round(Math.random() * value);

    }

    trace(randomize(6));

    JavaScript (HTML5):

    this.randomize = function(value)

    {

        return Math.round(Math.random() * value);

    }

    console.log(this.randomize(6));

    Please let us know if it helps.

    Regards,

    JC

    kglad
    Community Expert
    Community Expert
    February 20, 2018

    use Math.random()

    function f(){

    var r=Math.random();

    if(r<1/6){

    } else if (f>=1/6 && <1/3){

    } else if(...etc