4 Replies Latest reply on Dec 8, 2011 6:49 AM by kglad

    How to call a function from child swf

    iawara

      Hi,

      here is a parent swf loads a child swf file and there is a button/movieclip in child swf e.g childBtn_mc, now whener i click this childbtn_mc in parent swf (as child swf is loaded in its parent swf) i want to through a function in parent swf.

       

      for ex.

       

      child swf AS:

       

      childBtn_mc.onRelease = childBtnClicked;

      function childBtnClicked(){

           trace("calling from child");

      }

       

      parent swf AS:

       

      loadMovie("child.swf");

      chilBtn_mc.onRelease = childBtnClickedUsingParent;

      function childBtnClickedUsingParent(){

           trace("calling from parent");

      }

       

      ::::::::::::

      after compling the file when i click on childBtn_mc it trace =>  calling from child

      and i want "calling from parent" trace

      Please help.

       

      Thanks.

        • 1. Re: How to call a function from child swf
          kglad Adobe Community Professional & MVP

           

          childBtn_mc on child.swf main timeline:

           

          childBtn_mc.onRelease = _parent.parentFunction;

           

          parent swf AS:

           

          target_movieclip.loadMovie("child.swf");

          function parentFunction(){

               trace("calling parent function from child movieclip");

          }

           

          1 person found this helpful
          • 2. Re: How to call a function from child swf
            iawara Level 1

            Thanks, i dont know but not working.. can i access the childmovieclip in parent swf i mean is thr any way to use "childBtn_mc.onRelease" event in parent swf ?

            • 3. Re: How to call a function from child swf
              iawara Level 1

              its DONE.. Thanks kglad

               

              in parent swf AS:

               

              _root.createEmptyMovieClip("page2MC",2);

              loadMovie("test2.swf","page2MC");

               

              page2MC.greenbtn.onRelease =parentFunction;

               

              function parentFunction(){

                             trace("calling parent function from child movieclip");

                        }

              :::::::::::

              in child AS:

              greenbtn.onRelease = _parent.parentFunction;

               

               

              Thanks.

              • 4. Re: How to call a function from child swf
                kglad Adobe Community Professional & MVP

                 

                in parent swf AS:

                 

                _root.createEmptyMovieClip("page2MC",2);

                 

                // this

                //loadMovie("test2.swf","page2MC");

                //should be:

                page2MC.loadMovie("test2.swf");

                 

                //<- this

                //page2MC.greenbtn.onRelease =parentFunction; 

                //does nothing

                 

                function parentFunction(){

                               trace("calling parent function from child movieclip");

                          }

                :::::::::::

                in child AS:

                greenbtn.onRelease = _parent.parentFunction;

                 

                // and you're left with exactly what i suggested.
                1 person found this helpful