  | |  | AS2 - need help extending XML | AS2 - need help extending XML 2004-03-08 - By Steven L. Sacks
Back Hi,
I searched the web and the chattyfig archives to no avail. I'm trying to learn AS2 by converting my AS1 classes to AS2 classes. I'm having particular difficulty with extending the native XML class and I'm hoping somebody here can help.
To avoid memory waste, in AS1, I set every XML object instantiated to use the same onLoad method as such:
XML.prototype.setOnLoadHandler = function(handler, args){ this.onLoadHandler = handler; this.onLoadArguments = args; }; XML.prototype.onLoad = function(success){ this.onLoadHandler(success, this.onLoadArguments); };
This was then used in the following class:
_global.XMLLoaderClass = function() { this.init.apply(this.arguments); }; XMLLoaderClass.prototype.init = function(owner) { this.owner = owner; }; XMLLoaderClass.prototype.loadXML = function(xmlPath, callback) { delete this.xmlObject; this.xmlObject = new XML(); this.xmlObject.ignoreWhite = true; this.xmlObject.owner = this.owner; this.xmlObject.callback = callback; this.xmlObject.setOnLoadHandler(this.onLoadHandler); // noCache? this.xmlObject.load(xmlPath); }; // XMLLoaderClass.prototype.onLoadHandler = function(success) { if (success) { this.owner[this.callback](this); } };
Well, the conversion to AS2 has been frustrating for me. Here's my attempt:
dynamic class XML_EXT extends XML { private function XML_EXT() { // constructor } public static function setOnLoadHandler(handler:Function, args:Array):Void { trace("setOnLoadHandler called"); var onLoadHandler:Function = handler; var onLoadArguments:Array = args; } public static function onLoad(success:Boolean):Void { trace("onLoad = " + success); onLoadHandler(success, onLoadArguments); } }
And:
dynamic class XMLLoaderClass { private static var _owner:Object; private static var _xmlObject:XML; // public function XMLLoaderClass(owner:Object) { init.apply(this, arguments); } public function init(owner:Object):Void { _owner = owner; } public function loadXML(xmlPath:String, callback:String, noCache:Boolean):Void { _xmlObject = new XML(); _xmlObject.ignoreWhite = true; _xmlObject.owner = _owner; _xmlObject.callback = callback; _xmlObject.setOnLoadHandler(_onLoadHandler); } private static function _onLoadHandler(success) { if (success) { owner[callback](this); } } }
Unfortunately, the second script spits out a bunch of errors, which I understand but don't know what to do about. The XML object does not have owner, callback, or setOnLoadHandler, so it won't let me set them.
I believe I need to make the XML_EXT include the XML native class and instead of using new XML(), I would use new XML_EXT(), but I'm not sure.
Any help would be appreciated.
Thanks, Steven
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Supported by Fig Leaf Software =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Be sure to check the archives and the wiki: http://chattyfig.figleaf.com/ =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:106365 =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe send a blank e-mail to: Normal Mode: flashcoders-unsubscribe@(protected) Digest Mode: flashcoders-digest-unsubscrive@(protected)
Earn $52 per hosting referral at Lunarpages.
|
|
 |