| /trunk/air/FeedBurner/FeedBurner.as r95 | /trunk/air/FeedBurner/FeedBurner.as r96 | ||
| 1 | package { | 1 | package { |
|---|---|---|---|
| 2 | /** | 2 | /** |
| 3 | * Class Document for FeedBurner Adobe AIR version | 3 | * Class Document for FeedBurner Adobe AIR version |
| 4 | * Original idea by Napolux.com (http://www.napolux.com/2008/flex-3-adobe-air-feedburner.html) | 4 | * Original idea by Napolux.com (http://www.napolux.com/2008/flex-3-adobe-air-feedburner.html) |
| 5 | * | 5 | * |
| 6 | * @author Giovambattista Fazioli | 6 | * @author Giovambattista Fazioli |
| 7 | * @email g.fazioli@undolog.com | 7 | * @email g.fazioli@undolog.com |
| 8 | * @web http://www.undolog.com | 8 | * @web http://www.undolog.com |
| 9 | * | 9 | * |
| 10 | * CHANGE LOG | 10 | * CHANGE LOG |
| 11 | * | 11 | * |
| 12 | * ver 0.1 | 12 | * ver 0.1 |
| 13 | * - First Adobe AIR release | 13 | * - First Adobe AIR release |
| 14 | * | 14 | * |
| 15 | */ | 15 | */ |
| 16 | import flash.display.*; | 16 | import flash.display.*; |
| 17 | import flash.text.*; | 17 | import flash.text.*; |
| 18 | import flash.events.*; | 18 | import flash.events.*; |
| 19 | import flash.net.URLLoader; | 19 | import flash.net.URLLoader; |
| 20 | import flash.net.URLRequestMethod; | 20 | import flash.net.URLRequestMethod; |
| 21 | import flash.net.URLLoaderDataFormat; | 21 | import flash.net.URLLoaderDataFormat; |
| 22 | import flash.net.URLRequest; | 22 | import flash.net.URLRequest; |
| 23 | import flash.net.URLVariables; | 23 | import flash.net.URLVariables; |
| 24 | 24 | ||
| 25 | public class FeedBurner extends MovieClip { | 25 | public class FeedBurner extends MovieClip { |
| 26 | 26 | ||
| 27 | private const FEEDBURNER_API :String = 'http://api.feedburner.com/awareness/1.0/GetFeedData'; | 27 | private const FEEDBURNER_API :String = 'http://api.feedburner.com/awareness/1.0/GetFeedData'; |
| 28 | 28 | ||
| 29 | public function FeedBurner():void { | 29 | public function FeedBurner():void { |
| 30 | trace("construtor::FeedBurner"); | 30 | trace("construtor::FeedBurner"); |
| 31 | addEventListener( Event.ADDED_TO_STAGE, init ); | 31 | addEventListener( Event.ADDED_TO_STAGE, init ); |
| 32 | } | 32 | } |
| 33 | // | 33 | // |
| 34 | 34 | ||
| 35 | private function init( e:Event = null ):void { | 35 | private function init( e:Event = null ):void { |
| 36 | result_txt.text = ''; | 36 | result_txt.text = ''; |
| 37 | feed_url.text = 'http://www.undolog.com/feed'; | 37 | feed_url.text = 'http://www.undolog.com/feed'; |
| 38 | // | 38 | // |
| 39 | check_btn.addEventListener( MouseEvent.CLICK, checkFeedBurnerReaders ); | 39 | check_btn.addEventListener( MouseEvent.CLICK, checkFeedBurnerReaders ); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | // | 42 | // |
| 43 | private function checkFeedBurnerReaders(e:MouseEvent = null ):void { | 43 | private function checkFeedBurnerReaders(e:MouseEvent = null ):void { |
| 44 | trace( "FeedBurner::checkFeedBurnerReaders()" ); | 44 | trace( "FeedBurner::checkFeedBurnerReaders()" ); |
| 45 | // | 45 | // |
| 46 | var loader :URLLoader = new URLLoader(); | 46 | var loader :URLLoader = new URLLoader(); |
| 47 | var urlreq :URLRequest = new URLRequest(); | 47 | var urlreq :URLRequest = new URLRequest(); |
| 48 | var param :URLVariables = new URLVariables(); | 48 | var param :URLVariables = new URLVariables(); |
| 49 | // | 49 | // |
| 50 | param.uri = feed_url.text; | 50 | param.uri = feed_url.text; |
| 51 | urlreq.url = FEEDBURNER_API; | 51 | urlreq.url = FEEDBURNER_API; |
| 52 | urlreq.method = URLRequestMethod.GET; | 52 | urlreq.method = URLRequestMethod.GET; |
| 53 | urlreq.data = param; | 53 | urlreq.data = param; |
| 54 | // | 54 | // |
| 55 | loader.dataFormat = URLLoaderDataFormat.TEXT; | 55 | loader.dataFormat = URLLoaderDataFormat.TEXT; |
| 56 | loader.addEventListener(Event.COMPLETE, completeHandler); | 56 | loader.addEventListener(Event.COMPLETE, completeHandler); |
| 57 | try { | 57 | try { |
| 58 | loader.load(urlreq); | 58 | loader.load(urlreq); |
| 59 | } catch (error:Error) { | 59 | } catch (error:Error) { |
| 60 | trace("Errore nel caricamento dell' URL"); | 60 | trace("Errore nel caricamento dell' URL"); |
| 61 | } | 61 | } |
| 62 | function completeHandler(event:Event):void { | 62 | function completeHandler(event:Event):void { |
| 63 | //<rsp stat="ok"> | 63 | //<rsp stat="ok"> |
| 64 | // <feed id="651641" uri="undolog"> | 64 | // <feed id="651641" uri="undolog"> |
| 65 | // <entry date="2008-11-17" circulation="389" hits="1348" downloads="0" reach="43"/> | 65 | // <entry date="2008-11-17" circulation="389" hits="1348" downloads="0" reach="43"/> |
| 66 | // </feed> | 66 | // </feed> |
| 67 | //</rsp> | 67 | //</rsp> |
| 68 | Alert.show( "res", "alert"); | ||
| 69 | var x_xml :XML = XML(event.target.data); | 68 | var x_xml :XML = XML(event.target.data); |
| 70 | if( x_xml.@stat == 'ok' ) result_txt.text = x_xml.feed.entry.@circulation.toString(); | 69 | if( x_xml.@stat == 'ok' ) result_txt.text = x_xml.feed.entry.@circulation.toString(); |
| 71 | else result_txt.text = '0'; | 70 | else result_txt.text = '0'; |
| 72 | } | 71 | } |
| 73 | } | 72 | } |
| 74 | } | 73 | } |
| 75 | } | 74 | } |