Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : how to return array from function I wrote


spookman
5/8/2004 6:57:20 PM
I have written a function that uses the split function. I want to return the
array from the split function from the function I wrote. When I do this, it
does not seem to return the array. Below, the loop after I call loadFileLIst
does not run because the array returned from my function is empty. But the
trace statement down in the loadFileList function displays the array contents
correctly. It appears that I cannot return the array from my loadFileLIst
function. the way I have written this. Any idea what is wrong?

flist = loadFileList( "image_3x5/files.txt" );
for( i = 0; i < flist.length; i++ )
trace( "XXX: " + flist[i] );

function loadFileList( fname ) {

// create an object to store the variables
varReceiver = new LoadVars();
// load the variables from the text file
varReceiver.load( fname );
//loadVariablesNum
("http://ekigroup.netfirms.com/cgi-bin/bnbform3.cgi",0,"POST");
// trigger something - when the variables finish loading
varReceiver.onLoad = function( success ) {
if( success )
{
for (var x in this) {
if (typeof this[x] == "string") {
name = strip_crlf( x );
//trace( name );
}
}
fileList = name.split( " " );

for( i = 0; i < fileList.length; i++ )
trace( fileList[i] );
}
}

return fileList;
}

Jack.
5/8/2004 7:25:49 PM
varReceiver.onLoad only fires when all external
data has loaded, it therefore traces your array content.

your first loop will never trace, as the data is still loading
when you call for it,

hth
AddThis Social Bookmark Button