Mailing List
Home
Forum Home
Flash Pro
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
AS2 - need help extending XML

AS2 - need help extending XML

2004-03-08       - By Steven L. Sacks

 Back
Reply:     1     2     3  

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.