Example
The following example streams an MP3 file and buffers the sound before it plays for the user.
Two text fields are created at runtime to hold a timer and debugging information. The
property is set to buffer the MP3 for 10 seconds. A new Sound object
_soundbuftime
instance is created for the MP3.
// create text fields to hold debug information.
this.createTextField("counter_txt", this.getNextHighestDepth(), 0, 0, 100,
22);
this.createTextField("debug_txt", this.getNextHighestDepth(), 0, 20, 100,
22);
// set the sound buffer to 10 seconds.
_soundbuftime = 10;
// create the new sound object instance.
var bg_sound:Sound = new Sound();
// load the MP3 sound file and set streaming to true.
bg_sound.loadSound("yourSound.mp3", true);
// function is triggered when the song finishes loading.
bg_sound.onLoad = function() {
debug_txt.text = "sound loaded";
};
debug_txt.text = "sound init";
function updateCounter() {
counter_txt.text++;
}
counter_txt.text = 0;
setInterval(updateCounter, 1000);
this property
this
References an object or movie clip instance. When a script executes,
movie clip instance that contains the script. When a field is called,
to the object that contains the called field.
Inside an
event handler attached to a button,
on()
the button. Inside an
the Timeline of the movie clip itself.
110
ActionScript language elements
event handler attached to a movie clip,
onClipEvent()
this
this
refers to the Timeline that contains
this
references the
contains a reference
refers to
this