Example
The following example attaches the sound
has the linkage identifier
var my_sound:Sound = new Sound();
my_sound.attachSound("logoff_id");
my_sound.start();
duration (Sound.duration property)
public duration : Number [read-only]
The duration of a sound, in milliseconds.
Availability: ActionScript 1.0; Flash Player 6
Example
The following example loads a sound and displays the duration of the sound file in the
Output panel. Add the following ActionScript to your FLA or AS file.
var my_sound:Sound = new Sound();
my_sound.onLoad = function(success:Boolean) {
var totalSeconds:Number = this.duration/1000;
trace(this.duration+" ms ("+Math.round(totalSeconds)+" seconds)");
var minutes:Number = Math.floor(totalSeconds/60);
var seconds = Math.floor(totalSeconds)%60;
if (seconds<10) {
seconds = "0"+seconds;
}
trace(minutes+":"+seconds);
};
my_sound.loadSound("song1.mp3", true);
The following example loads several songs into a SWF file. A progress bar, created using the
Drawing API, displays the loading progress. When the music starts and completes loading,
information displays in the Output panel. Add the following ActionScript to your FLA or AS
file.
var pb_height:Number = 10;
var pb_width:Number = 100;
var pb:MovieClip = this.createEmptyMovieClip("progressBar_mc",
this.getNextHighestDepth());
pb.createEmptyMovieClip("bar_mc", pb.getNextHighestDepth());
pb.createEmptyMovieClip("vBar_mc", pb.getNextHighestDepth());
pb.createEmptyMovieClip("stroke_mc", pb.getNextHighestDepth());
pb.createTextField("pos_txt", pb.getNextHighestDepth(), 0, pb_height,
pb_width, 22);
pb._x = 100;
logoff_id
.
logoff_id
to
. A sound in the library
my_sound
Sound
1097
Need help?
Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?