///////////////////////////////////////////////////////////////////////////////// // Copyright © 2008-2010 W. Kowarschick // // Permission is granted to copy, distribute and/or modify this document // under the terms of the WK License, Version 1.0 (WKL 1.0) or any later version // published by Wolfgang Kowarschick. ///////////////////////////////////////////////////////////////////////////////// package die.view { import mx.flash.UIMovieClip; import flash.events.Event; public class ViewDie extends UIMovieClip { ///////////////////////////////////////////////////////////////////////////// // Constants ///////////////////////////////////////////////////////////////////////////// // An array of arrays, which contains for each of the numbers 0, 1, ..., 6 // the states of the pips. private static const c_pip_states: Array = [ ["off", "off", "off", "off", "off", "off", "off"], // 0 ["off", "off", "off", "on", "off", "off", "off"], // 1 ["off", "off", "on", "off", "on", "off", "off"], // 2 ["off", "off", "on", "on", "on", "off", "off"], // 3 ["on", "off", "on", "off", "on", "off", "on" ], // 4 ["on", "off", "on", "on", "on", "off", "on" ], // 5 ["on", "on", "on", "off", "on", "on", "on" ] // 6 ]; ///////////////////////////////////////////////////////////////////////////// // Instance Variables ///////////////////////////////////////////////////////////////////////////// // Instance variable of the attribute "value". private var v_value: uint; ///////////////////////////////////////////////////////////////////////////// // Public Attributes ///////////////////////////////////////////////////////////////////////////// /** The current value of the dice: 1, 2, 3, 4, 5, or 6; Error: 0. */ public function get value(): uint { return v_value; } public function set value(p_value: uint): void { // Do some integrity checks and finaly set the value: if (0 < p_value && p_value < 7) v_value = p_value; else v_value = 0; // A better error handling is missing! // Set the states of all pips by means of a for-loop. for (var i: int = 0; i < 7; i++) this["mc_pip_" + i].value = c_pip_states[v_value][i]; } ///////////////////////////////////////////////////////////////////////////// // EOC ///////////////////////////////////////////////////////////////////////////// } } ///////////////////////////////////////////////////////////////////////////////// // EOF /////////////////////////////////////////////////////////////////////////////////