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 sound<br />

File Description<br />

com/example/program<br />

mingas3/podcastplayer<br />

/RSSItem.as<br />

com/example/program<br />

mingas3/podcastplayer<br />

/SoundFacade.as<br />

com/example/program<br />

mingas3/podcastplayer<br />

/URLService.as<br />

An ActionScript class that holds data about an RSS item.<br />

The main ActionScript class for the application. It <strong>en</strong>capsulates the methods and ev<strong>en</strong>ts of the Sound class and the<br />

SoundChannel class and adds support for pausing and resuming playback.<br />

An ActionScript class that retrieves data from a remote URL.<br />

playerconfig.xml An XML file containing a list of RSS feeds that repres<strong>en</strong>t podcast channels.<br />

comp/example/progra<br />

mmingas3/utils/DateUt<br />

il.as<br />

Class that is used for easy date formatting (Flash only).<br />

Reading RSS data for a podcast channel<br />

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

The Podcast Player application starts by reading information about a number of podcast channels and their episodes:<br />

1. First, the application reads an XML configuration file that contains a list of podcast channels and displays the list of<br />

channels to the user.<br />

2. Wh<strong>en</strong> the user selects one of the podcast channels, it reads the RSS feed for the channel and displays a list of the<br />

channel episodes.<br />

This example uses the URLLoader utility class to retrieve text-based data from a remote location or a local file. The<br />

Podcast Player first creates a URLLoader object to get a list of RSS feeds in XML format from the playerconfig.xml file.<br />

Next, wh<strong>en</strong> the user selects a specific feed from the list, a new URLLoader object is created to read the RSS data from<br />

that feed’s URL.<br />

Simplifying sound loading and playback using the SoundFacade class<br />

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

The ActionScript 3.0 sound architecture is powerful but complex. Applications that only need basic sound loading and<br />

playback features can use a class that hides some of the complexity by providing a simpler set of method calls and<br />

ev<strong>en</strong>ts. In the world of software design patterns, such a class is called a facade.<br />

The SoundFacade class pres<strong>en</strong>ts a single interface for performing the following tasks:<br />

Loading sound files using a Sound object, a SoundLoaderContext object, and the SoundMixer class<br />

Playing sound files using the Sound object and the SoundChannel object<br />

Dispatching playback progress ev<strong>en</strong>ts<br />

Pausing and resuming playback of the sound using the Sound object and the SoundChannel object<br />

The SoundFacade class tries to offer most of the functionality of the ActionScript sound classes with less complexity.<br />

The following code shows the class declaration, the class properties, and the SoundFacade() constructor method:<br />

Last updated 6/6/2012<br />

468

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

Saved successfully!

Ooh no, something went wrong!