A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Pan/Volume based on X,Y

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    1

    Pan/Volume based on X,Y

    Hey y'all...

    Trying to get the children of lighterBoard to pan to different channels based on their Y coordinate.(children on the left side of the screen play left channel, children in the middle play both, right side, right channel etc.)

    volume works on X for the lighterBoard.

    Having trouble with Pan and getting it to look at the children.

    Halp?



    }
    function playVol01() {
    trace("Swoosh Sounded");
    Vol01Channel=Vol01Sound.play();
    var Vol01Transform=Vol01Channel.soundTransform;
    Vol01Transform.volume=1-((lighterBoard.y)/500);
    Vol01Channel.soundTransform=Vol01Transform;
    Vol01Transform.pan=???;
    }

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Your description has x and y backwards, but your code has them correct.

    pan goes from -1 (full left) to 1 (full right), so you need to map your coordinates to that range.

    Code:
    Vol01Transform.pan = (lighterBoard.x/stage.stageWidth)*2 - 1;
    This uses the x coordinate to calculate the percentage of the screen width that the lighterboard is at (middle is 50%). Multiply that by 2 because the range from -1 to 1 is 2, then subtract 1 so that it goes from -1 to 1 instead of 0 to 2.

    edit: if you want to apply this to individual children, you can use the child instead of lighterBoard. Depending on what it's relative to, you might have to change stage.stageWidth to lighterBoard.width.

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