From a8d348a8df64fa4b779af4444ab8739afb879be8 Mon Sep 17 00:00:00 2001 From: Cristiano Caldas Date: Mon, 7 Nov 2011 00:00:11 -0200 Subject: [PATCH] YAMLItem added --- .../stimuli/loading/loadingtypes/YAMLItem.as | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/br/com/stimuli/loading/loadingtypes/YAMLItem.as diff --git a/src/br/com/stimuli/loading/loadingtypes/YAMLItem.as b/src/br/com/stimuli/loading/loadingtypes/YAMLItem.as new file mode 100644 index 0000000..748409a --- /dev/null +++ b/src/br/com/stimuli/loading/loadingtypes/YAMLItem.as @@ -0,0 +1,110 @@ +/** + * @author Cristiano Caldas + */ + +package br.com.stimuli.loading.loadingtypes +{ + import br.com.stimuli.loading.loadingtypes.LoadingItem; + import br.com.stimuli.loading.BulkLoader; + + import flash.display.*; + import flash.net.*; + import flash.events.*; + import flash.utils.*; + import dupin.parsers.yaml.YAML; + + public class YAMLItem extends LoadingItem + { + public var loader:URLLoader; + + public function YAMLItem(url:URLRequest, type:String, uid:String) + { + super(url, type, uid); + } + + override public function _parseOptions(props:Object):Array{ + return super._parseOptions(props); + } + + override public function load() : void{ + super.load(); + loader = new URLLoader(); + loader.addEventListener(ProgressEvent.PROGRESS, onProgressHandler, false, 0, true); + loader.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, true); + loader.addEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false, 0, true); + loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false, 0, true); + loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false, 0, true); + loader.addEventListener(Event.OPEN, onStartedHandler, false, 0, true); + try + { + loader.load(url); + } + catch(e:SecurityError) + { + onSecurityErrorHandler(_createErrorEvent(e)); + } + }; + + override public function onErrorHandler(evt:ErrorEvent) : void{ + super.onErrorHandler(evt); + } + + override public function onStartedHandler(evt:Event) : void{ + super.onStartedHandler(evt); + }; + + override public function onCompleteHandler(evt:Event):void + { + try + { + _content = YAML.decode(loader.data); + } + catch(e:Error) + { + _content = null; + status = STATUS_ERROR; + dispatchEvent(_createErrorEvent(e)); + } + + super.onCompleteHandler(evt); + } + + override public function stop():void + { + try + { + if(loader) + loader.close(); + } + catch(e:Error) + { + + } + super.stop(); + }; + + override public function cleanListeners() : void { + if(loader){ + loader.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler, false); + loader.removeEventListener(Event.COMPLETE, onCompleteHandler, false); + loader.removeEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false); + loader.removeEventListener(BulkLoader.OPEN, onStartedHandler, false); + loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false); + loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false); + } + } + + override public function isText(): Boolean{ + return true; + } + + override public function destroy() : void{ + stop(); + cleanListeners(); + _content = null; + loader = null; + } + + } + +} \ No newline at end of file