Creating multiple instances of a shape honeyedoasis.. forked:0favorite:0lines:39license : MIT License modified : 2011-10-07 13:56:41 Embed Tweet package { import flash.display.Shape; import flash.display.Sprite; public class MultipleObjects extends Sprite { public function MultipleObjects() { Draw10RandomRectangles(); } public function Block(xPos:int , yPos:int, width:int, height:int):Shape { var Block:Shape = new Shape(); Block.graphics.beginFill(0x00ff00); Block.graphics.lineStyle(2, 0x000000); Block.graphics.drawRect(xPos, yPos, width, height); Block.graphics.endFill(); return Block; } public function DrawRandomRectangle():void { stage.addChild ( Block ( Math.round(Math.random() * stage.stageWidth), Math.round(Math.random() * stage.stageHeight), Math.round(Math.random() * 100), Math.round(Math.random() * 100) ) ); } public function Draw10RandomRectangles():void { for (var cnt:int = 0; cnt <= 10; cnt++) { DrawRandomRectangle(); } } } } Code Fullscreen Preview Fullscreen Basic Copy Multiple Rectangle Shape Simple Math.round height width addChild Math.random Sprite int