Control how sound plays through the right and left speakers
Switch the right and left speakers
To switch the left and right speakers:
- Import a sound file into Flash.
- With the sound selected in the Library, from the Options menu in the Library panel, choose Linkage. The Linkage Properties dialog box opens.
- Select the Export for ActionScript check box, and give the sound a linkage identifier (Figure 2).
Figure 2: This sound is identified in the Library as conversationID.
- Create a button symbol, place an instance of it on the Stage, and give it a name in the Property inspector.
- Select the first frame of the main Timeline, and open the Actions panel.
- Instantiate a new Sound object, as you did earlier in this chapter (Figure 3). Don’t specify a target movie clip for the parameter.
Figure 3: The mySound_sound Sound object is created.
- Attach the sound to this Sound object with the method attachSound().
- Create an onRelease event handler for your button.
- Choose the start() method for your Sound object (Figure 4). This button plays your sound.
Figure 4: The sound called conversationID plays five times when the button called startButton_btn is clicked.
- Place another instance of the button symbol on the Stage, and give it a name in the Property inspector.
- In the Actions panel, assign an onRelease event handler to the second button.
- Inside the event handler function, declare your transformation object by entering var, a name, and :Object followed by an equals sign.
- Choose ActionScript 2.0 Classes > Core > Object > “new Object.” Your new sound transformation object is instantiated (Figure 5).
Figure 5: Within the onRelease handler for the button called transformButton_btn, the object mySoundTransform is created as an instance of the generic Object class.
- On the next line of the onRelease event, enter the name of your sound transformation object followed by a period and then one of the properties. Enter an equals sign and then a number representing the percentage for that property. Do this for all four properties (Figure 6). The properties of your sound transformation object are defined. These properties will be used by the setTransform() method.
Figure 6: In the onRelease handler for the button called transformButton_btn, the four properties to be used by the setTransform() method are defined as properties of the object mySoundTransform.
- On the next line, still inside the onRelease event, enter the name of your Sound object followed by a period.
- Choose ActionScript 2.0 Classes > Media > Sound > Methods > setTransform.
- With your pointer between the parentheses, enter the name of your sound transformation object (Figure 7).
Figure 7: In the onRelease handler for the button called transformButton_btn, add the setTransform() method with the object mySoundTransform as its parameter. The four properties of the mySoundTransform object supply the method with the information required to distribute the sound to the left and right speakers.
- 18 Test your movie. When you click the second button, Flash creates a generic object whose properties (mySoundTransform.ll, mySoundTransform.lr, and so on) hold the sound transformation information. This information is then used by the setTransform() method to change the distribution of sound in the left and right speakers.
Where to go from here
For more information about working with sound in Flash, see the following articles: