RE: [Flashcoders] Extending the XML class

2006-01-05 Thread William Garr
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


Re: [Flashcoders] Extending the XML class

2006-01-04 Thread Jan Schluenzen
Hi,

I ran into the exact same problem about a year ago... The XML class doesn't
really make it easy to extend... The way I solved it is by overriding all
necessary methods of the XML class with methods in my extended version, so
EXML in your case.
E.g.

function someOverridenMethod():EXML {
  // do some other stuff
   
   return new EXML( this.cloneNode(true).toString() );
}

That way all instances of XMLNode are converted to EXML before being
returned.
This could of course also be used for newly added methods in your extended
class...

Hope that helps.
Jan



On 1/4/06, Rifled Cloaca [EMAIL PROTECTED] wrote:

 Hi!

 I'm new to AS2, and I'm trying to convert some old AS1 code to AS2.  This
 code uses XML.prototype to add functionality to the XML class (which is
 based on the XMLNode class, but you knew that already).  I'm creating a
 new
 class like this:

 dynamic class core.EXML extends XML {
 }

 This new XML class has new properties in each of its nodes, so I add:


 dynamic class core.EXML extends XML {

 public var _MC:MovieClip;
 public var _parentMC:MovieClip;

 }

 But, unfortunately, since the EXML class inherits from the XML class, the
 nodes are of XMLNode class, not EXML class, so the nodes do not inherit
 the
 properties and methods I create in the new EXML class.

 So, my question is, how do I create a class that creates instances of
 itself, or say, an EXMLNode class that inherits from XMLNode?

 Any help is greatly appreciated.  Thanks!

 -rc
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Extending the XML class

2006-01-04 Thread Rifled Cloaca
Jan,

Thanks, but I'm not having any luck.  I'm trying to force my EXML class to
create all of it's nodes of class EXMLNode instead of XMLNode.  That way, my
custom methods are accessible at any node in the tree.  Unfortunately, it
seems that all of the nodes of the tree are type XMLnode, not EXMLNode.

What I can't figure out is what methods are used in the intrinsic XML class
to create nodes in the first place, and how to rewire them to create nodes
of class EXMLNode instead of XMLNode.

Maybe I'm biting off more than I can chew for my first AS2 project... I
don't know.

Any ideas are much appreciated.

Thanks!
-rc


On 1/4/06, Jan Schluenzen [EMAIL PROTECTED] wrote:

 Hi,

 I ran into the exact same problem about a year ago... The XML class
 doesn't
 really make it easy to extend... The way I solved it is by overriding all
 necessary methods of the XML class with methods in my extended version, so
 EXML in your case.
 E.g.

 function someOverridenMethod():EXML {
 // do some other stuff
   
   return new EXML( this.cloneNode(true).toString() );
 }

 That way all instances of XMLNode are converted to EXML before being
 returned.
 This could of course also be used for newly added methods in your extended
 class...

 Hope that helps.
 Jan



 On 1/4/06, Rifled Cloaca [EMAIL PROTECTED] wrote:
 
  Hi!
 
  I'm new to AS2, and I'm trying to convert some old AS1 code to
 AS2.  This
  code uses XML.prototype to add functionality to the XML class (which is
  based on the XMLNode class, but you knew that already).  I'm creating a
  new
  class like this:
 
  dynamic class core.EXML extends XML {
  }
 
  This new XML class has new properties in each of its nodes, so I add:
 
 
  dynamic class core.EXML extends XML {
 
  public var _MC:MovieClip;
  public var _parentMC:MovieClip;
 
  }
 
  But, unfortunately, since the EXML class inherits from the XML class,
 the
  nodes are of XMLNode class, not EXML class, so the nodes do not inherit
  the
  properties and methods I create in the new EXML class.
 
  So, my question is, how do I create a class that creates instances of
  itself, or say, an EXMLNode class that inherits from XMLNode?
 
  Any help is greatly appreciated.  Thanks!
 
  -rc
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders