ActionScript 3 reading XML tutorial: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Flash tutorial|intermediate|CS6 (CS3 to CS5)|}} {{Incomplete}} <pageby nominor="false" comments="false"/> {{stub}} == Overview == <div class="tut_goals"> ; Learning goals ...") |
m (→Links) |
||
Line 23: | Line 23: | ||
: This text should technical people get going and may not be good enough for self-learning beginners. It can be used as handout in a "hands-on" class. That is what [[User:Daniel K. Schneider|Daniel K. Schneider]] made it for... | : This text should technical people get going and may not be good enough for self-learning beginners. It can be used as handout in a "hands-on" class. That is what [[User:Daniel K. Schneider|Daniel K. Schneider]] made it for... | ||
</div> | </div> | ||
== The principle == | |||
; Loading the DATA into a datastructure | |||
<source lang="XML"> | |||
var data:XML = new XML(); | |||
var xml_Loader:URLLoader = new URLLoader(); | |||
xml_Loader.load(new URLRequest("your_XML_file.xml")); | |||
// once that data is loaded, the event will be passed to the do_XML function | |||
xml_Loader.addEventListener(Event.COMPLETE, do_XML); | |||
</source> | |||
; Use it | |||
<source lang="XML"> | |||
function doXML(e:Event):void { | |||
// data sits in the event's target (aka the load)'s data | |||
data = new XML(e.target.data); | |||
for (var i:int = 0; i<data.*.length(); i++){ | |||
//.... do something here | |||
trace(data.*); | |||
}; | |||
} | |||
</source> | |||
== Links == | == Links == | ||
Line 28: | Line 55: | ||
Thanx to Faisal Rasim | Thanx to Faisal Rasim | ||
; Tutorials | |||
* http://www.maani.us/xml_charts/ | * http://www.maani.us/xml_charts/ | ||
* http://www.republicofcode.com/tutorials/flash/xml/ | * http://www.republicofcode.com/tutorials/flash/xml/ (AS2, not covered here) | ||
* http://www.republicofcode.com/tutorials/flash/as3xml/ (AS3) | |||
; Flash components that can read XML data | |||
* http://www.flashxml.net | * http://www.flashxml.net |
Revision as of 14:05, 27 April 2013
<pageby nominor="false" comments="false"/>
Overview
- Learning goals
The purpose of this tutorial is to show how to load XML data into Flash
- Prerequisites
- ActionScript 3 event handling tutorial
- Flash ActionScript 3 overview
- Moving on
- Flash drag and drop tutorial
- Flash games tutorial
- The Flash tutorials index has a list of other tutorials.
- Level and target population
- It aims at Flash designers, not beginning ActionScript 3 programmers, although programmers can read this to get a feeling for object properties before digging into a real documentation like Adobe's Flash 9 reference manual. Also, some of the code should be rewritten a bit. I skipped type declarations on purpose and should even rip off more. These don't make sense for a few lines of code written by/for non-programmers. The goal is to keep code as simple as possible. I should at some point decide whether I should remove all type declarations from the examples or consistently leave the ones that might be useful in order to receive compiler warnings.
- Quality
- This text should technical people get going and may not be good enough for self-learning beginners. It can be used as handout in a "hands-on" class. That is what Daniel K. Schneider made it for...
The principle
- Loading the DATA into a datastructure
var data:XML = new XML();
var xml_Loader:URLLoader = new URLLoader();
xml_Loader.load(new URLRequest("your_XML_file.xml"));
// once that data is loaded, the event will be passed to the do_XML function
xml_Loader.addEventListener(Event.COMPLETE, do_XML);
- Use it
function doXML(e:Event):void {
// data sits in the event's target (aka the load)'s data
data = new XML(e.target.data);
for (var i:int = 0; i<data.*.length(); i++){
//.... do something here
trace(data.*);
};
}
Links
Thanx to Faisal Rasim
- Tutorials
- http://www.maani.us/xml_charts/
- http://www.republicofcode.com/tutorials/flash/xml/ (AS2, not covered here)
- http://www.republicofcode.com/tutorials/flash/as3xml/ (AS3)
- Flash components that can read XML data