Flying Through Smiley Space web_netHacke.. forked:0favorite:2lines:116license : All rights reserved modified : 2009-05-09 03:03:23 Embed Tweet package { import flash.display.Sprite; import flash.display.Shape; import flash.events.Event; import flash.display.DisplayObject; public class FlashTest extends Sprite { private var cycleCount:int = 0; private var faceArray:Array; public function FlashTest() { faceArray = new Array(); addEventListener(Event.ENTER_FRAME, main); } private function main(event:Event):void { //comment out to stop if (cycleCount % 4 == 0) { makeFace(); bubbleZSort(); } for (var i:int = 0; i < faceArray.length; i ++) { var face:Face = faceArray[i]; face.z -= 40; if (face.z < -2000) { removeChild(face); faceArray.splice(i, 1); } } cycleCount ++; } private function makeFace():void { var face:Face = new Face(Face.HAPPY); face.x = Math.random() * 1000; if (Math.random() > 0.5) face.x = -face.x; face.y = Math.random() * 1000; if (Math.random() > 0.5) face.y = -face.y; face.z = 6000; addChild(face); faceArray.push(face); } private function bubbleZSort():void { do { var swapped:Boolean = false; for (var i:int = 0; i < numChildren - 1; i ++) { var curItem:DisplayObject = getChildAt(i); var nextItem:DisplayObject = getChildAt(i + 1); if (curItem.z < nextItem.z) { swapChildren(curItem, nextItem); swapped = true; } } } while (swapped == true); } } } import flash.display.Sprite; import flash.display.Shape; class Face extends Sprite { private var headColor:uint; private var eyeColor:uint; private var mouthColor:uint; private var faceType:uint; public static const HAPPY:uint = 0; public function Face(type:uint) { faceType = type; headColor = uint(Math.random() * 0xFFFFFF); eyeColor = 0xFFFFFF; mouthColor = 0xFFFFFF; drawHead(); drawEyes(); drawMouth(); } private function drawHead():void { var circ:Shape = new Shape(); circ.graphics.beginFill(headColor, 1); circ.graphics.drawCircle(0, 0, 50); circ.graphics.endFill(); addChild(circ); } private function drawEyes():void { var circOne:Shape = new Shape(); circOne.graphics.beginFill(eyeColor, 1); circOne.graphics.drawCircle(-width / 5, -height / 5, 10); circOne.graphics.endFill(); addChild(circOne); var circTwo:Shape = new Shape(); circTwo.graphics.beginFill(eyeColor, 1); circTwo.graphics.drawCircle(width / 5, -height / 5, 10); circTwo.graphics.endFill(); addChild(circTwo); if (faceType == Face.HAPPY) { var eyeCoverOne:Shape = new Shape(); eyeCoverOne.graphics.beginFill(headColor, 1); eyeCoverOne.graphics.drawCircle(-width / 5, -height / 8, 10); eyeCoverOne.graphics.endFill(); addChild(eyeCoverOne); var eyeCoverTwo:Shape = new Shape(); eyeCoverTwo.graphics.beginFill(headColor, 1); eyeCoverTwo.graphics.drawCircle(width / 5, -height / 8, 10); eyeCoverTwo.graphics.endFill(); addChild(eyeCoverTwo); } } private function drawMouth():void { var circOne:Shape = new Shape(); circOne.graphics.beginFill(mouthColor, 1); circOne.graphics.drawCircle(0, height / 4, 15); circOne.graphics.endFill(); addChild(circOne); if (faceType == Face.HAPPY) { var mouthCover:Shape = new Shape(); mouthCover.graphics.beginFill(headColor, 1); mouthCover.graphics.drawCircle(0, height / 6, 15); mouthCover.graphics.endFill(); addChild(mouthCover); } } } Code Fullscreen Preview Fullscreen bradsedito asnike : faceflysmilethroughgood face fly happy smile through height Shape width type addEventListener splice push Boolean length Event.ENTER_FRAME Array uint Math.random Event int