Log in

View Full Version : Use XML to load .jpg



evan
10-23-2008, 08:11 PM
With this code I am retrieving text from an XML node and placing it in a textbox

Code:


var myxml:XML;
var data:String;
var loader:URLLoader= new URLLoader();


loader.addEventListener(Event.COMPLETE,OnComplete);

loader.load(new URLRequest("myxml.xml"));
function OnComplete(evt:Event):void
{

myxml = new XML(evt.target.data);
loader.removeEventListener(Event.COMPLETE,OnComplete);
//trace(myxml.Content);
data=myxml.Content;
//trace (textdata)

textbox.text=textdata;

}


I also figured out how to use a loader to place images.

Can I use xml to load images? I'm not sure how to do it.

if my xml file has <picture>mypicture.jpg</picture>
I tried this in my code but it didn't work:

data=myxml.picture.mypicture.jpg

rd42
10-24-2008, 02:36 PM
This helped me, but I can't get it to display .png files, only jpeg.

http://www.gotoandlearn.com/play?id=22

It's a great tutorial and you can download the files.

Robert

evan
10-24-2008, 05:01 PM
This was a good toturial -I think I remember watching it, so I think I want to redirect my question to how this is done in Actionscript 3:

Namely in this example, you can access the nodes by decaring variables:
As2 version:

var urls:Array=new Array();
var captions:Array=new Array();
next he does this:


var photos:Array= this.firstChild.Childnodes;
//then a loop

for (1=0;<photos.legnth;i++)
{
urls.push(photos[i].attributes.url
captions.push(photos[i].attributes.url
}


is there an easy explanation for how this works in As3?

Medyman
10-24-2008, 06:04 PM
Since he can do a much better a explaining AS than I can, I'll let Lee finish the explanation:

http://www.gotoandlearn.com/play?id=64
http://www.gotoandlearn.com/play?id=65

The XML parsing structrue is a lot easier in AS3.

evan
10-24-2008, 07:31 PM
I have also seen those and played with them a bit

those show how to work with an rss feed and how to get style settings from a remote source.

but what I am trying to do on my own is a simple call to an xml node from an actual xml file to get the jpeg and place it

then push them into an array and place them on the stage just like the as2 version does.

Medyman
10-24-2008, 09:20 PM
The methodology is the same. If you post your XML structure, I can give you some tips.