Hi,
I am new into working with classes and I have a problem with addChild.
First I have a class called ThumbGrid in an external actionscript3 file:
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
public class ThumbGrid {
private var pHeight:Number = 100;
private var pWidth:Number = 75;
private var listLoader:URLLoader = new URLLoader( new URLRequest("filelist.xml") );
private var arrPicLoaders:Array = new Array();
private var arrPicList:Array = new Array();
private var numImages:Number;
private var stImagedir:String = "pix/";
public function ThumbGrid():void {
trace("constructor");
//constructor
listLoader.addEventListener(Event.COMPLETE, makePictureLoader);
}
private function makePictureLoader(e:Event):void {
trace("function: makePictureLoader");
//lees XML
var xmlData:XML = XML(listLoader.data);
numImages = xmlData.pix.length(); //aantal images
//shuffelen maar, resultaat in arrShuffled
//var arrShuffled:Array = shuffleList(numImages);
var stImage:String;
for (var i=0; i<numImages; i++) {
//stImage = xmlData.pix[arrShuffled*].toString();
stImage = xmlData.pix*.toString();
trace (stImagedir+stImage);
arrPicLoaders* = new Loader();
arrPicLoaders*.contentLoaderInfo.addEventListener(Event.COMPLETE, makePictureList);
arrPicLoaders*.load( new URLRequest(stImagedir+stImage) );
}
listLoader.removeEventListener(Event.COMPLETE, makePictureLoader);
}
private function makePictureList(e:Event):void {
trace("function: makePictureList");
//vul het bitmap object en stel de properties in
var thisBmp:Bitmap = Bitmap(e.target.content);
var thisWidth:Number = thisBmp.width;
var thisHeight:Number = thisBmp.height;
thisBmp.scaleX = pWidth/thisWidth;
thisBmp.scaleY = pHeight/thisHeight;
//voeg bitmap to aan array
arrPicList.push(thisBmp);
}
private function showPictureList():void {
trace("function: showPictureList");
var container1:DisplayObject;
var nNextheight:Number = 0;
//lees array
for (var i=0; i<arrPicList.length; i++) {
//maak rijen van 6 plaatjes
if (i%6==0) nNextheight += pHeight;
arrPicList*.x = pWidth*Math.floor(i%6); //pWidth*Math.floor(i/2);
arrPicList*.y = nNextheight-pHeight;
addChild(arrPicList*); //laat maar zien
}
}
}
}
In my fla file I instantiate the class. At that point an XML file is read and from that file images are being loaded into Bitmap objects and then gathered in an array.
After instantiating I call the method showPictureList.
var grid:ThumbGrid = new ThumbGrid();
grid.showPictureList();
If I test the fla file I get the following error:
[COLOR=red]1180: Call to a possibly undefined method addChild.[/COLOR]
What am I doing wrong?
thx. Arjo