root/Theme-1/nobu/Base.as

Revision 13, 3.6 kB (checked in by nobu, 9 months ago)

RSSのURLを変更。

Line 
1 package
2 {
3     import flash.events.Event;
4     import flash.events.IOErrorEvent;
5     import flash.events.SecurityErrorEvent;
6     import flash.net.URLRequest;
7     import flash.net.URLRequestMethod;
8     import flash.net.URLLoader;
9     import flash.net.URLVariables;
10     import lib.display.MovieClipExt;
11
12     public class Base extends MovieClipExt
13     {
14         private var index:int;
15         private var items:Array;
16
17         public function Base()
18         {
19         }
20
21         override protected function wakeUp(evt:Event):void
22         {
23             loadRSS();
24             super.wakeUp.call(this, evt);
25         }
26
27         private function loadRSS():void
28         {
29             var url:String = loaderInfo.parameters['feed-url'] || '/feed/';
30             var req:URLRequest = new URLRequest(url);
31             var loader:URLLoader = new URLLoader();
32             loader.addEventListener(Event.OPEN, onOpen, false, 0, true);
33             loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
34             loader.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);
35             loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError, false, 0, true);
36             loader.load(req);
37         }
38
39         private function showRSS(evt:Event=null):void
40         {
41             if (items.length <= 0) return;
42             if (index >= items.length) index = 0;
43             var p:Panel = addChild(new Panel(items[index++])) as Panel;
44             p.addEventListener(Event.REMOVED_FROM_STAGE, showRSS, false, 0, true);
45         }
46
47         private function onOpen(evt:Event):void
48         {
49             showLoading();
50         }
51
52         private function onComplete(evt:Event):void
53         {
54             var item:XML;
55             var category:XML;
56             var rss:XML = new XML(evt.target.data);
57             index = 0;
58             items = [];
59             for each (category in rss.channel.item.category)
60             {
61                 if (category.text() == 'Theme')
62                 {
63                     item = category.parent();
64                     items.push({
65                         title: item.title.text(),
66                         link: item.link.text(),
67                         pubDate: new Date(Date.parse(item.pubDate.text())),
68                         description: item.description.text()
69                     });
70                 }
71             }
72             removeChild(getChildByName('loading'));
73             if (items.length > 0)
74             {
75                 showRSS();
76             }
77         }
78
79         private function onError(evt:Event):void
80         {
81             hideLoading();
82             showFailure();
83         }
84
85         private function showLoading():void
86         {
87             var l:Loading = getChildByName('loading') as Loading;
88             if (!(l is Loading))
89             {
90                 l = addChild(new Loading()) as Loading;
91                 l.name = 'loading';
92             }
93             l.visible = true;
94         }
95
96         private function hideLoading():void
97         {
98             var l:Loading = getChildByName('loading') as Loading;
99             if (l is Loading)
100             {
101                 l.visible = false;
102             }
103         }
104
105         private function showFailure():void
106         {
107             var f:Failure = getChildByName('failure') as Failure;
108             if (!(f is Failure))
109             {
110                 f = addChild(new Failure()) as Failure;
111                 f.name = 'failure';
112             }
113             f.visible = true;
114         }
115
116         private function hideFailure():void
117         {
118             var f:Failure = getChildByName('failure') as Failure;
119             if (f is Failure)
120             {
121                 f.visible = false;
122             }
123         }
124     }
125 }
Note: See TracBrowser for help on using the browser.