User Guide

Global Properties 125
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
_soundbuftime property is set to buffer the MP3 for 10 seconds. A new Sound object
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, this references the
movie clip instance that contains the script. When a method is called,
this contains a
reference to the object that contains the called method.
Inside an
on() event handler attached to a button, this refers to the Timeline that contains
the button. Inside an
onClipEvent() event handler attached to a movie clip, this refers to
the Timeline of the movie clip itself.
Because
this is evaluated in the context of the script that contains it, you can't use this in a
script to refer to a variable defined in a class file.
Availability: ActionScript 1.0; Flash Player 5