home *** CD-ROM | disk | FTP | other *** search
- function Grid(width, height, cellWidth, cellHeight, display_mc)
- {
- this.gridWidth = width;
- this.gridHeight = height;
- this.xUnitsPerCell = cellWidth;
- this.yUnitsPerCell = cellHeight;
- var _loc7_ = 100 / width;
- var _loc8_ = 100 / height;
- this.cells = new Array(width);
- this.allCells = new Array();
- this.allContents = new Array();
- var _loc4_ = 0;
- while(_loc4_ < this.cells.length)
- {
- this.cells[_loc4_] = new Array(height);
- var _loc3_ = 0;
- while(_loc3_ < this.cells[_loc4_].length)
- {
- var _loc5_ = new Grid.Cell(_loc4_,_loc3_);
- this.cells[_loc4_][_loc3_] = _loc5_;
- var _loc6_ = this.allCells.push(_loc5_);
- _loc5_.id = _loc6_;
- display_mc.attachMovie("grid_cell","grid_cell_" + _loc6_,_loc6_);
- var _loc2_ = display_mc["grid_cell_" + _loc6_];
- _loc2_._x = _loc4_ * _loc7_;
- _loc2_._y = _loc3_ * _loc8_;
- _loc2_._width = _loc7_;
- _loc2_._height = _loc8_;
- _loc2_.gridCell = _loc5_;
- _loc2_.text = _loc4_ + "," + _loc3_;
- _loc5_.display_mc = _loc2_;
- _loc3_ = _loc3_ + 1;
- }
- _loc4_ = _loc4_ + 1;
- }
- }
- var t = Grid.prototype;
- t.mc = false;
- t.getCell = function(x, y)
- {
- return this.cells[x][y];
- };
- t.mapCell = function(x, y)
- {
- var _loc3_ = Math.floor(x / this.xUnitsPerCell);
- var _loc2_ = Math.floor(y / this.yUnitsPerCell);
- var _loc4_ = this.cells[_loc3_][_loc2_];
- return _loc4_;
- };
- t.placeInGrid = function(obj, x, y)
- {
- var _loc2_ = this.mapCell(x,y);
- if(obj.curGridCell == _loc2_)
- {
- return false;
- }
- obj.curGridCell.removeContent(obj);
- _loc2_.addContent(obj);
- this.allContents[obj.id] = _loc2_;
- };
- t.removeFromGrid = function(obj)
- {
- var _loc2_ = this.allContents[obj.id];
- _loc2_.removeContent(obj);
- };
- t.totalCells = 0;
- t.cells = false;
- t.allCells = false;
- t.allContents = false;
- t.xUnitsPerCell = 0;
- t.yUnitsPerCell = 0;
- t.gridWidth = 0;
- t.gridHeight = 0;
- Grid.Cell = function(x, y)
- {
- this.x = x;
- this.y = y;
- this.contents = new Array();
- };
- var t = Grid.Cell.prototype;
- t.x = 0;
- t.y = 0;
- t.id = 0;
- t.addContent = function(obj)
- {
- this.contents[obj.id] = this.contents.push(obj) - 1;
- obj.curGridCell = this;
- this.display_mc.nextFrame();
- };
- t.removeContent = function(obj)
- {
- var _loc2_ = 0;
- while(_loc2_ < this.contents.length)
- {
- if(this.contents[_loc2_] == obj)
- {
- this.contents.splice(_loc2_,1);
- break;
- }
- _loc2_ = _loc2_ + 1;
- }
- if(this.contents.length <= 0)
- {
- this.display_mc.prevFrame();
- }
- };
- t.contentsAsString = function()
- {
- var _loc3_ = "";
- var _loc2_ = 0;
- while(_loc2_ < this.contents.length)
- {
- _loc3_ += this.contents[_loc2_].id + ", ";
- _loc2_ = _loc2_ + 1;
- }
- return _loc3_;
- };
- t.contents = false;
- t.toString = function()
- {
- return "[Cell " + this.x + "," + this.y + "]";
- };
-