ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Extended Example: Displaying the O’Reilly New Books List | 201

Example 5-17. Main.as (document class)


1 package
2 {
3 import flash.display.MovieClip;
4 import flash.text.*;
5 import flash.events.*;
6 import flash.net.*;
7
8 /**
9 * Main Class
10 * @ purpose: Document class for movie
11 */
12 public class Main extends MovieClip
13 {
14 var xml:XML;
15 var xmlLoader:URLLoader;
16 var newBookListField:ListDisplayField;
17
18 public function Main( )
19 {
20 // create ListDisplayField (Adapter)
21 newBookListField = new ListDisplayField( );
22
23 // develop field formatting
24 var format:TextFormat = new TextFormat( );
25 format.size = 14;
26 format.font = "Arial";
27
28 // set field location and format
29 newBookListField.x = 20;
30 newBookListField.y = 20;
31 newBookListField.width = 500;
32 newBookListField.height = 300;
33 newBookListField.border = true;
34 newBookListField.defaultTextFormat = format;
35
36 // create list from O'Reilly New Books Feed (Atom)
37 var newBooksURL = "http://www.oreillynet.com/pub/feed/29";
38 xml = new XML( );
39 var xmlURL:URLRequest = new URLRequest(newBooksURL);
40 xmlLoader = new URLLoader(xmlURL);
41 xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
42
43 addChild(newBookListField); // add field to display list
44 }
45
46 function xmlLoaded(evtObj:Event)
47 {
48 xml = XML(xmlLoader.data);
49 // set the default XML namespace
50 if (xml.namespace("") != undefined)
51 {
52 default xml namespace = xml.namespace("");
Free download pdf