PDA

View Full Version : Loading external image from xml and resizing



panopticon_
July 12th, 2008, 06:45 AM
flash cs3 timeline code:



var band_load:String = "Thrice";
var image_xml:XML;

var xmlReq:URLRequest = new URLRequest("http://ws.audioscrobbler.com/1.0/artist/"+band_load+"/topalbums.xml");
var xmlLoader:URLLoader = new URLLoader();

function xmlLoaded(event:Event):void
{

image_xml = new XML(xmlLoader.data);


//SIMILAR ARTISTS

var imgLoader:Loader;


var slide:Sprite;
slide = new Sprite();
//slide.width = 10;
//slide.height = 10;
slide.x = 10;
slide.y = 10;
addChild(slide);

imgLoader = new Loader();
imgLoader.load(new URLRequest(image_xml.album[0].image.medium));

slide.addChild(imgLoader);

}

xmlLoader.load(xmlReq);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
i dont know how to resize the loaded image, if i use



slide.width = 10;
slide.height = 10;
nothing is displayed :(. if i remove these 2 lines, everything works fine but my image is not the right size

stringy
July 12th, 2008, 09:47 AM
wait until it loads

imgLoader.contentLoaderInfo.addEventListener(Event .INIT, imgLoaded);

function imgLoaded(e:Event):void {
//can use slide.width/slide.height
e.target.content.width = 10;
e.target.content.height = 10
}

Chuckanucka
July 12th, 2008, 11:08 AM
the image has be to loaded before you can retrieve its properties.

whoops should have read the post above ^

panopticon_
July 12th, 2008, 12:30 PM
thanks, works like a charm :)