I tried a different approach. I had performance problems with building a
new XML object tree with objects subclassed from XMLNode (I didn't want
to re-parse every node). I ended up writing a 'Wrapper' class (apologies
if I have the pattern mis-named) that uses __resolve() to route calls
from one class to another, simluating inheritance. The constructor takes
a reference to the object to be wrapped. I made my variant of XMLNode a
subclass of that class. When I run through an XML document, I create my
flavor of nodes, each of which keeps a reference to its original
XMLNode. It works pretty well for me. In my case, I keep character
offsets of the beginnings of all the text nodes, so I can find my way
around XHTML docs and insert 'virtual tokens'.' I use these for editing
the markup, or for finding character screen locations using
getTextExtent() -- at least for the time being--:).
It is probably a risky thing to work with __resolve(), I know, but this
way, I only use it in one place, so if the implementation changes, I
only need to make one edit.
Hope this helps.
Bill G
Message: 8
Date: Thu, 5 Jan 2006 01:43:50 -0500
From: Frederic v. Bochmann [EMAIL PROTECTED]
Subject: RE: [Flashcoders] Extending the XML class
To: 'Flashcoders mailing list' flashcoders@chattyfig.figleaf.com
Message-ID: [EMAIL PROTECTED]
Content-Type: text/plain; charset=us-ascii
Hey Rifled,
Maybe I'm biting off more than I can chew for my first AS2 project...
I think your chewing a bit, but that alright, that's what brains are made
for :)
Why not simply parse your loaded XML structure and recreate the organization
with your EXML objects?
For an answer to your question: can you override the XMLNode creation for
your own implementation, I think the answer is Yes and No! at least for
Flash Player 8.0 and lower. You can always use the xmlObject.onData method
to override the actual moment when the XML String gets parsed, and
eventually implement your own parser code that checks the player version to
call different ASNative calls according to the version (very hard to
maintain (example: XMLNitro)). Or you could parse the XML string by hand,
but that's too hard on your CPU if you're using player versions under 8.5.
Basically the answer is no. Don't try! :)
The reason why, is this: The Flash Player has its own build-in (Native) SAX
XML Parser that returns an array of objects representing the nodes parsed.
The XML API we commonly use in ActionScript, uses this build-in SAX Parser
to get an Array of Objects ordered in the order they are parsed (like a SAX
parser works). The XML implementation we normally use takes this array and
creates children of type XMLNodes on himself. It's quite easy to implement,
but the problem is that the address of the ASNative call might change from
version to version of the Flash Player. It's not suggested to use this
method.
PS: the ASNative call would look a bit like this: (This is old code)
this.status = ASnative(300, 0)(str, tags, false);
But BEWARE this might not work in all version of the player. Don't try ;)
One thing you might want to try is to associate some custom prototyped
functions on the XML object to method prototypes in your own class. For
example: XML.prototype.yourCustomMethod = EXML.prototype.yourCustomMethod;
and this way, you might be able to have some functionalities with your
XMLNode objects that your handling. Be aware of the context of the execution
of your methods by the way! (This is like backtracking AS2 to AS1, not
suggested either)
Anyways, I think you should try simply iterating threw the received (parsed)
xml to recreate your own structure, or something like that.
One thing that might be interesting is if (Adobe) would provide us with a
SAXParser which supports our own custom ContentHandler's that could permit
us to handle the data as its being parsed by the internal engine. I can
see why they haven't implemented this in previous versions, but with
upcoming versions, this sure would be nice to have, if possible. (but that's
just my two little tiny cents)
Good luck :)
Fredz./
--
William Garr
Sr. Educational Multimedia Developer
Center for New Designs in Learning and Scholarship
Georgetown University
Washington, DC 20057
phone: 202-687-9119
email: [EMAIL PROTECTED]
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders