///////////////////////////////////////////////////////////////////////////////// // 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 { import fl.controls.Button; import fl.controls.Label; import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import die.controller.Controllers; import die.controller.IControllerDice; import die.model.IModelDie; import die.model.Models; import die.view.ViewDie; import wk.mvcs.WK_InitMVCS; import wk.mvcs.model.WK_ModelEvent_CS; public class Dice_03 extends MovieClip { ///////////////////////////////////////////////////////////////////////////// // Private Members ///////////////////////////////////////////////////////////////////////////// private var v_controller: IControllerDice = Controllers.instance.controller; private var v_dice: Vector. = Models.instance.dice; private function eh_mouse_click_button(p_event: MouseEvent): void { v_controller.rollAllTheDice(); } private function eh_model_change(p_event: Event): void { var text: String = ""; for each (var l_die: IModelDie in v_dice) text += l_die.value + " "; cmp_dice_values.text = text; } ///////////////////////////////////////////////////////////////////////////// // Public Attributes ///////////////////////////////////////////////////////////////////////////// public var mc_die_0: ViewDie; public var mc_die_1: ViewDie; public var mc_die_2: ViewDie; public var cmp_button_roll_all_the_dice: Button; public var cmp_dice_values: Label; ///////////////////////////////////////////////////////////////////////////// // Constructor ///////////////////////////////////////////////////////////////////////////// public function Dice_03() { // Dice nr. 0 displays the value of dice model nr. 0. v_dice[0].addEventListener (WK_ModelEvent_CS.DATA_CHANGE, function (p_event: Event): void { mc_die_0.value = v_dice[0].value; } ); // A click on dice nr. 0 rolls that dice. mc_die_0.addEventListener (MouseEvent.CLICK, function (p_event: Event): void { v_controller.rollTheDie(0); } ); // Dice nr. 1 displays the value of dice model nr. 1. v_dice[1].addEventListener (WK_ModelEvent_CS.DATA_CHANGE, function (p_event: Event): void { mc_die_1.value = v_dice[1].value; } ); // A click on dice nr. 1 rolls that dice. mc_die_1.addEventListener (MouseEvent.CLICK, function (p_event: Event): void { v_controller.rollTheDie(1); } ); // Dice nr. 2 displays the value of dice model nr. 2. v_dice[2].addEventListener (WK_ModelEvent_CS.DATA_CHANGE, function (p_event: Event): void { mc_die_2.value = v_dice[2].value; } ); // A click on dice nr. 2 rolls that dice. mc_die_2.addEventListener (MouseEvent.CLICK, function (p_event: Event): void { v_controller.rollTheDie(2); } ); // A click on the roll-all-the-dices-button rolls all the dices. cmp_button_roll_all_the_dice .addEventListener(MouseEvent.CLICK, eh_mouse_click_button); // A sceond view is instantiated; The current values of all // three dices ist displayed in cmp_dice_values. for each (var l_dice: IModelDie in v_dice) l_dice. addEventListener(WK_ModelEvent_CS.DATA_CHANGE, eh_model_change); // We are ready. Now initialize all components. WK_InitMVCS.instance.init(); } ///////////////////////////////////////////////////////////////////////////// // EOC ///////////////////////////////////////////////////////////////////////////// } } ///////////////////////////////////////////////////////////////////////////////// // EOF /////////////////////////////////////////////////////////////////////////////////