Jump to content
Search Community

How to load text from XML to flash using loaderMax

dragontail test
Moderator Tag

Recommended Posts

I have been trying loaderMax sometime. There are alot of example of how to load image, swf and xml. but no loading for text.

The only text i can load is using xml to get url of a text file.

But what if, i want it to be dynamic, like i have 5 question set in xml.

<?xml version="1.0" encoding="utf-8"?>



This is question 1.
This is question 2.
This is question 3.
This is question 4.
This is question 5.



And i can use a array to get all the text from xml, and use it in flash.

Thank for helping.

Link to comment
Share on other sites

G'day mate,

 

First step in your XML is you might want to fix the end tag from to or your XML won't be well formed.

 

And this should be what your looking for.

 

	public function main() 
	{
		//Setup your XML Loader Var, listener and tell your XML object to load
		var xLoader:XMLLoader = new XMLLoader("file.xml")
		xLoader.addEventListener(LoaderEvent.COMPLETE, xmlLoaded)
		xLoader.load();
	}

	private function xmlLoaded(e:LoaderEvent):void 
	{
		//When your XML is Loaded, trap it in a new XMLList variable, along with the first node name
		//in this case, LoaderMax as it follows the  node
		var xList:XMLList = new XMLList(e.target.content.LoaderMax)
		//You can now navigate through the XMLList by calling the node name in your XML
		//For eg. to get Q1 text you would use:
		trace(xList.Q1);
	}

Link to comment
Share on other sites

Thanks mate~

It works, but how about this.

What if i want it to be random data?

Here are the XMl.

<?xml version="1.0" encoding="UTF-8" ?>


400


100


120


And this is part of the AS file

	private function completeHandler(event:LoaderEvent):void {
		var xList:XMLList=new XMLList(event.target.content.LoaderMax);
		var o:Number=Math.ceil(Math.random()*3);
		var energyo="energy"+o
		var value1:Number=xList.energyo;
		var value1_per=Math.ceil(Math.random()*20)+value1;
		trace(value1);
		trace("this is energy "+value1_per);
	}

The result is value1 = 0;

Any solution?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...