I am new to AS3. Trying to create a dice that generates a random number.
Almost got there, but I can’t get the dice to stop continuously generating a new number.
I’m sure it is something simple but I just can’t figure it out.
The code I am using is:
stage.addEventListener(Event.ENTER_FRAME, makeDice);
var _dice:Sprite;
var _value:uint;
function makeDice(event:Event)
{
_dice = new Sprite( );
_dice.x = 0;
_dice.y = 0;
addChild(_dice);
_dice.addEventListener(MouseEvent.CLICK, rollDice);
rollDice(null);
}
function rollDice(event:MouseEvent):void
{
_value = Math.floor(Math.random() * 6) + 1;
_dice.graphics.clear( );
_dice.graphics.lineStyle( );
_dice.graphics.beginFill(0xFFFFFF);
_dice.graphics.drawRect(0, 0, 50, 50);
_dice.graphics.endFill( );
_dice.graphics.beginFill(0x000000);
if (_value == 1 || _value == 3 || _value == 5)
{
_dice.graphics.drawCircle(25, 25, 4);
}
if (_value == 2 || _value == 3 || _value == 4 ||
_value == 5 || _value == 6)
{
_dice.graphics.drawCircle(11, 11, 4);
_dice.graphics.drawCircle(39, 39, 4);
}
if (_value == 4 || _value == 5 || _value == 6)
{
_dice.graphics.drawCircle(11, 39, 4);
_dice.graphics.drawCircle(39, 11, 4);
}
if (_value == 6)
{
_dice.graphics.drawCircle(11, 25, 4);
_dice.graphics.drawCircle(39, 25, 4);
}
}
Any help greatly appreciated!!
Stephen