Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Build a Better Charting Engine Using Flash and XML : Page 4

When you need to display data as charts in a Web app, forget about precompiled DLLs, assemblies, and expensive third-party components. This article will teach you how to use Flash MX to take data from any server-side script and render it in sleek-looking, animated charts.


advertisement
Loading the XML Data
There are three steps involved in loading XML data:
  1. Request XML from the HTML page.
  2. Validate the XML document.
  3. Parse the data and store into local objects, arrays, and variables.
To load the XML data, open the Actions Panel for Frame 1 on the Actions layer. This keyframe contains all the ActionScript required for loading XML:

//XML Object xmlData will store the entire XML Document var xmlData = new XML();

Create an XML object to store the data named xmlData:

//Request the data from the HTML Page and store it in the xmlData XML object. xmlData.parseXML(_root.data);

Request the XML data from the HTML page and use the parseXML method of the XML object to store it in the XML object. The data is provided to the chart in the following form:


<HTML> ... Other Contents ... <OBJECT ..> <PARAM NAME='Movie' Value='FCChart.swf'> <PARAM NAME='FlashVars' Value='&data=<chart>...</chart>'> ...<EMBED ... FlashVars='&data=<chart>...</chart>' ..> </OBJECT>

Use _root.data to access the HTML page in Flash:

//Check for error in XML document if (xmlData.status != 0) { //Means, there was an error in the XML document //- so redirect to frmXMLError gotoAndPlay("frmXMLError"); }

To check for errors in the XML document, use the XML doc's status property. When the XML document is perfectly valid, the status becomes 0.

If the status isn't 0, move the control to the XML error frame (frmXMLError) to display the appropriate error message. When the data has been validated, move on to step three.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date