# How reference an array created in a loadXML within a listener?

**URL:** <https://forum.kirupa.com/t/how-reference-an-array-created-in-a-loadxml-within-a-listener/253137>\
**Category:** flash\
**Created:** [February 27, 2008, 4:00pm UTC](https://forum.kirupa.com/t/how-reference-an-array-created-in-a-loadxml-within-a-listener/253137 "2008-02-27T16:00:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bentman](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@bentman](https://forum.kirupa.com/u/bentman)\
**Post date:** [February 27, 2008, 4:00pm UTC](https://forum.kirupa.com/t/how-reference-an-array-created-in-a-loadxml-within-a-listener/253137/1 "2008-02-27T16:00:26Z")

</div>

Hi,

New to AS.

I’m trying to integrate [this grid thumbnail gallery code](http://www.kirupa.com/forum/showthread.php?t=196734)with a full display.

I’m using CS3; code was originally intended for 8. Not sure if that’s relevant to my problem or not, but…:

I keep getting an error when I try to load the image from the image[] array within the tlistener.onLoadInit function. It comes back undefined, whether I use [variablename] or [#].

I’m guessing I need to reference the array differently because it’s in a function? I’ve tried a couple guesses like \_parent.image[p], but to no happy outcome.

“picture.loadMovie(‘media\Full’+k+’.jpg’, 1)” Works by building the path manually and just changing the number part of it with a variable, but isn’t proper, and also forces me to use a file naming convention rather than just passing the filename via XML.

I pasted the AS below, the part in question marked off by “//??!!??!!??!!??!!”.

Any suggestions appreciated!

Thanks in advance,

:)Ben

* * *

main\_menu.boton1.\_visible=false;  
main\_menu.boton2.\_visible=false;  
main\_menu.boton\_reset.\_visible=false;  
/////////////////////////////////////////////////////////////////////////////  
function loadXML(loaded) {  
if (loaded) {  
xmlNode = this.firstChild;  
thumbnails = [];  
image = [];  
title = [];  
description = [];  
\_global.total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {  
thumbnails\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;

// 1-!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??  
image\* = xmlNode.childNodes\*.childNodes[1].firstChild.nodeValue;  
//!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??

title\* = xmlNode.childNodes\*.childNodes[2].firstChild.nodeValue;  
description\* = xmlNode.childNodes\*.childNodes[3].firstChild.nodeValue;  
thumbnailer(i); trace(‘In loadXML - i=’+i+’–image\*=’+image\*);  
}  
firstImage(); //?need/wantt this here??  
} else {  
trace(“file not loaded!”);  
}  
}  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad =loadXML;  
xmlData.load(“images2.xml”);

//////////////////////////////////////////////////////////////////////////////////  
//////////////////////////////////// Load first  
//p = 0;  
//q=1;  
this.onEnterFrame = function() {  
//trace(‘enterframe’+q);  
filesize = picture.getBytesTotal();  
loaded = picture.getBytesLoaded();  
//q++;  
}; // nix, shortcircuit onEnterFrame?  
///////////////////////////////////////////////////////////////////////////////  
///////////////////////////////////load first image  
function firstImage() {  
if (loaded == filesize) {  
picture.\_alpha = 100;  
picture.loadMovie(image[0], 1);  
title\_txt.text = title[0];  
caption\_txt.text = description[0];  
picture\_num();  
}  
}

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

///////////////////////////////////////////////////////////////////////////////  
function thumbnailer(k){  
//trace(‘at beg thumbNailer: k=’+k+’- image[k]=’+image[k]);  
titleBGBar.\_alpha=50;

picXScale=100;  
picYScale=100;  
picX=260;  
picY=15;

titleBGBar.\_x=picX;  
titleBGBar.\_y=265;  
titleBGBar.\_width = 325 \* (picXScale/100);  
titleBGBar.\_height = 25;  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*used for altering demo. nix? incorporate?  
picXScale=120;  
picYScale=100;  
picX=200;  
picY=15;

titleBGBar.\_alpha=50;  
titleBGBar.\_x=picX;  
titleBGBar.\_y=266;  
titleBGBar.\_width = 325 \* (picXScale/100)+2 ;  
titleBGBar.\_height = 25;  
/\* \*/  
loaded\_counter=0;  
total\_thumbs = \_global.total;  
var container = thumbnail\_mc.createEmptyMovieClip(“th”+k,thumbnail\_mc.getNextHighestDepth());  
container.\_visible=false;  
container.\_alpha=0;  
var image = container.createEmptyMovieClip(“img”, container.getNextHighestDepth());  
tlistener = new Object();  
tlistener.onLoadInit = function(target\_mc) {  
// trace(‘target\_mc=’+target\_mc); // =‘s e.g. target\_mc=\_level0.main.thumbnail\_mc.th8.img  
// trace(‘k=’+k); //=‘s an integer 0 to totnum-1  
// trace(‘at begin onLoadInit: k=’+k+’- \_parent.image[k]=’+\_parent.image[k]);  
target\_mc.pictureValue = k;  
target\_mc.\_alpha =100; //BMTN - set so all are dim/bright unless hover. use with onHover  
target\_mc.onRelease = function() {  
p = this.pictureValue; // trace(‘p=’+p); trace(‘this.pictureValue=’+this.pictureValue); //='s integer 0 to …

// 2 - !!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??  
picture.loadMovie(image[5], 1); //??? image[] comes up undefined, with k, p, #, \_parent, this, etc. what am i missing?

picture.loadMovie(‘media\Full’+k+’.jpg’, 1); //Works, but isn’t proper… Also, forces use of file naming/numbering convention.

//!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??!!??

title\_txt.text = title[k];  
caption\_txt.text = description[k];  
picture.\_xscale=picXScale; //use for demoing different row/col numbers to adjust pics size  
picture.\_yscale=picYScale;  
picture.\_x=picX; //use for demoing different row/col numbers to adjust pics size  
picture.\_y=picY;  
title\_txt.\_x=picX;  
caption\_txt.\_x=picX;  
};  
target\_mc.onRollOver = function() {  
this.\_alpha = 50;  
};  
target\_mc.onRollOut = function() {  
this.\_alpha = 100;  
};  
loaded\_counter++;  
counting\_txt = loaded\_counter;  
if(loaded\_counter==total\_thumbs){  
main\_menu.boton1.\_visible=true;  
main\_menu.boton2.\_visible=true;  
grid\_maker\_01(); //BMTN – force it to lay out thumbs in grid  
}  
};  
image\_mcl = new MovieClipLoader();  
image\_mcl.addListener(tlistener);  
//orig: image\_mcl.loadClip(thumbnails[k], “thumbnail\_mc.th”+k+".img");  
image\_mcl.loadClip(thumbnails[k], “thumbnail\_mc.th”+k+".img");  
}

///////////////////////////////////////////////////////////////////////////////////////  
MovieClip.prototype.grid\_maker\_01=function(f){  
num=0;  
col=3; row=3; // Toggle with set in thumbNailer to switch setup  
//col=3; row=4;  
//col=2; row=4;  
scale=103;  
space=7;  
for (l=0;l\<col;l++){  
for (j=0;j\<row;j++){  
if(num\<\_global.total){  
with(eval(“this.thumbnail\_mc.th”+num)){  
\_x=((\_width+space)\*scale/100)\*l;  
\_y=((\_height+space)\*scale/100)\*j;  
\_xscale=\_yscale=scale;  
\_visible=true;  
}  
num++;  
}  
}  
}  
this.cascader();  
}  
//////////////////////////////////////////////////////////////////////////////////  
MovieClip.prototype.cascader=function(){  
inter=115;  
c=0;  
delayed\_fade=function(){  
if (c\<\_global.total){  
with(eval(“this.thumbnail\_mc.th”+c)){  
fadein();  
}  
c++;  
}else{  
main\_menu.boton\_reset.\_visible=true;  
clearInterval(delay);  
}  
}  
delay = setInterval(delayed\_fade, inter);  
}  
///////////////////////////////////////////////////////////////////////////////  
MovieClip.prototype.fadein=function(){  
this.onEnterFrame=function(){  
if (this.\_alpha\<100){  
this.\_alpha=this.\_alpha+5;  
}else{  
this.\_alpha=100;  
delete this.onEnterFrame;  
}  
}  
}  
///////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////  
function reset(){  
for(d=0;d\<\_global.total;d++){  
with(eval(“this.thumbnail\_mc.th”+d)){  
\_x=0;  
\_y=0;  
\_alpha=0;  
\_xscale=100;  
\_yscale=100;  
\_rotation=0;  
visible=false;  
}  
}  
}
