ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Example: Podcast Radio | 271

podcasts is that in podcasts, the story is not text but a URL to a media file. In an


audio podcast, the linked media file is usually in MP3 format. Example 7-25 shows a


fictitious podcast XML feed in RSS syndication format (with many elements deleted


for clarity).


To play an audio podcast, the podcast XML file has to be loaded and parsed to


access theurlattribute of theenclosureelement that holds the URL to the audio file.


Thereafter, the audio file has to be loaded from the Web and played.


Creating a Package with Utility Classes


First, we need to create two utility classes to create the button and text fields on the


stage. The first is the sameTextButtonclass shown in Example 7-14 that creates but-


tons on the stage. We also develop a class calledTextDisplayFieldthat subclasses


TextFieldto format and display the title of the currently playing podcast item. We


will add both classes into a package calledutils.


TheTextDisplayFieldclass is shown in Example 7-26. The class is straightforward,


and its main purpose is to set the initial text in the field, set the font size, and show


the text field border.


Example 7-25. Podcast XML feed


<?xml version="1.0" encoding="utf-8"?>




10AM ET News Summary

News Summary for Saturday, Nov 18 2006 at 10:00 AM EST
Sat, 18 Nov 2006 10:16:06 EST




Example 7-26. TextDisplayField.as


package utils {


import flash.text.TextFormat;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;


public class TextDisplayField extends TextField {


public function TextDisplayField(labelText:String = "",
fontSize:int = 14,
showborder:Boolean = true) {
autoSize = TextFieldAutoSize.LEFT;
text = labelText;
border = showborder;

Free download pdf