/* MyMatrix by kingnare.com. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.kingnare.controls { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.geom.Matrix; public class MyMatrix extends Sprite { public static const DEFAULT_FRAME:String = "default"; public static const START_FRAME:String = "start"; public static const SUCCESS_FRAME:String = "success"; public static const ERROR_FRAME:String = "error"; public static const WARNING_FRAME:String = "warning"; private var list:Array; private var maxWidth:uint; private var maxHeight:uint; private var _columnNum:uint; private var _hDis:uint; private var _vDis:uint; private var bitmap:Bitmap; private var bitmapData:BitmapData; private var matrix:Matrix; public function MyMatrix() { super(); _hDis = 1; _vDis = 1; _columnNum = 50; maxWidth = 1; maxHeight = 1; matrix = new Matrix(); bitmapData = new BitmapData(1, 1, true, 0); bitmap = new Bitmap(bitmapData); addChild(bitmap); } /** * * @param num * */ private function create(num:uint):void { if(num < 0) return; list = []; for(var i:uint = 0;i= _columnNum-1) { wNum = 0; hNum++; } else { wNum++; } } } maxWidth = _columnNum*(list[0].width + _hDis); maxHeight = (hNum+1)*(list[0].height + _vDis); drawMatrix(); } /** * draw bitmap * */ private function drawMatrix():void { bitmap.bitmapData.dispose(); bitmapData = new BitmapData(maxWidth, maxHeight, true, 0x00FFFFFF); var i:uint = 0; while (list && i < list.length) { matrix.tx = list[i].x; matrix.ty = list[i].y; bitmapData.draw(list[i], matrix); i++; } bitmap.bitmapData = bitmapData; } /** * * @param number * @param status * */ public function setStatus(number:uint, status:String):void { if(number < list.length) { var child:Cell = list[number] as Cell; if(child) { child.gotoAndStop(status); matrix.tx = child.x; matrix.ty = child.y; bitmapData.draw(child, matrix); } } } /** * * @param number * @return * */ public function getStatus(number:uint):String { if(number < list.length) { var child:Cell = list[number] as Cell; if(child) { return child.currentFrameLabel; } } return MyMatrix.DEFAULT_FRAME; } /** * * */ public function clear():void { while(list && list.length>0) { var cell:Cell = list.pop() as Cell; cell = null; } drawMatrix(); } /** * * @param value * */ public function set count(value:uint):void { if(!isNaN(value)) { clear(); if(value > 0) { create(value); } } } /** * * @return * */ public function get count():uint { return list.length; } /** * * @param value * */ public function set columnNum(value:uint):void { _columnNum = value; updateLayout(); } public function get columnNum():uint { return _columnNum; } /** * * @param value * */ public function set hDis(value:uint):void { _hDis = value; updateLayout(); } public function get hDis():uint { return _hDis; } /** * * @param value * */ public function set vDis(value:uint):void { _vDis = value; updateLayout(); } public function get vDis():uint { return _vDis; } } }