-
Senior Member
Loading XML
First I'm trying to get this XML file to load, but it's coming up undefined. Here's the actionscript:
var MyX:XML=new XML();
MyX.ignoreWhite=true;
var urls:Array=new Array();
var captions:Array=new Array();
MyX.onLoad=function(){
var photos:Array=this.firstChild.childNodes;
for(i=0;i<photos.length;i++){
urls.push(photos[i].attributes.url);
captions.push(photos[i].attributes.caption);
}
}
holder.loadMovie(urls[0]);
caption.text =captions[0];
MyX.load("funky.xml");
Now, here's the XML file:
<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow>
<photo url="m51.jpg" caption="M5 power, untouchable" />
</slideshow>
I have a movieclip and text field on the stage with the instance names "holder" and "caption" respecively.
-
up to my .as in code
You're trying to load the array items before the data is all pushed in. Tuck it back one bracket so it's done after the loop pushes all the items
var MyX:XML=new XML();
MyX.ignoreWhite=true;
var urls:Array=new Array();
var captions:Array=new Array();
MyX.onLoad=function(){
var photos:Array=this.firstChild.childNodes;
for(i=0;i<photos.length;i++){
urls.push(photos[i].attributes.url);
captions.push(photos[i].attributes.caption);
}
holder.loadMovie(urls[0]);
caption.text =captions[0];
}
MyX.load("funky.xml");
-
Senior Member
I fixed it; it's loading well now...
Howeve,r when I insert my CDATA tags , it's coming back undefined..
Here is the CDATAtags:
<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow>
<photo url="m51.jpg" caption="The m5 is the meanest Sedan in the world, check out the <![CDATA[<a href='http://www.bmwusa.com'>M5 Power.</a>]]>
" />
</slideshow>
I made the textfield "caption" HTML enabled; still coming back undefined... the CDATA issue is the problem now...
-
up to my .as in code
You should swap out to element style instead of attribute style if using CDATA.
-
Senior Member
I'm not familiar with element style. Can you provide an example or a working fla? I just need hyperlinks to work in XML files...
It is my view that hyperlinks in XML files that would be loaded into Flash needs some attention in the Flash community because msot people, even advanced scripters that I know, doesn't know the simple or standard way to insert hyperlinks in xml. Doesn't Flash 8 has a need and improved XML parser?
-
up to my .as in code
Well, it depends on the delivery. I can, for instance send in a url without CDATA from the XML and use it for a hyperlink on the frontend. What you are doing is sending in html with the hyperlink coded as html...in this case the methods have always been the same and once you are used to using CDATA, it's something you will always rely on for the purpose. Even with AS3 and Flex 2/Flash 9 it's used when sending in html formatted strings.
I'll contact you back with an example when I get home
-
up to my .as in code
Using this style of XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<items>
<slideshow>
<pic>image15.jpg</pic>
<caption><![CDATA[<a href='http://www.bmwusa.com'>M5 Power</a>]]></caption>
</slideshow>
</items>
And this AS:
var MyX:XML=new XML();
MyX.ignoreWhite=true;
var urls:Array=new Array();
var captions:Array=new Array();
MyX.onLoad=function(){
var photos:Array=this.firstChild.childNodes;
for(i=0;i<photos.length;i++){
urls.push(photos[i].childNodes[0].firstChild.nodeValue);
captions.push(photos[i].childNodes[1].firstChild.nodeValue);
}
holder.loadMovie(urls[0]);
caption.htmlText =captions[0];
}
MyX.load("funky.xml");
You'll be cruisin
Last edited by Chris_Seahorn; 02-08-2007 at 04:50 PM.
-
up to my .as in code
I see you've bumped into another thread asking the same thing I just posted scripting for so I'll close this one.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|