http://www.gaiaflashframework.com/index.php/topic,1847.msg7817.html#msg7817
Just so everyone is familiar with the context here, the above is the
thread on the forum about this.
The question is about how to use E4X to parse XHTML. I provide a code
example of how easy it is to do this, but Jonathan's question is more
of a general one about how to use E4X to parse nodes.
Flash doesn't support <div> in its htmlText, so that's why you use E4X
to grab the node content like
var value:XML = XMLList(copy.innerHTML)[0];
var body:XML = value.div.(@id == "body")[0];
I believe the challenge for Jonathan is what the above lines of code
mean and how they work.
value is the XHTML.
value.div returns an XMLList of all div nodes on the first level
within the XHTML.
value.div.(@id == "body") means give me an XMLList of the div nodes
that have an attribute id="body".
valid.div.(@id == "body")[0] means give me the first XML node in that
XMLList.
This is how E4X works. A lesson on E4X is out of scope of my forum.
However, there are lots of resources out there for E4X in AS3. I
highly recommend Colin Moock's Essential Actionscript 3.0 book, which
is how I learned it. That and the internet.
And Jason, you do not need to complicate things with RegEx. E4X does
enough. XHTML is technically XML and can be parsed the same using E4X.
Also, while Flash doesn't SEEM to support newer HTML tags like
<strong> and <em> for <b> and <i>, it actually DOES if you write css
to do it.
strong {
font-family: FFScala-Bold;
display: inline;
}
em {
font-family: FFScala-Italic;
display: inline;
}
In this case, I am using a bold and italic font to show them, and by
defining the node types in css (and setting them to display: inline),
it works like a champ!
Here's a detailed code sample:
http://www.gaiaflashframework.com/wiki/index.php?title=Runtime_Font_Loading#StyleSheet_Example
Now, I can keep my valid XHTML and use it directly in Flash. It's
really straightforward. The challenge is learning how to parse the
nodes using E4X, which, once you get your head around it (and it took
me a lot of experimenting to learn how awesome and powerful E4X is and
how to leverage it), you can do stuff like this easily.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders