views:

281

answers:

1

I am trying to embed some xml into my application but I get the following error

Fault] exception, information=TypeError: Error #1090: XML parser failure: element is malformed.

Here is my code.

package 
{
    import com.objects.EngineApi;
    import com.objects.Rectangles;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    /**
     * ...
     * @author Anthony Gordon
     */


    public class Main extends Sprite 
    {
        [Embed(source = "com/files/level1.xml", mimeType = "application/octet-stream")]
        private var theClass:Class;


        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            var xmlObj:Object = new theClass();
            trace(xmlObj);
            var xml:XML = new XML(xmlObj) as XML;
        }

    }

}

xml code

< STAGE>
    < OBJECTS>
        < BLOCK X="2" Y="23" WIDTH="36" HEIGHT="4" />
        < SPAWN X="6" Y="22" />
        < BLOCK X="12" Y="21" WIDTH="4" HEIGHT="2" />
        < TUTORIAL X="18" Y="16" TEXT="..." />
        < TUTORIAL X="28" Y="22" TEXT="..." />
        < BLOCK X="36" Y="2" WIDTH="2" HEIGHT="16" />
        < JUMPTHRU X="32" Y="9" WIDTH="4" />
        < BLOCK X="27" Y="9" WIDTH="5" HEIGHT="2" />
        < COIN X="28" Y="7" />
        < COIN X="30" Y="7" />
        < COIN X="32" Y="7" />
        < COIN X="34" Y="7" />
        < BLOCK X="17" Y="8" WIDTH="5" HEIGHT="2" />
        < BLOCK X="2" Y="9" WIDTH="10" HEIGHT="2" />
        < CHEST X="19" Y="7" COINS="5" />
        < DOOR X="5" Y="8" />
        < BLOCK X="37" Y="20" WIDTH="2" HEIGHT="3" />
        < BLOCK X="1" Y="5" WIDTH="3" HEIGHT="4" />
        < BIRD_GOLD X="2" Y="4" COINS="3" TIME="5" />
    </ OBJECTS>
</ STAGE>
A: 

That is a runtime error, meaning the actual embed is working but the xml-parser croaks when reading it. This can mean many things, either that the markup is wrong to begin with, you're reading it wrong or that the actual embed breaks the xml somehow.

My bet is that this is where your problem is:

var xmlObj:Object = new theClass();
trace(xmlObj);
var xml:XML = new XML(xmlObj) as XML;

This will likely trace as [Object object] or something like that, which is the same string Flash will try to parse as XML.

I can't test this right now, byt try setting the mimetype of the embed to "text/xml" and doing like this instead:

var xml:XML = new theClass;
grapefrukt