[Tweener] continuous flow then static
D
dharmangprajapati at gmail.com
Thu Nov 19 21:25:20 PST 2009
Hello
I am working on an application where you click will generate sound and a
visual
what i am trying to work is how would i get a flowing line with the sound
enables when it reaches to specific x and y pos.
is there any way i can move the point with the movement in mouse ?
package app.demo.bloom{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.*;
import flash.filters.GlowFilter;
import flash.filters.BitmapFilter;
import flash.filters.BitmapFilterQuality;
import flash.filters.DropShadowFilter;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.utils.getDefinitionByName;
//import flash.display.Bitmap;
//import flash.display.BitmapData;
//import flash.filters.*;
//import flash.geom.*;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import caurina.transitions.Tweener;
//import caruina.transitions.Equations;
public class Main extends Sprite
{
//we could use XML instead of this large array, but this will work
for now.
private var majorSounds:Array =
["C1.mp3", "D1.mp3", "E1.mp3", "F1.mp3", "G1.mp3", "A1.mp3",
"B1.mp3",
"C2.mp3", "D2.mp3", "E2.mp3", "F2.mp3", "G2.mp3", "A2.mp3",
"B2.mp3",
"C3.mp3", "D3.mp3", "E3.mp3", "F3.mp3", "G3.mp3", "A3.mp3",
"B3.mp3", "C4.mp3"];
//keep a list of all circles we make
private var line:Array = new Array();
private var circles:Array = new Array();
private var myPath:Array = new Array();
//this will hold all our circle graphics inside it
private var circleHolder:Sprite = new Sprite();
//button for clearing all circles
private var clearButton:Sprite = new Sprite();
private var bgColor:uint = 0xFFFFFF;
private var size:uint = 1;
private var offset:uint = 1;
public function Main() {
//Connect to FLOSC to recieve touch input
TUIO.init(this, 'localhost', 3000, '', true);
//create a new background that blends and changes over time
(with, height, color1, color2)
var backgroundColorChanger = new Bling(stage.stageWidth,
stage.stageHeight, 0x333333 * Math.random(), 0xFFFFFF * Math.random());
addChild(backgroundColorChanger);
//add the circleHolder to the screen
addChild(circleHolder);
//addChild(lineHolder);
//draw the clearButton graphics and add it. We add it last since
we want it on top of everything else.
clearButton.graphics.beginFill(0x333333, .5);
clearButton.graphics.drawRoundRect(0,0,100, 50, 30);
clearButton.graphics.endFill();
clearButton.x = 80;
clearButton.y = 25;
addChild(clearButton);
//draw shadow
draw();
var filter:BitmapFilter = getBitmapFilter();
var myFilters:Array = new Array();
myFilters.push(filter);
filters = myFilters;
//path
myPath.push({_x:20, _y:20});
myPath.push({_x:30, _y:30});
//add down listeners for when we press on the clear button
clearButton.addEventListener(MouseEvent.MOUSE_DOWN,
clearHandler);
clearButton.addEventListener(TouchEvent.MOUSE_DOWN,
clearHandler);
//add stage listener
stage.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
stage.addEventListener(TouchEvent.CLICK, downHandler);
// stage.addEventListener(Event.ENTER_FRAME, updater, false, 0,
true); // keep running
}
private function clearHandler(e:Event)
{
//remove all circles on stage from the circles array and
circleHolder display object
var count:uint = circleHolder.numChildren;
for(var i:uint=0;i<count;i++){
circleHolder.removeChildAt(0);
circles.splice(0,1);
}
//this prevents triggering a 'down' event on the stage
e.stopPropagation();
}
private function downHandler(e:Event)
{
//We limit the amount of circles to 32 because flash only allows
32 maximum sound channels at the same time
if(circles.length <= 32){
//create a random colored circle and add it to circleHolder.
var circle:Sprite = new Sprite();
circle.graphics.lineStyle(3, 0x333333 * (Math.random() +
.2), 1);
//circle.graphics.beginFill(0xFFFFFF, 1);
//circle.graphics.beginFill(0xFFFFFF * (Math.random() + .2),
1);
//circle.graphics.moveTo(0, 0);
//circle.graphics.curveTo(10, 0, 50, 50);
//circle.graphics.lineTo(30, 0);
//circle.graphics.lineTo(-30, 0);
//circle.graphics.lineTo(0, 100);
//circle.graphics.drawRect(-5, -5, 10, 10);
circle.graphics.drawCircle(0, 0, 10);
//circle.graphics.drawCircle(0, 0, 20);
circle.graphics.endFill();
circle.x = e.stageX;
circle.y = e.stageY;
circle.name = 1;
circleHolder.addChild(circle);
//add the circle to the circles array for storage
circles.push(circle);
//fade and resize the circle
tween(circle);
//listen for rollover and down events so we can remove
individual circles
circle.addEventListener(MouseEvent.MOUSE_OVER, rollHandler);
circle.addEventListener(MouseEvent.MOUSE_DOWN,
rollHandler);
circle.addEventListener(TouchEvent.MOUSE_DOWN, rollHandler);
circle.addEventListener(TouchEvent.MOUSE_OVER,
rollHandler);
}
}
private function getBitmapFilter():BitmapFilter {
var color:Number = 0xF7F7F7;
var alpha:Number = 5;
var blurX:Number = 100;
var blurY:Number = 100;
var strength:Number = 10;
var inner:Boolean = false;
var outer:Boolean = true;
var knockout:Boolean = true;
var quality:Number = BitmapFilterQuality.HIGH;
return new GlowFilter(color, alpha, blurX, blurY, strength,
quality, inner, knockout);
}
private function draw():void {
graphics.beginFill(bgColor);
graphics.drawRect(offset, offset, size, size);
graphics.endFill();
}
private function tween(sprite:Sprite){
//this part is used for a temporary hack (for rollover)
sprite.name += 1;
//check if the circle is still active
if(circles.indexOf(sprite, 0) != -1){
//soundsteps is the number of sounds we have divided by the
screenwidth
var soundSteps = stage.stageWidth/22;
//since there's 37 sounds, we use that many
for (i = 0; i < 22; i++)
{
//find what note to play based on it's x-asix
if(sprite.x > (i * soundSteps) && sprite.x < (i *
soundSteps) + soundSteps){
playNote(i);
break;
}
}
//set circle alpha
sprite.alpha = 1;
//set circle scale
sprite.scaleX = sprite.scaleY = 2;
//start tweening the fade and scale
Tweener.addTween(sprite, {scaleX: 3, scaleY: 3,_color:
0x00ff1e, alpha: 100, rotation: 360 , delay: 0, time: 2.5,
transition:"easeInOutElastic", onComplete:tween,
onCompleteParams:[sprite]});
}
}
private function playNote(note:Number){
//get the soundd by requesting it from the swf folder
var soundBg:Sound = new Sound(new URLRequest("sound/" +
majorSounds[note]));
//play the sound
var sc:SoundChannel = soundBg.play(5);
if(sc != null){
//create a soundtransform object so we can set the volume of
the sound
var st:SoundTransform = sc.soundTransform;
//we change volume because flash likes to play things really
loud if you don't
st.volume = .5;
sc.soundTransform = st;
}
}
private function rollHandler(e:Event)
{
//this is used for a temporary hack (for rollover)
if(e.currentTarget.name > 11){
//when we remove a circle, let's have it fade out. When it's
completley faded, we'll remove it.
Tweener.addTween(e.currentTarget, {scaleX: 0, scaleY: 0,
alpha: 0, delay: 0,
time: .25,
transition:"easeInOutElastic",
onComplete:function()
{circleHolder.removeChild(e.target);
var index =
circles.indexOf(e.target);
circles.splice(index,1);}});
}
}
}
}
Thanks,
Dharmang
http://www.dharmang.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20091120/edb397d7/attachment.htm>
More information about the Tweener
mailing list