Actionscript RMXml
August 13th, 2007
This flash tutorial explains how to use my Actionscript 2.0 RMXml class to load simple single node xml files into flash projects. This assumes you want to extract content data from an xml file and display it in a TextField. It even allows basic html formatting by using [brackets] in place of <html tags>
I use a class that i named RMXml in flash projects that require loading xml text content. This class is included in my “New Flash Project page” template.
I’ll probably make this a static class, or at least make a get content_txt function :D
Download the “New Flash Project” template
download “newflashproject.tar.bz2” 12.7 KB
download “newflashproject.zip” 16.5 KB
visit “New Flash Project page”
View the “RMXml” class
How To Use RMXml actionscript 2.0
- first create a TextField object on the stage with an instance name, make sure this TextField is multiline
- name this dynamic text field “myTextField” for this example
- then create an xml file in the xml/ directory (subdirectory of the project directory) and save it as “myContent.xml”
- copy and paste this sample xml as an example if you like
sample xml/myContent.xml
(if the <content> node begins with a [bracket] like this example, you need a leading space first)
- copy and paste this sample xml as an example if you like
<?xml version="1.0" encoding="utf-8"?> <content> [font size="15"]My simple html content[/font] [br /] [i]examples are fun[/i] Line breaks like this will produce an extra empty line use [br /] for a single line break. [u][a href="http://remixtechnology.com"]links work too![/a][/u] so do [u]underlines[/u] and [b][u]nested tags[/u][/b] the end </content>
- finally, create an RMXml object using this RMXml class with FileName and TextField as arguments.
main.as
class main { function main(){ var myXML:RMXml = new RMXml(“myContent”, _root.myTextField); } }
if you have a dynamic text field in main.fla with an instance name of “myTextField”, a file in a subdirectory called xml/ named myContent.xml with the previously mentioned xml content, the RMXml.as and cfg.as classes in a subdirectory called classes/, and your classpath set to classes/, then the above code will certainly work. otherwise, just use my “New Flash Project page” to see how it all works together.




