Trouble with scope and delegate,load XML

Hi All,

I’m sure this is a common error, and I’ve tried searching around for the answers, but after a whole day of unluck yesterday I’ve decided to post it on the forum.

I’m having a hard time with a scoping issue. I have a mc that is to load some XML. I want to grab the info from the XML, stick it in an array, and have the array be accessable in my class.

Simple right??!??!

Getting the XML and parsing it is no problem. I can’t get it to retain the correct scope and let the class variable reflect the results from the XML file.

I’ve read all the posts as well as kirupa and some other sites. I can’t seem to figure out what’s up with the delegate and why the scope is not working.

Please help I have been trying this all day long. Thanks!!!

Here it is in a class::

  import mx.utils.Delegate; 

dynamic class mc_random_img extends MovieClip{ 
    public var images:Array; 
    private var _xml:XML; 
    private var xml_source:String; 
     
     
    function mc_random_img(){ 
        images = new Array(); 
        xml_source = new String(); 
        _xml = new XML(); 
        _xml.ignoreWhite = true; 
        _xml.onLoad =Delegate.create(this, onLoadEvent); 
        _xml.load("random_img.php"); 
    } 

    function onLoadEvent(success:Boolean):Void{ 
        if (success) { 
            xml_page_node = xml_source =  _xml.childNodes[0]; 
            my_images = xml_page_node.childNodes; 
            for (var i=0; i<my_images.length; i++) { 
                rand_pic = my_images*; 
                rand_file =  rand_pic.attributes.thumb2; 
                trace(rand_file) //prints file OK 
                // add the value to the images array! 
                images.push(rand_file); 
            }     
            trace("IMAGES FINAL:" + images.length); // prints out the correct length 
        } else { 
                trace("xml NOT loaded ok"); 
        } 
    } 

     
    function get_images(){ 
        trace("get images" + images.length); // prints 0... 
        trace("get images" + xml_source); // prints undefined... 
         
    } 
     
     
     
}  
                          

… and I call it like this::

 test = new mc_random_img(); 
test.get_images();

Man it’s frustrating, if someone would be kind enough to explain what I’m missing I would really appreciate it. Thanks again and THANK YOU KIRUPA, your tutorials are excellent.

Frizzo