13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with video<br />

<br />

<br />

<br />

<br />

<br />

Finally, the xmlCompleteHandler() method calls the main() method which sets up the various compon<strong>en</strong>t instances<br />

on the display list, as well as the NetConnection and NetStream objects which are used to load the external FLV files.<br />

Creating the user interface<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

To build the user interface you need to drag five Button instances onto the display list and give them the following<br />

instance names: playButton, pauseButton, stopButton, backButton, and forwardButton.<br />

For each of these Button instances, you’ll need to assign a handler for the click ev<strong>en</strong>t, as se<strong>en</strong> in the following snippet:<br />

playButton.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.CLICK, buttonClickHandler);<br />

pauseButton.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.CLICK, buttonClickHandler);<br />

stopButton.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.CLICK, buttonClickHandler);<br />

backButton.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.CLICK, buttonClickHandler);<br />

forwardButton.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.CLICK, buttonClickHandler);<br />

The buttonClickHandler() method uses a switch statem<strong>en</strong>t to determine which button instance was clicked, as se<strong>en</strong><br />

in the following code:<br />

private function buttonClickHandler(ev<strong>en</strong>t:MouseEv<strong>en</strong>t):void<br />

{<br />

switch (ev<strong>en</strong>t.curr<strong>en</strong>tTarget)<br />

{<br />

case playButton:<br />

ns.resume();<br />

break;<br />

case pauseButton:<br />

ns.togglePause();<br />

break;<br />

case stopButton:<br />

ns.pause();<br />

ns.seek(0);<br />

break;<br />

case backButton:<br />

playPreviousVideo();<br />

break;<br />

case forwardButton:<br />

playNextVideo();<br />

break;<br />

}<br />

}<br />

Next, add a Slider instance to the display list and give it an instance name of volumeSlider. The following code sets<br />

the slider instance’s liveDragging property to true and defines an ev<strong>en</strong>t list<strong>en</strong>er for the slider instance’s change<br />

ev<strong>en</strong>t:<br />

Last updated 6/6/2012<br />

507

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

Saved successfully!

Ooh no, something went wrong!