Dice

Compatibility Flash MX, MX 2004, Flash 8
Approval Adobe
Version 1.0
Commercial Free
Overview

The Dice component simulates a 6 sided dice, it is visually smart and easy to use. It will enhance any game or activity that requires the use of one or more 6 sided dice.

Features

Parameters and working examples

Dice onRolled

1. onRolled : here you can specify a function to call when the dice stopped moving (see example 1 below).
2. roll duration : specify the duration of the roll (in milliseconds)
3. roll onClick : The dice can be rolled in two ways. You can use the method roll() or you can roll by clicking on the dice (by setting roll onClick to true



Example 1


Click on the dice or on the "roll" button

// ---------- code----------

// In our case here, the function rollDice is called when the button is pressed and the roll onClick parameter is set to true.

// showResult is called when the dice has finished moving
function showResult(de_instance){

// result represents the text field variable that will receive the value of  rollValue

_root.result = de_instance.rollValue;
}

// rollDice is called when the Roll button is pressed roll() is the method use to roll a dice
function rollDice(){
de.roll();
}

// the function below is triggered as soon as the “Roll” button is pressed
myRollButton.onPress = function(){
rollDice();
}

Example 2

// ---------- code----------

// the variable dice will be incremented by 1 each time a dice has finished rolling
var dice:Number = 0;

// The function rollDice is called when the Roll button is pressed. The roll() method is then invoked on each instance of the Dice component
function
rollDice() {
de1.roll();
de2.roll();
de3.roll();
}

// the function getResult is called each time a dice has finished moving, myDice refer to the instance of the Dice component that called the function
function
getResult(myDice) {
// here we increment the variables dice by 1
dice++;
// if dice is equal to 3 then we send the result for each dice to their respective text fields, respectively called "textField1", "textField2" and "textField3".
if (dice == 3) {
for (var i=1; i<=3; i++) {
_root["textField"+i].text = _root["de"+i].rollValue;
}
// we set the variable dice back to zero ready for a next roll
dice = 0;
}
}

// the function below is triggered as soon as the “Roll” button is pressed
myRollButton.onPress = function(){
rolldice();
}


FREE
Compatible with Flash MX, MX 2004, Flash 8
flashvalley
 
Copyright ©2006-2008 flashvalley.com - All rights reserved