import iap.commander.extentions.Drag; import iap.commander.extentions.Ease; import iap.commander.extentions.Matrix; import iap.commander.extentions.Text; import iap.commander.extentions.Draw; import iap.commander.MovieClipCommander; /** * This class demonstrate how much easy it is to create complex behaviours * with so little code */ class Application { private var matrix:Matrix; function Application() { // // defining matrix MovieClipCommander // var mc:MovieClipCommander = new MovieClipCommander(_root, "diamond",0); var matrix:Matrix = Matrix(mc.registerExtention("matrix", Matrix)); // // initializing matrix // matrix._cellHeight = 100; matrix._cellWidth = 100; matrix.defineMatrix(6,8,0, -50, 50); matrix.cellsTemplate("diamond_",""); // // defining what extentions to attach to each matrix cell // matrix.extentionsTemplate( {drag:Drag, ease:Ease, draw:Draw, txt:Text}, {drag:[true], ease:[true], draw:[0x00BBFF,100 ,0x0000FF, 35, true]}); matrix._autoDestroy = false; // // registring listenning to these events // mc.addEventListener(Matrix.EVT_MATRIX_CELL_CREATED, this); mc.addClipEvent("onEnterFrame", this); } /** * Event handling method */ public function handleEvent(evt:Object) { // trace (this+", handle event of type: "+[evt.type, evt.commander, evt.cell]); switch (evt.type) { case "onEnterFrame": // // on each enter frame create the next cell if (evt.commander._commands.matrix.createNextCell() == undefined) { evt.commander.removeClipEvent("onEnterFrame", this); } case Matrix.EVT_MATRIX_CELL_CREATED: // // when a matrix cell is created, we want to initialize it var mc:MovieClipCommander = evt.cell; // // draw its interior mc._commands.draw.diamond(50,50,50); // // creates text inside it mc._commands.txt._text = evt.index; mc._commands.txt.move(45,45); // // listenning to drag events mc.addEventListener(Drag.EVT_START_DRAG, this); mc.addEventListener(Drag.EVT_STOP_DRAG, this); break; case Drag.EVT_START_DRAG: // // when dragging a cell - remove it from matrix var matrix:Matrix = evt.commander._parent._commands.matrix; var mc:MovieClipCommander = evt.commander; mc._core._clip.swapDepths(mc._parent._depth.higher); matrix.removeFromMatrix(evt.commander._params.getNumber("index")); break; case Drag.EVT_STOP_DRAG: // // when stop dragging - push back to matrix var matrix:Matrix = evt.commander._parent._commands.matrix; matrix.pushToMatrix(evt.commander); evt.handled = true; break; } } }