12 Replies Latest reply: May 1, 2010 6:14 AM by Petteri_Paananen RSS

    frames to moviclips with as3?

    Petteri_Paananen Community Member

      Hi

       

      Is there any way to convert keyframes of externally loaded SWF to movieclip instances? I can´t use Flash for that,  it has to be done runtime....

       

      For instance

      -I load SWF with 6 keyframes (frames 1,2,3,4,5,6).

      -I would like to create dynamically 6 movieclips

      -and add them to stage right after SWF loading has completed...

       

      Any ideas?

        • 1. Re: frames to moviclips with as3?
          Petteri_Paananen Community Member

          I tried to solve that by loading same swf multiple times, then I used gotoAndStop-command to go to frame 2 with second instance, frame 3 with third instance an so on.... it works if I create all those loader deparately. But if I try to loop that loading process, I can´t find any way to move loaded SWF to any other frame than frame 1?

           

          I have following line of code, I load file SWFkoko.swf 4 times (I replace this later to dynamic value based on totalFrames):

           

          =============code starts ==============

          //start
          createPages();

           

          function createPages(){
          PageCont2.y = 0;
          PageCont2.x = 0;
          var il = 4;
          var xPos= 400;

           

          //loop for creating loaders side by side
          for (var i:uint=0; i<il; i++)
              {
              var container = new MovieClip();
              var loader:Loader = new Loader();
             
              container.name = "container"+i;
              loader.name = "loader"+i;
             
              this.addChild(container);
              PageCont2.addChild(loader);
             
              loader.x = xPos*i;

           

              loader.y = 100;
              loader.load(new URLRequest("SWFkoko.swf"));


              }

          //goto commands for moving instances to right frame - doesn´t work 
          loader1.content.gotoAndStop(currentFrame+1);
          loader2.content.gotoAndStop(currentFrame+2);
          loader3.content.gotoAndStop(currentFrame+3);

           

          }

           

          ============== code ends  ==============

           

          Script works nice until it should use goto... it will put all 4 loader instances side by side inside PageCont2, which is Library based moviclip...

          When I try to use those gotoAndStop commands, I get following warning:

           

          1120: Access of undefined property loader1.

          1120: Access of undefined property loader2.

          1120: Access of undefined property loader3.

          • 2. Re: frames to moviclips with as3?
            Ned Murphy CommunityMVP

            Two things.  You need to wait for the swf to load and be set up before you can attempt to command it to do anything.  So add an INIT event listener to the loader and deal with assigning the frame to goto in the event handler function for that listener.  The error messages are telling you something obvious... you are suddenly inventing loader1, loader2, loader3, etc...  You cannot just arbitrarily name things without having defined them.  You have only defined "loader"

            • 3. Re: frames to moviclips with as3?
              Petteri_Paananen Community Member

              Thanks for answering....

               

              ok... I understand the point..

               

              I tried following right after createPages-function...

               

              =========

              loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, magLoaded);
              loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, magLoaded);
              loader3.contentLoaderInfo.addEventListener(Event.COMPLETE, magLoaded);

               

              function magLoaded(e:Event){
                  trace("fired up");
                  }

              ==========

               

              It didn´t work... I got warning

               

              TypeError: Error #1010: A term is undefined and has no properties.
                  at xxxxxxx_fla::MainTimeline/frame1()

              • 4. Re: frames to moviclips with as3?
                Ned Murphy CommunityMVP

                My response remains the same.  You don't have a loader1, loader2, etc... you only have loader.  And as I also said, you want to use the INIT event, not the COMPLETE event.  The INIT event happens when the loaded swf is ready to be used.

                • 5. Re: frames to moviclips with as3?
                  Petteri_Paananen Community Member

                  I accidentaly used that COMPLETE... I tried it with INIT but it behaved same way....

                   

                  You said I don´t have loader1, loader2 etc.. should I instantiate them somehow inside the loop? Now my loop creates those names for the loaders.... but I guess it´s not enough? My problem is that I won´t know how many loaders there will be. In some cases there might just few, in another there might be 25... it depends on how many frames there will be in loaded SWF...

                  • 6. Re: frames to moviclips with as3?
                    Petteri_Paananen Community Member

                    Ok, I put my eventlistener inside the loop:

                     

                    loader.contentLoaderInfo.addEventListener(Event.INIT, magLoaded);

                     

                    Now it seems to fire up my magLoaded-function in every round of a loop... but I it still doesn´t recognize those loader1, loader2 etc instances....I guess I shouls present them somehow... inside the loop? or even outside createPages function?

                    • 7. Re: frames to moviclips with as3?
                      Ned Murphy CommunityMVP

                      You shouldn't need the numbered loaders.  What does your INIT event handler function look like?

                      • 8. Re: frames to moviclips with as3?
                        Petteri_Paananen Community Member

                        If I use it like this:

                         

                        function magLoaded(e:Event){
                        trace("Fires Up");
                            }

                         

                        it traces "Fires Up" 4 times as it should

                         

                        But if I try to test some actual gotoAndStop there, it stops working

                         

                        function magLoaded(e:Event){
                        loader.content.gotoAndStop(currentFrame+1);
                            }

                        • 9. Re: frames to moviclips with as3?
                          Ned Murphy CommunityMVP

                          Try using:

                           

                          function magLoaded(e:Event){
                               e.target.content.gotoAndStop(currentFrame+1);
                          }

                           

                          I doubt currentFrame+1 is what you want to use, but get it working as is first, then resolve how to update the frame value you intend.

                          • 10. Re: frames to moviclips with as3?
                            Petteri_Paananen Community Member

                            That did the trick... thanks!

                             

                            I still have a lot to do with goto commands. As you thougt, currentFrame+x is not my way to go.... I put there a numeric variable which value grows every round and I will use that as goto target...

                             

                            I still have a small problem with order of my loaded swfs, flash seems to give first frame to the loader that is ready first, and it´s not necesserely one which should be first... I have think about this little further... thanks anyway, this has been very helpful....

                            • 11. Re: frames to moviclips with as3?
                              Ned Murphy CommunityMVP

                              Although I'm not sure it would apply in your case if you are loading the same file for each loading, you could implement a sequential loading scheme rather than let a for loop manage the load requests.  I would think in your case that you could increment a value for whatever file happens to load whenever it gets there.  In case it is something you'd like to consider, a sequential approach relies primarily on 4 elements:

                              1) A storage device for the file names to be loaded (an array works well) ... but wouldn't apply in a one-file-loading case

                              2) A counter to control who's getting loaded when

                              3) A loading function who's sole purpose is to load the file in the array currently being poiinted at by the counter ( file[counter] )

                              4) A load complete function (INIT or COMPLETE event) that processes the loaded object, increments the counter, and calls the loading function again if the counter doesn't yet equal the array length

                              • 12. Re: frames to moviclips with as3?
                                Petteri_Paananen Community Member

                                Thanks, I´ll check out that option too... it sounds good...