/ Published in: ActionScript 3
Taken from Christian Cantrell's Adobe article called 'Authoring mobile Flash content for multiple screen sizes'.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Display as many blocks on the screen as will fit var BLOCK_SIZE:Number = 1; var BLOCK_BUFFER:uint = 3; var blockSize:uint = this.inchesToPixels(BLOCK_SIZE); var blockTotal:uint = blockSize + BLOCK_BUFFER; var cols:uint = Math.floor(this.stage.stageWidth / blockTotal); var rows:uint = Math.floor((this.stage.stageHeight) / blockTotal); var blockXStart:uint = (this.stage.stageWidth - ((cols * blockSize) + ((cols - 1) * BLOCK_BUFFER))) / 2; var blockX:uint = blockXStart; var blockY:uint = ((this.stage.stageHeight) - ((rows * blockSize) + ((rows - 1) * BLOCK_BUFFER))) / 2; for (var colIndex:uint = 0; colIndex < rows; ++colIndex) { for (var rowIndex:uint = 0; rowIndex < cols; ++rowIndex) { var block:Sprite = this.getBlock(blockSize); block.x = blockX; block.y = blockY; this.addChild(block); blockX += blockTotal; } blockY += blockTotal; blockX = blockXStart; } function getBlock(blockSize:uint):Sprite { var block:Sprite = new Sprite(); block.graphics.beginFill(0xAAC228); block.graphics.drawRect(0, 0, blockSize, blockSize); block.graphics.endFill(); block.cacheAsBitmap = true; return block; } function inchesToPixels(inches:Number):uint { return Math.round(Capabilities.screenDPI * inches); }
URL: http://www.adobe.com/devnet/flash/articles/authoring_for_multiple_screen_sizes.html