PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
vibration to sound
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: vibration to sound

  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    51

    vibration to sound

    Hello,

    I'm trying to match up a shape so it vibrates to the sound on rollover.
    On rollout I'd like it to slowly deminish the vibration as the sound deminishes too.

    I've experimented with a number of functions with out success.
    I've included the source code i've been working on, any help or pointers to this would be great. Should the source file be required I will supply it on request.

    Thanks

    Actionscript Code:
    var green:Sound = new Doh();

    var channel:SoundChannel = new SoundChannel();

    var greenPosition:Number = 0;

    var blur:BlurFilter = new BlurFilter(10, 10);

    var timer:Timer = new Timer (5000);


    greenBtn.buttonMode = true;

    greenBtn.addEventListener(MouseEvent.MOUSE_OVER, onPlaySound, false, 0, true);
    function onPlaySound(evt:MouseEvent):void {
        channel= green.play(greenPosition);
        greenBtn.filters = [blur];
        greenBtn.scaleX = 2 + channel.leftPeak;
        greenBtn.x+= 10;
        greenBtn.x-= 15;

    }

    greenBtn.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
    timer.addEventListener(TimerEvent.TIMER, onTimer);
    timer.start();

    function onTimer(evt:TimerEvent):void {
        greenBtn.scaleX =1;
        greenBtn.filters = [blur];

    }
    function onOut(evt:MouseEvent):void {
        greenBtn.filters = [];
        greenBtn.scaleX = 1 + channel.leftPeak;
        greenBtn.x = 116;
    }

  2. #2
    Senior Member
    Join Date
    Sep 2010
    Posts
    324
    Not sure this will help but have you seen:
    Sound Driven Animation
    http://www.gotoandlearn.com/index.php?currentpage=10
    Best of luck!
    Video Man

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    If you're looking for beat detection this probably won't help, but if you want to animate the shape based on the shape of the sound wave then you should look up computeSpectrum. If you try that example it'll look like something similar to the bar visualizer for Windows Media Player. It draws that based on an array of values ranging from -1 to 1 returned from computeSpectrum. By the way this function captures every single sound that is playing at one instant, so if you have 2 songs playing at once you can't use this to find the values of 1 song.

  4. #4
    Member
    Join Date
    Apr 2009
    Posts
    51
    Thanks for the pointers.

    Effectively I will want eight sounds that will be activated by rollover, then stopping at rollout, the sounds are about 3-4 seconds and continue for the determined length on rollout. I want this so the sounds overlap as users drag their mouse over each button. I have managed to do this, but what I need is each button to vibrate to the sound, to move acording to the sound, this is where I'm a little stumpped.
    As you can see from the code, I've tried to move the button, given it a blur to enhance the moving effect and applied a timer to give it a determined time to vibrate according to the sound. These functions don't seem to work, they're static, all that changes is the state of the button, from a solid to a blur, with a little move to the right then back to its origin on rollout.

    I'll have a look at some of the gotoAndLearn site I see there is a sound bar that moves to music, but I'm not sure this can be applied to what I want. As for the computeSpectrum, if its only one sound it can do then it won't be what I'm looking for.

    Thanks

  5. #5
    Member
    Join Date
    Apr 2009
    Posts
    51
    Ok I've found a solution, which isn't pure AS, but works well enough.

    I haven't managed to line it up with the sound in AS so what I did was make a few tweens in the mc timline for the duration of the sound, this works, it's not exactly what i wanted but at least it will allow me to continue with the project.

    i've included my code, as you'll note I've added the tween and easing functions to it which have helped immensly, to get the mc back to where it started.

    But should anyone find out how to do it through AS I'd most grateful.

    Thanks

    Actionscript Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;


    var green:Sound = new Doh();

    var channel:SoundChannel = new SoundChannel();

    var greenPosition:Number = 0;

    var blur:BlurFilter = new BlurFilter(10, 10);

    var startPos:Number = 116;
    var endPos:Number = 120;

    greenBtn.buttonMode = true;

    greenBtn.addEventListener(MouseEvent.MOUSE_OVER, onPlaySound, false, 0, true);

    greenBtn.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);


    function onPlaySound(evt:MouseEvent):void {
        channel= green.play(greenPosition);
        greenBtn.filters = [blur];
        //var tOut:Tween = new Tween(evt.currentTarget, "x", Elastic.easeOut, greenBtn.x, greenBtn.x - 4, .5, true);
            var tOut:Tween = new Tween(evt.currentTarget, "x", Bounce.easeOut, greenBtn.x, greenBtn.x - 4, .5, true);
            greenBtn.gotoAndPlay("bounce");


    }

    function onOut(evt:MouseEvent):void {
        greenBtn.filters = [];
        //var tInOut:Tween = new Tween(evt.currentTarget, "x", Elastic.easeInOut, greenBtn.x, greenBtn.x + 2, .5, true);
            var tIn:Tween = new Tween(evt.currentTarget, "x", Bounce.easeIn, evt.currentTarget.x, startPos, 5, true);

    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center