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 progress bar using the Drawing API <strong>and</strong> the bytesLoaded<br />

<strong>and</strong> bytesTotal properties. The bar displays the progress of the operation as video1.flv is<br />

loaded into the video object instance called my_video. A text field called loaded_txt is<br />

dynamically created to display information about the loading progress as well.<br />

var connection_nc:NetConnection = new NetConnection();<br />

connection_nc.connect(null);<br />

var stream_ns:NetStream = new NetStream(connection_nc);<br />

my_video.attachVideo(stream_ns);<br />

stream_ns.play("video1.flv");<br />

this.createTextField("loaded_txt", this.getNextHighestDepth(), 10, 10, 160,<br />

22);<br />

this.createEmptyMovieClip("progressBar_mc", this.getNextHighestDepth());<br />

progressBar_mc.createEmptyMovieClip("bar_mc",<br />

progressBar_mc.getNextHighestDepth());<br />

with (progressBar_mc.bar_mc) {<br />

beginFill(0xFF0000);<br />

moveTo(0, 0);<br />

lineTo(100, 0);<br />

lineTo(100, 10);<br />

lineTo(0, 10);<br />

lineTo(0, 0);<br />

endFill();<br />

_xscale = 0;<br />

}<br />

progressBar_mc.createEmptyMovieClip("stroke_mc",<br />

progressBar_mc.getNextHighestDepth());<br />

with (progressBar_mc.stroke_mc) {<br />

lineStyle(0, 0x000000);<br />

moveTo(0, 0);<br />

lineTo(100, 0);<br />

lineTo(100, 10);<br />

lineTo(0, 10);<br />

lineTo(0, 0);<br />

}<br />

var loaded_interval:Number = setInterval(checkBytesLoaded, 500, stream_ns);<br />

function checkBytesLoaded(my_ns:NetStream) {<br />

var pctLoaded:Number = Math.round(my_ns.bytesLoaded/<br />

my_ns.bytesTotal*100);<br />

loaded_txt.text = Math.round(my_ns.bytesLoaded/1000)+" of<br />

"+Math.round(my_ns.bytesTotal/1000)+" KB loaded ("+pctLoaded+"%)";<br />

progressBar_mc.bar_mc._xscale = pctLoaded;<br />

if (pctLoaded>=100) {<br />

clearInterval(loaded_interval);<br />

}<br />

}<br />

502 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!