home | articles | career center | tutorials | fla downloads | music loops | flash directory | games | |
![]() |
|
profile | register | faq | search | today's hot topics |
![]() ![]() |
![]() ![]() |
Last Thread | Next Thread |
We're Here Forums! > Flash 5 ActionScript > Double your XML speed | |||
Author | Thread This thread is 2 pages long: 1 2 | ||
AquaFig WH Senior Member Registered: Aug 2000 Posts: 203 |
Hey all... first a little background info: Turns out there is this undocumented function in Flash 5 called ASNative. It calls out to the player and runs a direct call from there. Now normally, that would be a big deal, as it does the exact same stuff you can do with other functions normally. However, in one case it *is* a big deal... When you call ASNative you pass it two parameters. A lot of the possible number combinations are blank, I believe to allow for custom additions to the Flash player. Anyways, it looks like this: ASNative(x,y) this will return back a reference to a function. It just so happens that the function living at 300, 0 is what does the actual parsing of XML for Flash. When you call it you pass it two things, the string you want to parse and a blank array you want filled with the resulting tags: tags = new Array(); status = ASNative(300, 0)(xmlstr, tags); optionally you can also specify a boolean as well, this is the ignoreWhite attribute that was added in the R41/42 player and hence won't work in the r30 player. Anyways, this will result your tags array being filled with the nodes from the XML file, that is, unless there was a problem with parsing, in which case the appropriate status code will be returned. The actual elements in your array will be objects with the following attributes: value - value or name of node or xml decl or xml doc decl type - 1-node, 3-text, 4-xml decl, 5-xml doc decl attrib - object containing all attributes for this node empty - boolean, true if node is empty Now, here's the neat thing, this parsing is *fast*! We are talking 250+K in less than a second and half! Turns out that its the conversion from that flat array to the XML object structure that is slow! So... as I found out, if you rewrite that part of the actual parsing with a mind toward hard-core optimization, you can get a 70-120% improvement in parsing speed. w00t! Oh, and if you are a little industrious you can also get it so that ignoreWhite works in all versions of the Flash player ;-) One quick disclaimer, this is an undocumented funciton and as such may not be around in Flash 6. Thats why the code is wrapped in a version checker... Just drop the AS file in the directory of your FLA and add #include "ASnitro.as" to the first frame of your movie. Enjoy! http://chattyfig.figleaf.com/~bhall/killastuff/XMLnitro.as __________________ -= Branden J. Hall -= Senior Interactive Developer/Instructor -= Fig Leaf Software - "We've got you covered!" IP: Logged |
||
QueMark WH Superstar Registered: Jul 2001 Posts: 350 |
Wow thanks for the post, AquaFig! This is definitley something that would really help out. I have up till now not very pleased with the speed of the XML parser in Flash as opposed to other XMLparsers. Hope this sticks around in Flash 6! __________________ ![]() IP: Logged |
||
cwes WH Flasher Registered: Feb 2001 Posts: 76 |
just curious as to how you found out about the function??? Thanks for the post btw, -Wes ___________________ http://www.opticstatic.com IP: Logged |
||
AquaFig WH Senior Member Registered: Aug 2000 Posts: 203 |
Just FYI to anyone using XMLnitro.... make sure you get the new version(same URL). It fixes some issues with CDATA sections as well as some problems it had with the newest versions of the Flash plugin. __________________ -= Branden J. Hall -= Senior Interactive Developer/Instructor -= Fig Leaf Software - "We've got you covered!" IP: Logged |
||
joe_reach2 WH Flasher Registered: Jul 2001 Posts: 2 |
genius IP: Logged |
||
phriso WH Flasher Registered: Feb 2000 Posts: 8 |
printting the array elements Now that I have parsed in the xml with ASNative how do I get at the array elements? thansk in advance IP: Logged |
||
AquaFig WH Senior Member Registered: Aug 2000 Posts: 203 |
Each element in the resulting array is an object. Just do a for...in loop over one of these objects to see what's there. __________________ -= Branden J. Hall -= Senior Interactive Developer/Instructor -= Fig Leaf Software - "We've got you covered!" IP: Logged |
||
Johannes WH Flasher Registered: May 2001 Posts: 20 |
Thanks AquaFig for sharing this inside information. I've been developing XML driven Flash apps since Flash5 was released and this undocumented function is a pleasant surprise. I hope somebody from Macromedia is monitoring this forum and realizes that it makes sense to expose this function or something similar in future releases as well. IP: Logged |
||
phriso WH Flasher Registered: Feb 2000 Posts: 8 |
still not clear I'm still not clear on how to read the array holding the xml? Any help would be appreciated. Thanks in advance. my script #include "XMLnitro.as" myArray = new Array(); tags = new Array(); status = ASNative(300, 0)("cd.xml", tags); trace ("tags.length="+tags.length); trace ("value="+tags[0]["value"]); trace ("attrs="+tags[0].attrs); for (name in tags[0]) { trace ("tags[0]."+name+" = "+tags[0][name]); } stop (); the output tags.length=1 value=cd.xml attrs= tags[0].attrs = tags[0].empty = false tags[0].value = cd.xml tags[0].type = 3 IP: Logged |
||
AquaFig WH Senior Member Registered: Aug 2000 Posts: 203 |
You pass the *string* you want to parse to ASNative. Not the name of the document. You don't have to include XMLnitro.as to play with ASNative. In fact, to use XMLnitro, you don't do *anything* different from using XML the way you would normally. It just speeds everything up. __________________ -= Branden J. Hall -= Senior Interactive Developer/Instructor -= Fig Leaf Software - "We've got you covered!" IP: Logged |
||
phriso WH Flasher Registered: Feb 2000 Posts: 8 |
post an example can you post an example script that uses this? thanks in advance. IP: Logged |
||
AquaFig WH Senior Member Registered: Aug 2000 Posts: 203 |
#include "XMLnitro.as" That's it! Seriously! You don't have *do* anything else, just code your XML as usual! __________________ -= Branden J. Hall -= Senior Interactive Developer/Instructor -= Fig Leaf Software - "We've got you covered!" IP: Logged |
||
davro WH Senior Member Registered: Feb 2001 Posts: 161 |
Just tested on old project. "nice" Makes getting medium to large docs in the flash player a bit more realistic now, xml has always needed a bit of a shove. Cheers Aquafig. Davro UT "Nan_slayer" __________________ IP: Logged |
||
sambuca WH Flasher Registered: Aug 2001 Posts: 3 |
anyone check this one? http://www.alabamasubs.com/541am/xmlq/ <!----------------------------------- oh yeah: Alabama subs' developer spends more time rockin' .as code than he does making sandwitches... -------------------------------> [Last edited by sambuca on 08-08-2001 at 03:03 PM] IP: Logged |
||
wehr WH Flasher Registered: Jun 2001 Posts: 2 |
oh god...its not at alabamasubs... alabamasubs...oh no... my parent's buissiness's site on the same IP... (I should redesign that for them) I think you are looking for: http://www.541am.com/541am/xmlq Its a Queued XML object based on XMLnitro. The difference is that XMLq shifts the parsing to the next frame if it takes too long, which means you dont have the 'stall' when an large XML document is being loaded. john info@johnwehr.com [Last edited by wehr on 08-08-2001 at 01:07 PM] __________________ Full Browser Window @ http://www.541am.com IP: Logged |
||
Rods Tiger WH Flasher Registered: Jul 2001 Posts: 11 |
AquaFig - how closely is this ASNative(300,0) thingy related to a SAX parser? Or more to the point, is it 'event' based as opposed to the fully tree based paradigm of the resulting DOM tree that lives in the XML object? If it's SAX derived, I wonder if it's capable of somehow firing off events on certain situations, without having to have the entire XML document or file or stream having been eaten completely. That is, if you want to retrieve a specific element's text or something, normally, you'll have to have Flash eat the whole XML file before you can do something useful with it, because the DOM tree has to be constructed in the XML object, and to do that, it has to get closure of every element, including the root element. Only then can it let you at it. __________________ Cheers. Ian Tindale. Join the Flash XML Yahoo group: http://groups.yahoo.com/group/flashxml/join IP: Logged |
||
DT Blabbermouth Registered: Oct 2000 Posts: 2183 |
***** BUMP ****** Hi, sorry to bump, could someone explain how to use XMLnitro.as in normal usage. Esp. I undrestand from various postings that it includes an ignore whitespace function that covers all flash5 versions. Any help much appreciated. DT IP: Logged |
||
HumanCompiler WH Senior Member Registered: Jul 2001 Posts: 280 |
Actually, yah, thanx for asking DT, cuz I want to know too...I tried it and it didn't help out the performance in my stuff that I already had written...in fact, it broke it! ![]() as for .ignoreWhite = true; that's only for Flash 5 r 41 it's the easiest way by far though, if your clients have that version... __________________ /signature Erik "Life's a bowl of punch, g'ahead and spike it!" -311 IP: Logged |
||
phriso WH Flasher Registered: Feb 2000 Posts: 8 |
http://flash5actionscript.com/xmlobject.shtml shows an example, I have got it to work but sorting through a large file is still a problem. IP: Logged |
||
AquaFig WH Senior Member Registered: Aug 2000 Posts: 203 |
All you need to do is #include "XMLnitro.as" That's it. The .ignoreWhite *will* work in both versions of the Flash plugin with XMLnitro *except* if you have mixed-content nodes. As for the questions about ASNitro, it doesn't work like SAX at all since the data you recieve is still in one big flat array. You may be able to get it work more like SAX, but that would require sorting out a parse-over-frames type solution as well as a decent event model. __________________ -= Branden J. Hall -= Senior Interactive Developer/Instructor -= Fig Leaf Software - "We've got you covered!" IP: Logged |
||
|
![]() ![]() |
Admin Options: |
< Contact Us - We're Here Forums! - Privacy Statement >
Powered by: vBulletin Version 1.1.5
Copyright © Jelsoft Enterprises Limited 2000.
Copyright, We're Here Forums!, 1999-2000
home | articles | career center | tutorials | fla downloads | music loops | flash directory | games |