External Exam Download Resources Web Applications Games Recycle Bin

loop playback

set up 3 scenes, and on 1st scene make a clickMeButton movie clip and add two instances to stage btnLeft and btnRight:

on First Prize scene, import any animated .gif from the web onto the stage:

on whatever the last frame of was of your animated gif animation, add the actionscript to take the movie back to the start:

gotoAndPlay(1, "Choose Left or Right");

repeat the above steps for the other prize scene, then add the following actionscript to to the first layer / first frame / first scene where the 2 button instances are:

stop();
btnLeft.addEventListener(MouseEvent.CLICK, clicked);
btnRight.addEventListener(MouseEvent.CLICK, clicked);

function clicked(event:MouseEvent):void
{
  trace(event.target.name); //btnLeft or btnRight

  // random number between 1 and 2:
  var lucky_number = Math.floor( 1 + Math.random() * 2 );
  
  if (lucky_number == 1){
    gotoAndPlay(1, "First Prize");
  }
  else {
	gotoAndPlay(1, "Second Prize");
  }
}

Alternative - you can add multiple prizes. Here is a sample code snippet of a pack opener for R6. Note there is only 1 pack to click on. There is also a 6 in 10 chance of getting common, 3 in 10 chance of getting rare, 1 in 10 chance of getting blackice:

stop();
btnPack.addEventListener(MouseEvent.CLICK, clicked);

function clicked(event:MouseEvent):void
{
  // random number between 1 and 10:
  var lucky_number = Math.floor( 1 + Math.random() * 10 );
  
  if (lucky_number < 7){
    gotoAndPlay(1, "Common");
  }
  else {
		if (lucky_number < 10){
			gotoAndPlay(1, "Rare");
		}
		else {
			gotoAndPlay(1, "BlackIce");
		}
  }
}