# Function and global variables

**URL:** <https://forum.kirupa.com/t/function-and-global-variables/46911>\
**Category:** Uncategorized\
**Created:** [March 29, 2004, 1:18pm UTC](https://forum.kirupa.com/t/function-and-global-variables/46911 "2004-03-29T13:18:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![icube](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@icube](https://forum.kirupa.com/u/icube)\
**Post date:** [March 29, 2004, 1:18pm UTC](https://forum.kirupa.com/t/function-and-global-variables/46911/1 "2004-03-29T13:18:37Z")

</div>

[AS]  
fileNamesLoadVars = new LoadVars();  
fileNamesLoadVars.load(“getFilesNames.txt”);  
fileNamesLoadVars.onLoad = function(){  
\_global.gFileNamesArray = this.fileNames.split("|");  
trace(\_global.gFileNamesArray.length); //which output successfully in output window as 7  
}

for(i=0; i\< \_global.gFileNamesArray.length; i++){  
//do something here

}  
[/AS]

ok… i’ve got problem with the actionscipt above… this AS is inside a movieclip at the first frame. i’ve declared \_global.gFileNamesArray = new Array(); in the main timeline(\_root), but the problem is my ‘for loop’ which it couldn’t get the global variable…

when i do a trace(\_global.gFileNamesArray.length) outside the loadvars.load function it gives me 0…

any suggestions y…? how do i use the loadvars.load function to manipulate a global variable…?

i’m rather new to actionscript btw…
