# I can't get the dice to stop continuously generating a new numbe - loops constantly?!

**URL:** <https://forum.kirupa.com/t/i-cant-get-the-dice-to-stop-continuously-generating-a-new-numbe-loops-constantly/325308>\
**Category:** flash\
**Created:** [October 8, 2011, 9:53pm UTC](https://forum.kirupa.com/t/i-cant-get-the-dice-to-stop-continuously-generating-a-new-numbe-loops-constantly/325308 "2011-10-08T21:53:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevie7](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@stevie7](https://forum.kirupa.com/u/stevie7)\
**Post date:** [October 8, 2011, 9:53pm UTC](https://forum.kirupa.com/t/i-cant-get-the-dice-to-stop-continuously-generating-a-new-numbe-loops-constantly/325308/1 "2011-10-08T21:53:16Z")

</div>

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
