1

I try to add a MovieClip with every loop.

But my script overwrite every MC except for the last one.

I have to use AS2

var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("config.xml");
myXML.onLoad = function(success){

    if (success){
        var images = myXML.firstChild.childNodes;

        for (i = 0; i <  images.length; i++) {
            var imageNumber = i+1;
            var imageValue = images[i].firstChild.nodeValue;
            var imageName = "image"+imageNumber;
            trace(imageName);

            _root.createEmptyMovieClip(imageName, this.getNextHighestDepth());

            trace(imageNumber+": "+imageName + i);

            imageName.loadMovie(imageValue);

            imageName.width=500;
            imageName.height=500;

            _root.imageName.loadMovie(imageValue);


        } // for loop
    } // if success
    trace("________________");
    trace("1: "+image1);
    trace("2: "+image2);    
    trace("3: "+image3);
}

If I trace the MCs in the Loop it works. The MCs are on the stage. BUT if I trace Clips outside the loop only the last MC are on the stage. All others are undefined.

1 Answers1

0

i am guessing that the pitfall is using "this" inside onLoad function. if you try tracing "this" inside the loader you will see that it will not be what yo uexpect. the loader acts differently than the regular code on the frame.

i think the error happens here:

_root.createEmptyMovieClip(imageName, this.getNextHighestDepth());

where this.getNextHighestDepth() gives you a constant height, as in this case "this" always refers to the same object, and the new movieclips keep replacing the old ones on the same movieclip height. use _root.getNextHighestDepth() instead.

if you really want to use 'this' in the onLoad function, then assign it to some variable on the same frame but not inside the onLoad event. for example like this:

handle=this;
myXML.onLoad = function(success){
  trace(handle); //what you expect
  trace(this); //not what you expect
}
user151496
  • 1,849
  • 24
  • 38