| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Holosuit User
|
As E4X is short, I'll try to follow it's spirit. We need this thread, so, why won't we have one?
Semantics: @ - attribute accessor. Example: ActionScript Code:
. (dot) - child accessor. Example: ActionScript Code:
.. (double dot) - descendants accessor. Example: ActionScript Code:
:: (double colon) - namespace accessor. Example: ActionScript Code:
[] - (square brackets) - access dynamic property. Example: ActionScript Code:
() (parentheses) - perform operation on every XMLList item. Example: ActionScript Code:
{} (braces) - generate XML element. Example: ActionScript Code:
* (asterisk) - substitute for XML element. Example: ActionScript Code:
Common Use Cases Q: Why some nodes appear in trace() as empty strings, while I'm sure they are there? A: Unless the node you trace() is a root node the following condition applies: the trace() will use myXML.toString() method to output the child nodes of the XML passed as an argument. If XML passed for the argument has no children, the empty string will appear in the output. NOTICE: the text value of the node is also a child. If you want to trace() the structure of the node and it's children you need to use myXML.toXMLString(). Example ActionScript Code:
A: You need to use explicit casting to convert attribute value to String. The type of the attribute value is XMLList. Example ActionScript Code:
Q: Why parsing with E4X is slow? A: The most common mistakes when parsing: You put the E4X expression inside the for / for-each for-in loop. E4X is a set of loops itself, thus, if you execute it in a loop it will multiply the execution time in geometric progression. You used descendant accessor where you could avoid it. Example ActionScript Code:
Q: How do I convert XML to Array? A: There're only two reason I've found so far to do so: 1. When you need to sort / change order of the nodes based on complex condition. Example ActionScript Code:
ActionScript Code:
Q: How do I parse XML, that has names containing ":" (colons)? A: Colon divides the qualified XML name into 2 parts, first is the namespace prefix, last is the local name. Example ActionScript Code:
Q: How do I strip all namespaces from the XML? A: Regretfully there's no way to do this using either AS XML API or E4X. Here's some string processing that accomplishes the same task. If you have a better suggestion on how to do this - please correct me: Example ActionScript Code:
Q: How do I parse XML, that has names containing symbols that break E4X statements? (Eg. XAML, hyphenated node names etc). Example ActionScript Code:
Q: How do I loop through all the nodes recursively? Example ActionScript Code:
Q: How do I map all nodes using unique ID for every node? Example ActionScript Code:
Q: How do I generate XML dynamically? Example ActionScript Code:
Continued:
__________________
The .NET open source editor for Flash and web developers *This would be my contribution to the project* couchsurfing if you need it Last edited by wvxvw; 02-02-2009 at 07:19 PM.. |
|
|
|
|
|
#2 |
|
Super Moderator
Join Date: Jul 2001
Location: NYC
Posts: 10,065
|
You should turn this into an article as well.
__________________
Color Wars™ | (kul′ər wôrs) n. - Open conflict between factions. www.theColorWars.com cota - www.chadworkman.com | http://shavedplatypus.com occupation: designer | flash developer | server-side developer (php, asp, mssql, mysql) |
|
|
|
|
|
|
|
|
#3 |
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 25,331
|
Totally agreed... Very nice, wvxvw...
![]()
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer http://CyanBlue.FlashVacuum.com http://www.FlashVacuum.com http://tutorials.FlashVacuum.com Do NOT PM, Email or Call me... Your question belongs right in this forum...
|
|
|
|
|
|
#4 |
|
Site Contributor
|
Cool!
I have a question, and not to clutter up your spiffy new thread, but... How useful is inline XML? I mean, I can see the advantage of loading an external XML file: You can always edit the XML and never again touch the flash application. And I know the inline XML is a new feature of AS3, but what could possibly be the advantage of keeping the XML inline and in the flash file(s)? Thanks. I agree you should do an article on this. Also one on regular expressions, which I have noticed you are good at. Last edited by Mazoonist; 02-02-2009 at 04:31 AM.. |
|
|
|
|
|
#5 |
|
Paintball Freak
|
Honestly, I never use inline XML in my projects because I don't see any point in doing so... The only time I write inline XML is when I want to help someone out with something and I'm too lazy to write an XML file and load it dynamically... Other than that, I really see no point in ever using inline XML.
Check out this link: http://www.senocular.com/flash/tutor...ashcs3/?page=4
__________________
FLASHFORUM.RO - You must speak Romanian in order to join. BLOG.WISEBISOFT.COM - Share and Experiment. |
|
|
|
|
|
#6 |
|
Super Moderator
Join Date: Jul 2001
Location: NYC
Posts: 10,065
|
I think the inline XML for this is for example purposes.
__________________
Color Wars™ | (kul′ər wôrs) n. - Open conflict between factions. www.theColorWars.com cota - www.chadworkman.com | http://shavedplatypus.com occupation: designer | flash developer | server-side developer (php, asp, mssql, mysql) |
|
|
|
|
|
#7 |
|
Site Contributor
|
Hey, Cota. Right. I knew that, it just served to remind me.
|
|
|
|
|
|
#8 |
|
Holosuit User
|
As for the inline XML, I use it sometimes for layouting purposes. Say, you have a static layout which uses components with dataproviders. Imagine typical HTML survey, that uses lots of comboboxes with predefined values which aren't likely to change ever, eg. the list of countries / languages / hours of the day etc.
The advantage of doing so: faster initialization less traffic (SWF will zip the XML inside it, while loaded XML is likely to be 50% bigger than zipped, also you don't need to send another request to the server). Also, sometimes I need to have a default XML in place where there may be the loaded later XML. I.e. imagine this: you're trying to fetch user info from the Facebook account. But user didn't fill in all the entries. So, I'd rather take the XML with the default values and replace only the entries that are filled. Thus I won't need to rebuild all the XML anew. I.e. say, there's the username and avatar nodes. User may not supply the avatar picture, but, I need the default avatar picture anyway. So, I process the default XML, build the UI with the default values, then after I load the XML from Facebook, I loop through it to see if the avatar node isn't empty, if so - replace the node in my schema and reload the picture, if not - leave it with the default value. Sorry, it's taking somewhat more time then I originally though, but I'll try to post the continuation today in the evening ![]()
__________________
The .NET open source editor for Flash and web developers *This would be my contribution to the project* couchsurfing if you need it |
|
|
|
|
|
#9 |
|
Holosuit User
|
Q: How do I generate UI elements depending on the values from XML?
A: There're lots of ways you can do it. This example shows how to load number of images dynamically based on their URL defined in XML: For creating symbols from the library rather than loading them see manual on flash.utils.getDefinitionByName() Example ActionScript Code:
This is only an example, you may extend it at will. Example ActionScript Code:
Also keep in mind that usually you'd like to have a more complex condition for sorting. And passing arguments via defining them on the function you use for sorting will not be usually what you want to do. Example ActionScript Code:
Example ActionScript Code:
Example ActionScript Code:
Example ActionScript Code:
ActionScript Code:
Example ActionScript Code:
__________________
The .NET open source editor for Flash and web developers *This would be my contribution to the project* couchsurfing if you need it Last edited by wvxvw; 02-11-2009 at 10:29 PM.. |
|
|
|
|
|
#10 |
|
Intelligent Ape
|
Thumbs up, I love using E4X....I just have to look up information exactly like this because I can never remember the syntax. Thanks a ton!
__________________
"Try the morphine, it's excellent today." |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| E4X vs XMLDocument parsing speed... | CyanBlue | ActionScript 3.0 | 20 | 09-08-2008 05:51 PM |
| E4X, parents of target query? | Reggie1979 | ActionScript 3.0 | 9 | 09-04-2008 08:09 PM |
| How to filter multiple elements by name using E4X predicates? | rollingsj | ActionScript 3.0 | 2 | 05-12-2008 06:40 PM |
| Possible memory leak in e4x or in HttpService | lacito | Flex 2 & 3 | 11 | 10-11-2007 11:03 AM |
| Clarification of Senocular FAQ regarding classes which extend MovieClip | ironchefmoto | ActionScript 2.0 | 3 | 07-18-2007 06:24 AM |