When a Sound Ends
Posted by Admin in Uncategorized on December 13th, 2009
You can use the duration and position of a sound to determine when a sound ends. They will be equal to each other. However, if a sound loops, the duration and position of a sound will be equal to each other for a moment at the end of each playback of the sound.
A better way to determine the end of a sound is to use the onSoundComplete listener.
This is a function triggered when the sound is finished playing.
Setting the Balance
You can also direct the sound more to one speaker than the other with the setPan command. This is similar to the balance control on a stereo.
You can set the pan of a sound to a value from -100 to 100. If you set it to -100, all sound comes from the left speaker. Setting it to 100 means that all sound comes from the right speaker.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Sound Properties
Posted by Admin in Uncategorized on December 10th, 2009
Sound objects have two properties that you should know about. The first is duration. This is the how long the sound is, in milliseconds.
The sibling property to this is position. This is the location of the current bit of sound being played, in milliseconds.
For instance, if a sound has a duration of 3000, it is 3 seconds long. If the position of the sound is 1500, the sound is right in the middle of being played.
The example movie 22tracksound.fla demonstrates using position and duration to show the playback of a sound visually.
After starting a sound, a movie clip script positions a movie clip named mark at a position along the width of a movie clip named bar.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Adjusting Volume
Posted by Admin in Uncategorized on December 7th, 2009
You can alter a sound both before and during playback with a variety of commands. All these commands somehow alter the volume of the sound, in both speakers together or separately.
The setVolume command is the simplest of these adjustments. By setting the volume to a number from 0 to 100, you can raise, lower, or silence a sound:
mySound.setVolume(50);
The example movie 22playsoundvolume.fla features a Play button and four different volume buttons. The top one sets the volume to 0, the next one to 10, the next to 50, and the bottom button to 100. The Play button plays a sound 100 times so that you can have the chance to adjust the volume while it plays.
You can click a button during playback to adjust the volume. Note that adjusting the volume of a specific sound does not affect the volumes of other sounds being played at the same time. This means that you can have separate controls for different sounds—such as background music and instance sounds.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
The start Command
Posted by Admin in Uncategorized on December 4th, 2009
The start command in the previous example can be used in a few different ways. You can add up to two additional parameters to it to alter the way the sound plays.
The first parameter you can add is an offset. This starts the sound somewhere in the middle, rather than at the beginning. For instance, this line starts the sound off 1000 milliseconds, or 1 second, into the sound:
mySound.start(1000);
The second parameter the start command can take is the number of loops. For instance, if you want to start the sound off at 1 second and loop it three times, you would do this:
mySound.start(1000,3);
If you want to start the sound at the beginning and loop it three times, just use 0 as the offset:
mySound.start(0,3);
The companion command to start is stop. If you are playing a long sound, you can issue a stop command at any time to halt the sound in its tracks. You must supply the sound name again as a parameter. Otherwise, the stop command stops all sounds playing.
mySound.stop(”poof.wav”);
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
For instance
Posted by Admin in Uncategorized on December 1st, 2009
For instance, if you import the file mysound.wav, it will appear in the Library as mysound.wav. When you set its Linkage properties so that it exports with the file, it will be assigned the linkage name mysound.wav, but you can change that to anything you want. It is this linkage name that you will use to refer to the sound in your code.
You can find this simple example in the movie 22playsound.fla. You can find a slightly more sophisticated approach in the movie 22playsoundfunction.fla. In this movie, a function called playSound is placed in the main timeline. This function includes all the code you need to play a simple sound.
By using this function, you can simplify your ActionScript so that you can play a sound with only one line. Here is a button script that uses this function:
on (release) {
playSound(”poof.wav”);
}
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Although the ScrollPane
Posted by Admin in Uncategorized on November 28th, 2009
Although the ScrollPane does not require any ActionScript at all to work, there are plenty of functions that you can use to determine which part of the movie clip is being viewed or to change the width and height of the pane.
You can also use the Properties panel to change the width and height of the scroll pane. When you do this, the scroll pane looks distorted in Flash, but it looks fine when you run the movie.
One useful ActionScript command is the loadScrollContent command. This command takes a URL and gets an external movie clip to display in the pane.
The scroll pane can be useful as an image browser.
ScrollBar
The last component is the ScrollBar. This adds scrolling bars to text fields. You can use this component without any ActionScript at all. Just drag and drop a ScrollBar component to a text field, and it adds itself there.
The ScrollBar component does have a small list of ActionScript-accessible properties. For instance, you can use getScrollPosition() to get the current scroll position and setScrollPosition() to change it.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
ScrollPane
Posted by Admin in Uncategorized on November 25th, 2009
The next two components are different from the previous five. They are not used to allow the user to make choices, but are instead used to display large amounts of information in small spaces.
The ScrollPane component consists of a vertical and horizontal scrollbar and a rectangular viewing area. Its main parameter is Scroll Content. This is the Linkage name for a movie clip. When you run the movie, the movie clip is copied from the Library and placed in the view area of the scroll pane. The scrollbars then allow the user to view different parts of the movie clip.
Figure 21.9 shows the ScrollPane with a movie clip inside. You can see this example in the movie 21scrollpane.fla.
If you set the Drag Content parameter to true, the user can also click in the display area and drag the image around. The scrollbars follow the dragging.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
shows all three variations
Posted by Admin in Uncategorized on November 22nd, 2009
shows all three variations of a combo box. The box on the left is what a combo box looks like when it is inactive. The second box shows what happens when the user clicks the combo box. The third box shows what happens when there are more choices than rows.
When a user selects a new choice in the combo box, the Click Handler is called. Here is one that simply tells you the label that was selected:
You can also use getSelectedIndex() to get the zero-based number of the selected choice.
The example movie 21combobox.fla shows an example of a ComboBox component.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
ComboBox
Posted by Admin in Uncategorized on November 19th, 2009
A combo box is something that Windows users will be familiar with, but no such thing exists in standard Macintosh interfaces. It is a pull-down menu where the user can also type in a value manually.
Fortunately, you can also turn off the option to edit the value. This turns the combo box into a normal pull-down menu. The parameter for doing this is the first one in the Properties dialog for a combo box, named Editable. In addition to that parameter, you can also provide arrays for the Labels and Data.
Another parameter for a combo box is the Row Count. Combo boxes can act a little like list boxes. When the user clicks them, they expand into a list of choices. If the number of choices exceeds the Row Count, a scrolling bar appears to the right to allow the user to scroll through the choices.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
There is also a PushButton
Posted by Admin in Uncategorized on November 16th, 2009
There is also a PushButton component in the example movie. When it is clicked, it runs this function. It uses the getSelectedItems() function to get an array of the choices selected in the list box. Each item in the array is an object with a label and data property. Because we didn’t use the data properties of the list box, we’ll get the labels instead.
You can also add or remove lines from the list box using ActionScript. For instance, addItem adds an additional choice to the list box.
myListBox.addItem(”Choice Four”);
You can use addItemAt, removeItemAt, and replaceItemAt to make even more changes to the list box with ActionScript.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours


Recent Comments