dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How to control multiple sounds for global panning?

  1. #1
    dude Jammin-D's Avatar
    Join Date
    Jun 2001
    Location
    Kent, England
    Posts
    334

    How to control multiple sounds for global panning?

    Hi,

    Is there a way to control the volume / panning of multiple sounds using slider / position of mouse?

    If so, could you provide a link to a tutorial on this for me?

    Many thanks in advance

    Ben
    Imagination is more important than knowledge. Knowledge is limited, Imagination encircles the world.

  2. #2
    Moderator
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    you can pan all sounds in the player with a global sound object.

    global = new Sound(); // no associated mc in sound function
    global.setPan(-100); // pan all sounds to the left speaker

    as for interaction, sure you can use a slider or your mouse position to change pan. These are two different technical problems though. Which one are you interested in?
    aviarts.com - web development and flash development

  3. #3
    dude Jammin-D's Avatar
    Join Date
    Jun 2001
    Location
    Kent, England
    Posts
    334
    Well if you could explain the difficulties with the mouse position that would be really good of you, also are there any tech difficults when using the mouse position to adjust the global sound's volume?

    for instance, the panning is effect by _xmouse and the volume by _ymouse, would this cause me any problems?

    Thanks again in advance.
    Imagination is more important than knowledge. Knowledge is limited, Imagination encircles the world.

  4. #4
    Moderator
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    for mouse position sound control, you would need to know the width and height of the SWF. I think you can get this from _width and _heigth parameters of the level0 _root timeline.

    convert the mouse position into a percentage (value of 0 - 100) by dividing the position by the width or height. You have to flip the value because the upper left corner of _root is 0,0. So subtract by 100 to make to of scree full volume and bottom of screen 0 volume.

    Code:
    /* 
    upper left corner is 0,0
    subtract by 100 to make top of movie 100 volume
    */
    volume = 100 - Math.round(_root._ymouse/_root._height * 100);
    pan is a little more complicated because you have a range of 200
    values (-100 to 100). The example below should generate values in the desired range as every other value rather than 200 distinct values.

    Code:
    /*
    convert _xmouse into a percentage
    multiply by 2 to get a number range of 0 - 200
    subtract by 100 to shift range to -100 to 100
    */
    pan = 100 - ((_root._xmouse/_root._width * 100) * 2)
    once you convert _xmouse and _ymouse to appropriate pan and volume values, you need a way to update the values as user moves mouse. you can use mouse move event or a looping mc to update sound. looping mc is probably more cpu efficient.

    Code:
    /*
    update volume and pan from mouse coords per frame rate
    of a looping movie clip or enterFrame loop
    */
    onClipEvent(enterFrame){
       volume = 100 - Math.round(_root._ymouse/_root._height * 100);
       pan = 100 - (Math.round(_root._xmouse/_root._width * 100) * 2)
       _root.global.setVolume(volume);
       _root.global.setPan(pan);
    }
    I have not tested this code but hopefully you get the general idea of how to approach the problem.
    aviarts.com - web development and flash development

  5. #5
    dude Jammin-D's Avatar
    Join Date
    Jun 2001
    Location
    Kent, England
    Posts
    334
    OMG dude, thank you soo much, I owe you a beer (or a whole crate you choose lol, )

    Thank you so much,

    Ben

    p.s - i'll let you know how i get on!
    Imagination is more important than knowledge. Knowledge is limited, Imagination encircles the world.

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