1 Reply Latest reply on Mar 30, 2007 2:46 PM by abeall

    Declaring MovieClipLoader Objects in loop

    Point Happy Level 1
      I'm trying to clean up my code. I have a varying number of MovieClipLoaders and related listeners.

      I wanted to make a general purpose loop to create them where I can call the function with a variable and instantiate both the MovieClipLoader and its listener.

      I'm starting with pretty typical MovieClipLoader code.

      var MCname = new MovieClipLoader();
      var MCListener = MCSlotname+"Listener";
      var MCListener:Object = new Object();
      MCSlotname.addListener(MCListener);
      //Load Files
      MCListener.onLoadComplete = function(MCSlotname:MovieClip) {
      _global.MCname.Loaded = true;
      };

      But if I try to put it into a function and pass a variable so that each call to the function will instantiate a different movieclip loader it seems I run into a problem.

      function MakeLoader(InstanceName){
      var MCname = new MovieClipLoader();
      }

      How do I use the value of the instanceName to provide a unique var name for the instancing of the new MovieClipLoader?

      Thanks.
        • 1. Re: Declaring MovieClipLoader Objects in loop
          abeall Level 3
          > var MCListener = MCSlotname+"Listener";
          > var MCListener:Object = new Object();

          That won't do what I imagine you want it to do. The first line gets overwritten by the second line.

          > How do I use the value of the instanceName to provide a unique var name for
          > the instancing of the new MovieClipLoader?

          There are a couple of different ways this could be approached. The most literal answer to your question I think would be:

          this['loader_'+instanceName] = new MovieClipLoader();

          So, say the instance name is "myClipOne", it would make:
          this.listener_myClipOne

          However, here are a couple other things to consider:
          1) A single MovieClipLoader can load multiple clips at once.
          2) Neither the MovieClipLoader nor the listener need to be assigned to a variable, or unique variable. They will function the same wether or not there is a reference to them in variable.