Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

randomNumber == timeline label

New Here ,
May 03, 2013 May 03, 2013

Hello everybody,

I'm having an other question.

I have a movieclip with a slotmachine roll changing it's dice dots. http://delah.nl/diceSlotMachineTest.swf

I labeled some keyframes with the amount of dots on it. When pressing start there is a random number created and after 2 seconds playing it has to stop on the label which is equal to the random number.

I hope there is a very simple line of code to fix that last part. Something like:

function stopRoll(event:TimerEvent):void{

          if (randomNumber == roll_mc./*label?*/){

                    roll_mc.stop();

          }

How can I make this happen?

Thanks in advance

TOPICS
ActionScript
576
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2013 May 03, 2013

Instead of labels, use frame numbers and have your random number generated using something like...

randomNum = Math.ceil(Math.random()*numberOfFrames);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2013 May 03, 2013

Make an array that holds the names of each of these frame labels. Use the Math.random() method to grab one of the frame labels. When your timer goes off, use an enterFrame event to compare the current frame label with the one that you want to use.

var labelsArray:Array = new Array("one", "two","three", "four", "five", "six");

var labelsCount:int = labelsArray.length;

var thisLabel:String;

function pickAMarker():void {

     thisLabel = labelsArray[Math.floor(Math.random() * labelsCount)];

}

startButton.addEventListener(MouseEvent:MOUSE_UP, runTimer);

function runTimer(event:MouseEvent):void {

                 var myTimer:Timer = new Timer(2000, 1);

                 myTimer.addEventListener("timer", timerHandler);

                 myTimer.start();

        }

  function timerHandler(event:TimerEvent):void {

                 stage.addEventListener(Event.ENTER_FRAME,useMarker);

        }

function useMarker(event:Event):void {

     if(rollMC.currentLabel == thisLabel) {

          rollMC.stop();

          stage.removeEventListener(Event.ENTER_FRAME,useMarker);

     }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2013 May 05, 2013

Thank you for your answer.

I've put an trace on thisLabel and everytime I see "null". I think something goes wrong. Any ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 05, 2013 May 05, 2013
LATEST

You will need to run the function "pickAMarker" at some point. You could run it at the beginning of the "useMarker" function, or someplace else, depending on what you have going on in your movie.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines