AS3 Read XML document __game

Source: Internet
Author: User

I use the development tool is: Flash Professional CS5.5

Create a new AS3 project, save the FLA file as: F1.fla, create a new AS3 file, file name: main.as, code as follows:

Package  {
	
	import flash.display.MovieClip;
	Import Flash.net.URLLoader;
	Import Flash.net.URLRequest;
	Import flash.events.Event;
	
	public class Main extends MovieClip {
		
		var url:urlrequest = new URLRequest ("Data.xml");
		var loader:urlloader = new Urlloader (URL);
		var myxml:xml = new XML ();
	
		Public Function Main () {
			Loader.addeventlistener ("complete", success);
		}
		
		Private Function Success (event:event): void
		{
			myxml = XML (loader.data);
			
			Trace ("CC0: [" + myxml.name () + "]#");
			Trace ("CC0: [" + Myxml.nname + "]#");
			Trace ("CC1: [" + myxml.child (0) + "]#");
			Trace ("CC1: [" + myxml.child (0). Length () + "]#");
			Trace ("CC2: [" + Myxml.child ("age") + "]#");
			Stop ();}}


XML Document: Data.xml

<root>
	<nname>Hello</nname>
	<age>25</age>
</root>

Press CTRL ENTER to run:

CC0: [root]#
cc0: [hello]#
cc1:
[hello]# cc1: [1]# cc2: [25]#

Note: The AS3 can be accessed directly by the node name, or through the child to access the node.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.