Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Instead of labels, use frame numbers and have your random number generated using something like...
randomNum = Math.ceil(Math.random()*numberOfFrames);
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
Thank you for your answer.
I've put an trace on thisLabel and everytime I see "null". I think something goes wrong. Any ideas?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now