I recently developed a slot machine for the sake of it. I'm sure there are quite a few ways to do this but this is the way I did it. This has to be done for each reel.
There are usually three symbols visible inside your blitmask. If your blitmask is one symbol high then this method will give you the visible symbol
First declare a variable to keep track of the centre symbol.
I positioned my strip so that the 3rd symbol was center in the blitmask window, remember this is not the index.
Basically you know where it is going to land so you can find out what the symbol is before it lands.
var REEL1:Number = 3;
function spin(event:MouseEvent):void
{
var newNumber:Number = (randomNumber(1, 10)) ;
//call function to find the symbol to land
REEL1 = GetReelPosition(REEL1, newNumber);
//work out the amount to tween. Random number * symbol height + strip length
//if you want a longer spin add more strip lengths
newNumber = (newNumber * 100) + 1000;
var myTimeline:TimelineMax = new TimelineMax();
myTimeline.append(new TweenLite(Strip1, 2, {y:String(newNumber)}));
//get target symbol as movieclip
var currentTile:MovieClip = Strip1.getChildAt(REEL1-1) as MovieClip;
//if you have export for actionscript, this will tell what the object is
trace(String(currentTile));
}
When creating your strip, make symbols from your images, export for actionscript then add to your strip from top to bottom. If you change a symbol then you will have to delete and paste from top to bottom again. The index reflects the order the symbols are added.
function GetReelPosition(reel:Number,num:Number):Number
{
reel = reel - num;
switch(reel)
{
//if symbol is the first number on the strip and random
//number = 1 (1-1) then the centre symbol is the last on the strip
case 0:
reel = 10;
break;
//if symbol is the first number on the strip and random
//number = 10 (1-10) then the centre symbol is the first on the strip
case 1:
case -9:
reel = 1;
break;
case 2:
case -8:
reel = 2;
break;
case 3:
case -7:
reel = 3;
break;
case 4:
case -6:
reel = 4;
break;
case 5:
case -5:
reel = 5;
break;
case 6:
case -4:
reel = 6;
break;
case 7:
case -3:
reel = 7;
break;
case 8:
case -2:
reel = 8;
break;
//case 9, -1:
case 9:
case -1:
reel = 9;
break;
}
return reel;
}
I updated the switch code. case 9, -1: was not reliable. I'm not sure what language I picked that one from.
This was my first flash project and I did this slot machine fairly quickly. I'm sure there are better ways to do this. Have a look at my slot?
http://rcras.com/pokies/funnyfarm