-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test.as
91 lines (71 loc) · 1.99 KB
/
Test.as
1
var currentTile:int = 0; var horizontalTiles:int = 20;var verticalTiles:int = 10; var totalTiles:int = mcCurrentTile.totalFrames; var levelTilesContainer:Sprite = new Sprite(); makeSelectionTiles();makeLevelTiles(); function makeSelectionTiles():void { var container:Sprite = new Sprite(); container.x = 200; container.y = 20; for (var i:int; i<totalTiles; i++) { var tile:Tile = new Tile(); tile.gotoAndStop(i + 1); container.addChild(tile); tile.x = (tile.width - 1) * i; tile.addEventListener(MouseEvent.MOUSE_DOWN, selectionClick); } addChild(container);} function selectionClick(evt:MouseEvent):void { currentTile = evt.currentTarget.currentFrame; updateCurrentTile();} function updateCurrentTile():void { mcCurrentTile.gotoAndStop(currentTile);} function makeLevelTiles():void { var xPos:Number = 0; var yPos:Number = 0; for (var i:int=0; i<verticalTiles; i++) { for (var j:int=0; j<horizontalTiles; j++) { var tile:Tile = new Tile(); tile.x = xPos; tile.y = yPos; tile.name = "" + i + j; tile.addEventListener(MouseEvent.MOUSE_DOWN, levelClick); levelTilesContainer.addChild(tile); xPos += (tile.width - 1); } yPos += (tile.height - 1); xPos = 0; } levelTilesContainer.x = 50; levelTilesContainer.y = 100; addChild(levelTilesContainer); } function levelClick(evt:MouseEvent):void { evt.currentTarget.gotoAndStop(currentTile);} btnGenerate.addEventListener(MouseEvent.MOUSE_DOWN, generateClick); function generateClick(evt:MouseEvent):void { var array:String = "[ "; for (var i:int=0; i<verticalTiles; i++) { array += "["; for (var j:int=0; j<horizontalTiles; j++) { var target:DisplayObject = levelTilesContainer.getChildByName("" + i + j); if (j == (horizontalTiles - 1)) { array += (MovieClip(target).currentFrame - 1); } else { array += (MovieClip(target).currentFrame - 1) + ", "; } } if (i == (verticalTiles - 1)) { array += "] ]"; } else { array += "],\n"; } } trace(array);}