forked from: Tween reacting on microphone, forked from: 光る玉
// forked from Kallethyselius's Tween reacting on microphone, forked from: 光る玉
// forked from Kallethyselius's forked from: forked from: 光る玉
package
{
import caurina.transitions.Tweener;
import caurina.transitions.properties.CurveModifiers;
import flash.display.*;;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.utils.*;
import flash.media.*;
import flash.system.*;
import flash.ui.*;
import flash.text.*;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]
public class bezier extends Sprite
{
private var bmpd:BitmapData;
private var colorMatrix:ColorMatrixFilter;
private var Blur:BlurFilter;
private var myMic:Microphone;
private var sprites:Array;
public function bezier()
{
bmpd = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
var bmp:Bitmap = new Bitmap(bmpd);
addChild(bmp);
sprites = [];
var timer:Timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
CurveModifiers.init();
colorMatrix = new ColorMatrixFilter([0.99, 0, 0, 0, 1, 0, 0.99, 0, 0, 1, 0, 0, 0.99, 0, 1, 0, 0, 0, 0.99]);
Blur = new BlurFilter(8, 8, 1);
addEventListener(Event.ENTER_FRAME, onFrame);
myMic = Microphone.getMicrophone();
//Security.showSettings(SecurityPanel.MICROPHONE);
myMic.setLoopBack(true);
myMic.setUseEchoSuppression(true);
initFullScreen();
}
private function onTimer(e:TimerEvent):void
{
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xffffff * Math.random(), 1);
sp.graphics.drawCircle(0, 0, 20 * Math.random() + 4);
sp.graphics.endFill();
var spHolder:Sprite = new Sprite();
addChild(spHolder);
spHolder.addChild(sp);
spHolder.x = -10;
spHolder.y = 495*Math.random()-30;
spHolder.scaleX = spHolder.scaleY = spHolder.alpha = 0;
spHolder.filters = [new BlurFilter(32, 32, 1)];
spHolder.blendMode = BlendMode.ADD;
sprites.push(sp);
var t:Number=(13 - 8) * Math.random() + 8;
Tweener.addTween(spHolder, {alpha:0.5, scaleX:1, scaleY:1, time:1});
Tweener.addTween(spHolder, {x:600, y:465*Math.random(), _bezier:[{x:232.5, y:665*Math.random()-100}], time:t})
Tweener.addTween(spHolder, {alpha:0, scaleX:0, scaleY:0, time:1, delay:t-2, onComplete:function():void
{
spHolder.removeChild(sp);
sp.filters = [];
sp.graphics.clear();
sp = null;
removeChild(spHolder);
spHolder = null;
}});
}
private function onFrame(e:Event):void
{
bmpd.draw(this);
bmpd.applyFilter(bmpd, bmpd.rect, new Point(0, 0), Blur);
bmpd.applyFilter(bmpd, bmpd.rect, new Point(0, 0), colorMatrix);
for each(var item:Sprite in sprites)
{
item.y += myMic.activityLevel*20 * (Math.random()-0.50) ;
}
}
private var myContextMenu:ContextMenu;
public function initFullScreen():void
{
myContextMenu = new ContextMenu();
removeDefaultItems();
addCustomMenuItems();
this.contextMenu = myContextMenu;
addChild(createLabel());
}
private function removeDefaultItems():void
{
myContextMenu.hideBuiltInItems();
var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
defaultItems.print = true;
}
private function addCustomMenuItems():void
{
// add the full screen item
var fs:ContextMenuItem = new ContextMenuItem("Go Full Screen" );
fs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onShowFullScreen);
myContextMenu.customItems.push( fs );
// add the 'back to normal size' option
var xfs:ContextMenuItem = new ContextMenuItem("Exit Full Screen");
xfs.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onShowNormalScreen);
myContextMenu.customItems.push( xfs );
}
public function onShowFullScreen(event:ContextMenuEvent):void
{
// Go Full Screen Option Selected
stage.displayState = StageDisplayState.FULL_SCREEN;
}
private function onShowNormalScreen(event:ContextMenuEvent):void
{
// Exit Full Screen Option Selected
stage.displayState = StageDisplayState.NORMAL;
}
private function createLabel():TextField
{
var txtField:TextField = new TextField();
txtField.text = "Right-click the stage area and choose enter Full Screen";
txtField.x = 0;
txtField.y = 0;
txtField.width = stage.stageWidth;
return txtField;
}
}
}