Skip to main content
Known Participant
January 23, 2018
Answered

Random Timeline

  • January 23, 2018
  • 1 reply
  • 1326 views

Hallo!

Ich habe eine nette kleine Flash-Animation in meinem Archiv die ich gerne für Animate/HTML5 nutzen würde.

Der Code war extrem simpel und bewirkte dass zufällig zwischen 4 Bildmarkierungen (f0 bis f3) gesprungen wurde.

Am Ende von ein paar Frames sitzt das Script und schickt den Player jeweils auf einen andere Markierung, wo er wieder läuft bis zum Script, usw..

Seit Stunden versuche ich das mit Javascript zu machen, leider erfolglos. So war es:

zufall = random(3);

if (Number(zufall) == 0) {

gotoAndPlay("f0");

}

if (Number(zufall) == 1) {

gotoAndPlay("f1");

}

if (Number(zufall) == 2) {

gotoAndPlay("f2");

}

if (Number(zufall) == 3) {

gotoAndPlay("f3");

}

Gibt es da keine einfache Lösung?

So geht es jedenfalls nicht (dass ich kein Programmierer bin sieht man vermutlich gleich 😉

var zufall;

zufall = Math.random() *4;

zufall2 = Math.ceil(zufall);

if (zufall2 == 1) {

gotoAndPlay("f0")

}

;

if (zufall2== 2) {

  gotoAndPlay("f1")

}

;

if (zufall2== 3) {

gotoAndPlay("f2")

}

;

if (zufall2== 4) {

gotoAndPlay("f3")

}

;

Al

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

    Hi.

    Call this function one frame before every label:

    this.randomFrame = function()

    {

        this.gotoAndPlay("f" + parseInt(Math.random() * 4));

    }

    // call in this way: this.randomFrame();

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    January 23, 2018

    Hi.

    Call this function one frame before every label:

    this.randomFrame = function()

    {

        this.gotoAndPlay("f" + parseInt(Math.random() * 4));

    }

    // call in this way: this.randomFrame();

    Known Participant
    January 23, 2018

    thank you

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 23, 2018

    You're welcome.