# Trouble with scope and delegate,load XML

**URL:** <https://forum.kirupa.com/t/trouble-with-scope-and-delegate-load-xml/218171>\
**Category:** flash\
**Created:** [March 5, 2007, 5:34pm UTC](https://forum.kirupa.com/t/trouble-with-scope-and-delegate-load-xml/218171 "2007-03-05T17:34:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![frizzo](https://avatars.discourse-cdn.com/v4/letter/f/9fc29f/32.png) [@frizzo](https://forum.kirupa.com/u/frizzo)\
**Post date:** [March 5, 2007, 5:34pm UTC](https://forum.kirupa.com/t/trouble-with-scope-and-delegate-load-xml/218171/1 "2007-03-05T17:34:32Z")

</div>

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::

```auto
  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::

```auto
 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
