03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example<br />

The following example creates a new Sound object, <strong>and</strong> loads a sound. Loading the sound is<br />

h<strong>and</strong>led by the onLoad h<strong>and</strong>ler, which allows you to start the song after it is successfully<br />

loaded. Create a new FLA file, <strong>and</strong> add the following ActionScript to your FLA or AS file. For<br />

this example to work, you must have an MP3 called song1.mp3 in the same directory as your<br />

FLA or AS file.<br />

this.createTextField("status_txt", this.getNextHighestDepth(), 0,0,100,22);<br />

// create a new Sound object<br />

var my_sound:Sound = new Sound();<br />

// If the sound loads, play it; if not, trace failure loading.<br />

my_sound.onLoad = function(success:Boolean) {<br />

if (success) {<br />

my_sound.start();<br />

status_txt.text = "Sound loaded";<br />

} else {<br />

status_txt.text = "Sound failed";<br />

}<br />

};<br />

// Load the sound.<br />

my_sound.loadSound("song1.mp3", true);<br />

See also<br />

loadSound (Sound.loadSound method)<br />

onSoundComplete (Sound.onSoundComplete<br />

h<strong>and</strong>ler)<br />

onSoundComplete = function() {}<br />

Invoked automatically when a sound finishes playing. You can use this h<strong>and</strong>ler to trigger<br />

events in a SWF file when a sound finishes playing.<br />

You must create a function that executes when this h<strong>and</strong>ler is invoked. You can use either an<br />

anonymous function or a named function.<br />

Example<br />

Usage 1: The following example uses an anonymous function:<br />

var my_sound:Sound = new Sound();<br />

my_sound.attachSound("mySoundID");<br />

my_sound.onSoundComplete = function() {<br />

trace("mySoundID completed");<br />

};<br />

my_sound.start();<br />

578 ActionScript classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!