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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

getBytesLoaded (Sound.getBytesLoaded method)<br />

public getBytesLoaded() : Number<br />

Returns the number of bytes loaded (streamed) for the specified Sound object. You can<br />

compare the value of getBytesLoaded() with the value of getBytesTotal() to determine<br />

what percentage of a sound has loaded.<br />

Returns<br />

Number - An integer indicating the number of bytes loaded.<br />

Example<br />

The following example dynamically creates two text fields that display the bytes that are<br />

loaded <strong>and</strong> the total number of bytes for a sound file that loads into the SWF file. A text field<br />

also displays a message when the file finishes loading. Add the following ActionScript to your<br />

FLA or AS file:<br />

this.createTextField("message_txt", this.getNextHighestDepth(),<br />

10,10,300,22)<br />

this.createTextField("status_txt", this.getNextHighestDepth(), 10, 50, 300,<br />

40);<br />

status_txt.autoSize = true;<br />

status_txt.multiline = true;<br />

status_txt.border = false;<br />

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

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

if (success) {<br />

this.start();<br />

message_txt.text = "Finished loading";<br />

}<br />

};<br />

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

message_txt.text = "Clearing interval";<br />

clearInterval(my_interval);<br />

};<br />

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

var my_interval:Number;<br />

my_interval = setInterval(checkProgress, 100, my_sound);<br />

function checkProgress(the_sound:Sound):Void {<br />

var pct:Number = Math.round(the_sound.getBytesLoaded()/<br />

the_sound.getBytesTotal() 100);<br />

var pos:Number = Math.round(the_sound.position/the_sound.duration 100);<br />

status_txt.text = the_sound.getBytesLoaded()+" of<br />

"+the_sound.getBytesTotal()+" bytes ("+pct+"%)"+newline;<br />

status_txt.text += the_sound.position+" of "+the_sound.duration+"<br />

milliseconds ("+pos+"%)"+newline;<br />

}<br />

568 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!