5 Replies Latest reply on Nov 19, 2009 6:48 AM by kglad

    Get content of dynamically loaded movieclip

    virusg_a_g

      Hey,

       

      After trying to no avail to get the totalframes of a dynamically loaded .swf in AS3 I've regressed to AS2.

       

      Now I can add the clip and get the totalframes of the content, no problem.

       

      THe problem is I cannot resize the content at all.
      I have no idea how to target the loaded content.

       

      Here's the code I'm using:

      var myXML:XML = new XML();
      var path:String;
      var mcl:MovieClipLoader = new MovieClipLoader();
      var mclm:MovieClipLoader = new MovieClipLoader();
      var mclL:Object = new Object();
      var frames:Number;
      var i:Number = 0;
      var mc:MovieClip = new MovieClip
      myXML.ignoreWhite=true;
      myXML.load("content.xml");
      
      holder_mc._alpha = 0;
      
      myXML.onLoad = function(xmlLoaded){
      menu();
      load();
      }
      
      
      
      mclL.onLoadComplete = function() {
                frames = (MovieClip(holder_mc)._totalframes);
                if (frames == 1) {
                     image();
                }
                else if (frames > 1) {
                     clip();
                }
           }
      
      load = function(){
           clearInterval(timer);
           path = myXML.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue;
           mcl.loadClip(path, holder_mc);
           var tFiles:Number = myXML.firstChild.childNodes.length;
           if (i < tFiles){
                i++;
           }
           else if (i == (tFiles)){
                i=0;
                load();
           }
           mcl.addListener(mclL);     
      }
      
      image = function() {     
           seconds=1000;
           holder_mc._alpha = 100;
           timer = setInterval(load, seconds);
      }
      
      clip = function() {     
           holder_mc._alpha = 100;
           ftimer = setInterval(checkFrames, 100);
      }
      
      checkFrames = function() {
                frame = (MovieClip(holder_mc)._currentframe);
                if (frame==(frames-1)){
                     clearInterval(ftimer);
                     load();
                }
           }
           
      menu = function(){
           
           var tFiles:Number = myXML.firstChild.childNodes.length;
           for (me=0; me < tFiles; me++){
           path = myXML.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue;
           i++;
           _root.attachMovie("circle", "circle"+me, me, {_x:(me*30), _y:330});
           mclm.loadClip(path, ("circle"+me));     
           }
           
      }
      

      I need to resize the content both for the main holder_mc as well as for the menu elements.

        • 1. Re: Get content of dynamically loaded movieclip
          kglad Adobe Community Professional & MVP

          :

           

          mclL.onLoadComplete = function(target:MovieClip) {
                    frames = target._totalframes;
                    if (frames == 1) {
                         image();
                    }
                    else if (frames > 1) {
                         clip();
                    }
          // size target here
               }

          1 person found this helpful
          • 2. Re: Get content of dynamically loaded movieclip
            virusg_a_g Level 1

            Thank you for the response.

             

            Unfortunately that didn't work.

             

            Even if I try to trace either target._width or holder_mc._width where you suggested I get 0 values.

             

            The only values I did manage to get was when I put the trace in the load() function but they were out of sync with the images being loaded.

             

            I even tried it on a simpler model:

            var myXML:XML = new XML();
            var path:String;
            var mcl:MovieClipLoader = new MovieClipLoader();
            var mclL:Object = new Object();
            var frames:Number;
            var i:Number = 0;
            var tFiles:Number;
            myXML.ignoreWhite=true;
            myXML.load("content.xml");
            
            myXML.onLoad = function(xmlLoaded){
            path = myXML.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue;
            tFiles = myXML.firstChild.childNodes.length;
            loader();
            }
            
            loader = function() {
                 mcl.loadClip(path, holder_mc);
                 mcl.addListener(mclL);
            }
            
            mclL.onLoadComplete = function(target:MovieClip) {
                 trace(target._width);
                 trace(holder_mc._height);
            }
            

            ..and I still get 0 values.

            • 3. Re: Get content of dynamically loaded movieclip
              kglad Adobe Community Professional & MVP

              use onLoadInit():

               

               

               

              mclL.onLoadInit = function(target:MovieClip) {
                        frames = target._totalframes;
                        if (frames == 1) {
                             image();
                        }
                        else if (frames > 1) {
                             clip();
                        }
              // size target here
                   }

              • 4. Re: Get content of dynamically loaded movieclip
                virusg_a_g Level 1

                That was it!

                 

                1000 Thank you!!!

                • 5. Re: Get content of dynamically loaded movieclip
                  kglad Adobe Community Professional & MVP

                  you're welcome.