Jump to content
GreenSock

Benjamin Waller

error " 1046: Type .... not a compile-time constant: ContentDisplay.

Recommended Posts

hello there,

 

I'm getting an error when trying to get the Contents from an XML file as followers.

 

Here's the code:

 

LoaderMax.activate([imageLoader, XMLLoader, DataLoader, MP3Loader]);
var loader:XMLLoader = LoaderMax.parse("viet_alphabet.xml",{name:"viet_alphabet", onComplete:parse_xml,estimatedBytes:20000});
loader.load();[/size][/font]
[font=verdana,geneva,sans-serif][size=5]function parse_xml(event:LoaderEvent):void
{
  //trace (event.target.content.letter);
  //var xmlList = event.target.content.letter;
  var firstLetter:ContentDisplay = LoaderMax.getContent("b");
  trace (firstLetter);

 

and a bit of the XML data:

 

<?xml version="1.0" encoding="UTF-8"?>
<data>
<LoaderMax name="VietnameseAphabet" load="true">
 <letter id="b" audioPath="assets/sound/alphabet/b.mp3"><![CDATA[b]]></letter>
 <letter id="c" audioPath="assets/sound/alphabet/c.mp3"><![CDATA[C]]></letter>
 <letter id="d" audioPath="assets/sound/alphabet/d.mp3"><![CDATA[D]]></letter>

Any ideas?

Cheers,

Ben

Link to comment
Share on other sites

hmmm. unfortunately you are doing a few things wrong.

 

1: you can't pass in an xml file url to LoaderMax.parse();

 

EDIT: And have LoaderMax automatically analyze every URL that is in the XML. Pls see greensock's response below /EDIT

 

2: LoaderMax has no understanding of how your <letter> nodes are configured and can not create the appropriate SWFLoaders based on the content of the audioPath attribute.

 

firstLetter:ContentDisplay = LoaderMax.getContent("b") is not going to work :(

 

I would have to suggest at this point that you read the XMLLoader docs and try to structure you xml around the examples given in there. You best bet is to configure the xml more like:

 

<LoaderMax name="VietnamesAlphabet" load="true">
<SWFLoader name="a" url="assets/sound/alphabet/a.mp3 />
<SWFLoader name="b" url="assets/sound/alphabet/b.mp3 />
<SWFLoader name="c" url="assets/sound/alphabet/c.mp3 />
  </LoaderMax>

 

you can absolutely keep the xml the way you have it but it would require you to first:

Load the xml with an XMLLoader

Manually parse out the url attributes and add them to an array

pass that array into LoaderMax.parse() so that LoaderMax can create the SWFLoaders based on the urls.

  • Like 1
Link to comment
Share on other sites

Just one minor correction: you can pass an XML url to LoaderMax.parse() - it will simply spit back an XMLLoader because it interprets that URL as being an XML file (it ends in ".xml"). What was likely confusing things is that it seemed like maybe you were expecting LoaderMax to go get that xml file and parse its contents using LoaderMax.parse() which of course it doesn't. Carl explained everything else perfectly - XMLLoader can only interpret certain things automatically inside the XML file. Specifically, LoaderMax-related nodes like <ImageLoader />, etc.

 

Have fun.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Sorry for this late reply. Thanks for pointing that out. I'm getting there slowly!

 

Appreciate both your comments.

Cheers,

 

Ben.

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.
×