Function Scope Question

Hello people!

I am trying to advance in actionscript and i have a question…

I 've wrote this

function galleryFetcher() {

   galName = [];

 var galXml:XML = new XML();

 galXml.ignoreWhite = true;
 
 galXml.load("gallery.xml");
 
 galXml.onLoad = function(success:Boolean) {
     if(success) {
         
         var galleries = this.firstChild.childNodes;
         
         for(var i:Number = 0;i<galleries.length;i++) {
             
             var gallery = galleries*;
             
             galName.push(galleries*.attributes.name);
             
            
         }
         
         
         
         
     } 
     
     
     galleryButtons();
 }
 

}

function galleryButtons() {
    
    for(var k:Number = 0;k<galName.length;k++) {
        trace(k);
    }
    

}

galleryFetcher();

If i write

galName = [];

it works fine BUT if i write

var galName:Array = [];

it doesnt…Can anyone tell me why?

I think it is so simple and basic but i dont have the knowledge.

Thanks in advance!