package { import flash.display.DisplayObject; import flash.display.Sprite; import flash.events.Event; import flash.media.Microphone; import flash.system.Security; import flash.system.SecurityPanel; import flash.utils.getTimer; /** * Phlashers 2010 AS3 Contest * http://www.phlashers.com */ [SWF(width=465, height=465, frameRate=60, backgroundColor=0x000000)] public class Main extends Sprite { public static var SPEED:int = 2; public static var HIT:Sprite; public var lns:Array; public var ds:Array; public var ys:Array; public var ls:Array; public var d:uint; public var c:uint; public var cnt:uint; public var mic:Microphone; public function a(_l:int, _w:int,_y:int, l:String):void { lns.push(_l); ds.push(_w); ys.push(_y); ls.push(l); } public function Main():void { addEventListener(Event.ADDED_TO_STAGE, init); } public function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); addChild(new Vol(30)); addChild(new Vol(70)); addChild(new Vol(110)); addChild(new Vol(150)); addChild(new Vol(190)); addChild(new Vol(230)); addChild(new Vol(270)); addChild(new Vol(310)); mic = Microphone.getMicrophone(); Security.showSettings(SecurityPanel.MICROPHONE); mic.setLoopBack(true); mic.setUseEchoSuppression(true); lns = new Array(); ds = new Array(); ys = new Array(); ls = new Array(); d = 0; c = 0; a(8, 2000, 1, "Ha-"); a(8, 400, 1, "-ppy"); a(16, 800, 2, "birth"); a(16, 800, 1, "day"); a(16, 800, 4, "to"); a(32, 800, 3, "you"); a(8, 1600, 1, "Ha-"); a(8, 400, 1, "-ppy"); a(16, 800, 2, "birth"); a(16, 800, 1, "day"); a(16, 800, 5, "to"); a(32, 800, 4, "you"); a(8, 1600, 1, "Ha-"); a(8, 400, 1, "-ppy"); a(16, 800, 8, "birth"); a(32, 800, 6, "day"); a(8, 1600, 4, "Ha-"); a(8, 400, 4, "-ppy"); a(16, 800, 3, "birth"); a(32, 800, 2, "day"); a(8, 1600, 7, "Ha-"); a(8, 400, 7, "-ppy"); a(16, 800, 6, "birth"); a(16, 800, 4, "day"); a(16, 800, 5, "to"); a(32, 800, 4, "you"); cnt = lns.length; v = new Sprite(); v.graphics.beginFill(0xFF0000); v.graphics.drawCircle(0, 0, 15); v.graphics.endFill(); HIT = v; addChild(v); addEventListener(Event.ENTER_FRAME, this_EnterFrame); } public var v:Sprite; public function this_EnterFrame(e:Event):void { if (c < cnt) { if (ds[c] + d < getTimer()) { addChild(new Note(ys[c], lns[c], ls[c])); d += ds[c]; c++; } } var mL:Number = 0; if (mic.activityLevel > 0) { mL = mic.activityLevel - (mic.activityLevel % 35); v.y = 310 - (mL * 2.8); v.x = 30; } else { v.x = -1000; } } } } import flash.events.Event; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; class Vol extends Sprite { public function Vol(_y:int) { var color:uint = 0x999999 + (Math.random() * 0x666666) graphics.beginFill(color); graphics.drawRect(30, _y, 20, 20); graphics.endFill(); graphics.moveTo(50, _y + 10); graphics.lineStyle(2, color + 0x222222); graphics.lineTo(465, _y + 10); } } class Note extends Sprite { public function Note(_y:int, _w:int, _l:String) { var color:uint = 0x333333 + (Math.random() * 0x666666) graphics.beginFill(color); graphics.lineStyle(3, 0xFFFFFF); graphics.drawRoundRect(0, 0, _w * 5, 10, 3, 3); graphics.endFill(); x = 500; y = ((8 - _y) * 40) + 35; var l:TextField = new TextField(); l.text = _l l.setTextFormat(new TextFormat("Arial", 12, 0XFFFFFF, true)); l.y = 12; l.x = 10; addChild(l); addEventListener(Event.ENTER_FRAME, t_oEF); } public function t_oEF(e:Event):void { this.x -= Main.SPEED; if (hitTestObject(Main.HIT)) { removeEventListener(Event.ENTER_FRAME, t_oEF); parent.removeChild(this); } } } Vocal Hero