6 Replies Latest reply on May 25, 2010 6:56 AM by Roland684

    Using one .swf to control another .swf

    ActusxReus

      AS2

      Flash CS4

       

      Okay so here's my dilemma.

       

      I need to find a way to come up to a solution to this problem, I can't have a different solution - for difficult reasons, I'm stuck with this layout.

       

      I have one .swf file (call it Parent.swf) - and within this .swf file there are two other .swf files sitting next to each other. (cLeft.swf and cRight.swf)

       

       

      Now - again for reasons that are complicated to explain - the cLeft.swf plays through it's animations, and then stops at the end - but there are no buttons to replay it - and right-clicking is not an option.  So, I was wondering if there was code I could use in cRight.swf to target and replay cLeft.swf - understanding that at runtime - both of these are embedded within a larger parent .swf - as I named Parent.swf

       

       

       

       

      Alright - my fellow friends - help me out here.

       

      -R.J.

        • 1. Re: Using one .swf to control another .swf
          Ned Murphy Adobe Community Professional & MVP

          How are the swf files loaded into the main file?

          • 2. Re: Using one .swf to control another .swf
            ActusxReus Level 1

            They are hard coded right in - imported into the library of the main.

             

            I should - if I'm right - just be able to make a button on the rchild.swf with something like  button1.onrelease (){ _root.Lchild.gotoAndPlay(1);  }

             

            or whatever the syntax is, I'm just writing it off the top of my head, but you get the idea.

             

            Let me see if this works...?

            • 3. Re: Using one .swf to control another .swf
              ActusxReus Level 1

              And along with that this is another question I have...

               

              Is there a way for me to do a gotoAndPlay(); type function - but instead of using "frame numbers" I can use frame labels instead?

              • 4. Re: Using one .swf to control another .swf
                Ned Murphy Adobe Community Professional & MVP

                Importing swf files into the library is not the way to go.  When you import an swf into the library it loses any actionscript it contains.  You should either copy the timelines/contents of those swf files into movieclips in the main file or load the swf files dynamically.

                1 person found this helpful
                • 5. Re: Using one .swf to control another .swf
                  Ned Murphy Adobe Community Professional & MVP

                  Yes, you can use frame labels (in quotes--numbers, no quotes).  Just look up gotoAnd Play() in the help documentation if you need any information on its use.

                  1 person found this helpful
                  • 6. Re: Using one .swf to control another .swf
                    Roland684

                    I've used a similar situation. Not with 2 child movies, but just one, but the principle is the same. I load the swf dynamically.

                     

                    I solved it like this:

                     

                    In the parent swf I create a property of _level0 and fill it with a function I want the child to be able to call.

                    The parent can already call functions of the child, you need not do anything for that.

                     

                    I have 2 functions in both parent and child: quit and go.

                    go() in the parent is for the child to let the parent know it is done initialising and (optional) in the child for the parent to order the child to (re)start doing what it (the child) should do.

                    quit() in the child is for the parent to order the child to clean up it's stuff because it's going to be unloaded. (intervals, listeners, etc. have to be removed otherwise they will remain). quit() in the parent is for the child to tell the parent it want's to quit (the child can not unload itself, it has to ask the parent to do so)

                     

                    in parent.swf:

                    function killChild ()

                    {

                         destinationMovieClip.removeMovieClip();

                    }

                    function childHasBorn(firstWord)

                    {

                         trace("your babies first word is: "+firstWord);

                    }

                    _level0.quit=killChild;     // do not add ()

                    _level0.go=childHasBorn;

                     

                    var mcl:MovieClipLoader = new MovieClipLoader();

                    mcl.loadClip("http://.....swf", destinationMovieClip);

                     

                    in child.swf:

                    function quit()

                    {

                         // clean up

                    }

                    function go(here)

                    {

                         gotoAndPlay(here);

                    }

                     

                    From the child swf you can now call the functions of the parent like this:

                    _level0.quit();

                    _level0.go("dada");

                     

                    And from the parent you can call the childs functions like this:

                    destinationMovieClip.quit();

                    destinationMovieClip.go(684);