Newbie need help on loading image to movieclip

I’ve read the tutorial Photo Gallery Using XML and Flash from Kirupa but I’m trying to implement it in AS3… I have no knowledge on AS1/2 which also means I have no idea if I’m writing the correct codes or not…

First of all, below is the code that I’ve written:


import flash.display.*;
import flash.events.*
import flash.display.Loader;
import flash.display.LoaderInfo;

var images_list:Array = new Array();
var images_count:int = 0;
var loaded:int = 0;
var loaded_filesize:int = 0;

//Create the loader, set dataFormat to text 
//and listen when data is loaded
var xmlString:URLRequest = new URLRequest("images.xml");
var xmlLoader:URLLoader = new URLLoader()
xmlLoader.dataFormat = URLLoaderDataFormat.TEXT
xmlLoader.addEventListener(Event.COMPLETE, onImagesXMLLoadComplete)
xmlLoader.load(xmlString);

function onImagesXMLLoadComplete(ev:Event):void
{
	trace("Parsing XML...");
	try
	{
        //Convert the downloaded text into an XML
        var myXML:XML = new XML(ev.target.data)
        var list:XMLList = myXML..image;
		this.images_count = list.length();
        for(var i=0; i<this.images_count; i++)
		{
			this.images_list.push(new Array(list*.filename, list*.caption));
        }
		trace(this.images_list);
		this.display_first_image();
	}
	catch (e:TypeError)
	{
        //Could not convert the data, probably
        //because is not formated correctly
        trace("Could not parse the XML")
        trace(e.message)
    }

}

/////////////////////////////////////

prev_btn.addEventListener(MouseEvent.CLICK, onPrevButtonClickEvent);
next_btn.addEventListener(MouseEvent.CLICK, onNextButtonClickEvent);

function onPrevButtonClickEvent(e:Event):void
{
	trace("previous btn clicked");
}

function onNextButtonClickEvent(e:Event):void
{
/*	if (p<(total-1)) {
		p++;
		if (loaded == filesize) {
			picture._alpha = 0;
			picture.loadMovie(image[p], 1);
			desc_txt.text = description[p];
			picture_num();
		}
	}
*/
	trace("next btn clicked");
}


this.addEventListener(Event.ENTER_FRAME, onEnterFrameEvent);

function onEnterFrameEvent(e:Event):void
{
/*	this.filesize = Stage.loaderInfo.bytesTotal();
	this.loaded_filesize = Stage.loaderInfo.bytesLoaded();
	preloader._visible = true;
	if (this.loaded_filesize != this.filesize) {
		preloader.preload_bar._xscale = (this.loaded_filesize / this.filesize) * 100;
	} else {
		preloader._visible = false;
		if (image._alpha < 100) {
			image._alpha += 10;
		}
	}*/
}

function display_first_image():void
{
	trace("loading ..." + this.images_list[0][0]);

	//if (this.loaded_filesize == this.filesize)
	//{
		var loader:Loader = new Loader();
		loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInitEvent);
		//loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		var request:URLRequest = new URLRequest(this.images_list[0][0]);
		loader.load(request);
		image.addChild(loader);
		trace(stage.stageHeight);
		image.x = 0;
		image.y = 0;
	//}
}

function onLoaderInitEvent(event:Event):void {
	// for now just displaying the info from LoaderInfo
	var loader:Loader = Loader(event.target.loader);
	var info:LoaderInfo = LoaderInfo(loader.contentLoaderInfo);
	trace("initHandler: loaderURL=" + info.loaderURL + " url=" + info.url);
}

The codes are almost completely different from the tutorial but I’m able to get the XML loading/parsing part working. However, I’m stuck at the point on how to load images correctly to MovieClip. The area I’m can be narrowed down to:


function display_first_image():void
{
	trace("loading ..." + this.images_list[0][0]);

	//if (this.loaded_filesize == this.filesize)
	//{
		var loader:Loader = new Loader();
		loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInitEvent);
		//loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		var request:URLRequest = new URLRequest(this.images_list[0][0]);
		loader.load(request);
		image.addChild(loader);
		trace(stage.stageHeight);
		image.x = 0;
		image.y = 0;
	//}
}

The variable image is an instance of symbol (MovieClip).

I’m not sure about:
[LIST=1]
[]Is this the correct way to load an image in AS3 ?
[
]If so, how can I set the height and width of the variable image (movieclip) to, say 300x300? doing something like image.width = 300; will cause the image disappear.
[*]If the picture is larger than the movieclip area (eg. 300x300), how can I resize the image to fit in the movieclip area ?
[/LIST]

Somebody please help me ? :puzzle: