XML:
-
<code>
-
<make reference="w" class="BasicView" args="stage.stageWidth, stage.stageHeight, false"/>
-
<call method="addChild" args="w"/>
-
-
<make reference="wireMat" class="WireframeMaterial" args="0x000000" />
-
-
<make reference="sphere" class="Sphere" args="wireMat, 100" />
-
-
<call method="w.scene.addChild" args="sphere" />
-
-
<make reference="animation" class="Object">
-
<set z="-500" rotationY="360" rotationX="360" ease="Back.easeOut"/>
-
</make>
-
-
<call method="TweenLite.to" args="sphere, 3, animation" />
-
-
<call method="setInterval" args="w.singleRender, 32" />
-
-
</code>
This snippet shows XML that the mini-library AsXML can read and run - in this case AsXML is set up to run with Papervision
A few days ago I had the idea to write some code that would run ActionScript based on XML. I spent some time getting rid of a few bugs and setting up some demos with TweenLite, Papervision and QuickBox2D. I wrapped everything up into a mini-library called AsXML.
Download AsXML and demo files here.
AsXML Features:
1) call methods of the main timeline
2) read and write properties on the main timeline
3) instantiate classes on the main timeline
4) call methods on these classes
5) read and write properties on these classes
6) store references to return values from functions
8 Comments
So it’ a bit like ANT, but for AS3. Interesting
@Mr.doob It’s sort of like ANT in the way the xml file is organized… but it doesn’t have anything to do with compiling/building… it just creates a bunch of dynamically typed objects at runtime based on the XML - it then sets properties and runs methods on those objects (again based on the XML file)… My knowledge of ANT isn’t all that extensive so maybe it does something like that for Java and I just wasn’t aware of it…
i love you for this…
thanks… if you end up using it on something cool… let me know…
yea i got some cool stuff planned… can do some interesting serverside scripted as3/xml hybrid heh… last night I added to the class ability to do basic arithmetic in the xml which is really useful so you can do for loops on methods etc and basic string parsing like (4+4)/2 and in theory you could do vars too… which would be sick for loops (i*20) in xml heh
i’m trying to fix one particular problem tho… it only seem s to compile with Flash CS4… i’ tried for a while last night and couldn’t figure out why i couldn’t get to compile via Flash Builder it has something to do with what “this” is considered … tonight i’ll try to use a document class+Flash CS4 but I think it will face same problem with targeting the root.
Thanks alot for this one… i’ve been in search of solutions your works solve and may I say that is one beautiful parser class
Hey cmoore that sounds cool. What math parser did you use? for the (4+4)/2 stuff…
it should work in flex, I can look at that a little later today… what is the error that your getting? the asxml class adds properties to the flash movie dynamically … so you’ll need to add the dynamic keyword to your document class - maybe that’s the problem…
thanks zevan making it dynamic maked it work perfectly
i got my start for the string eval class here its proven really useful with xml so cant wait to try it with your classes.
http://www.actionscript.org/forums/showthread.php3?t=160367
also another interesting library would be the AS3 eval library…
thanks again for the blog really amazing stuff
cool… that flash and math lib from that post is the one I would recommend…
I have an as3 eval library almost finished but its not as good as the flash and math one…
3 Trackbacks
[...] 做一個跟twitter相同風格的logo嗎~ twitlogo 把任何的png圖片轉成PV3D object的class ExtrudeImage 這不是mxml… XML to ActionScript [...]
[...] XML to ActionScript #3 (AsXML) [...]
[...] – XML to ActionScript #3 (AsXML) [...]