Issues loading data from XML, any help? [Solved]


(Matt Gambell) #1

I’m trying to load some text data from an XML Document like this

package utilities{
import flash.utils.ByteArray;
import net.flashpunk.FP;
import net.flashpunk.Entity;
public class loadTextData 
{	
	public var type:String;
	public var index:int;
	
	public var textArray:Array = new Array ;
	
	[Embed(source="dialogue/prompt.xml")]public const PROMPT_DIALOGUE:Class;
	
	public function loadTextData() {
		
		var promptDataXML:XML = FP.getXML(PROMPT_DIALOGUE);

		
	}}
}

But i’m constantly getting an output failure with:

"[Fault] exception, information=TypeError: Error #1034: Type Coercion failed: cannot convert utilities::loadTextData_PROMT_DIALOGUE@552fff1 to flash.utils.ByteArray."

Every tutorial I’ve looked at have Embedded the XML Document as a class like I have above and have then used the FP.getXML() function with no issue, I’m stumped as to where I’m going wrong…


(Ultima2876) #2

To load XML that way it looks like it has to be stored as byte data. Modify your embed to look like this:

[Embed(source="dialogue/prompt.xml", mimeType="application/octet-stream")]public const PROMPT_DIALOGUE:Class;

This declares the type of the embedded object as being an ‘octet-stream’; which is essentially another word for byte data, which makes it compatible with functions expecting a ByteArray (like FP.getXML).


(Matt Gambell) #3

Excellent, that fixed it! Thanks :smile:


(Ultima2876) #4

No problem at all :slight_smile:

This topic is now closed. New replies are no longer allowed.