4 Replies Latest reply on Sep 6, 2006 4:21 PM by ewon15

    Communicating between swf files

    ewon15 Level 1
      Okay here is my senario:

      I have two files, one is main.swf and the other one is sub.swf. sub.swf is an external swf that i loaded into main.swf on _level1. In the sub file I have a movie clip and when it is clicked on it needs to tell the main file (the host) what to do...how do i go about referring to the main.swf?

      any info would help!
        • 1. Re: Communicating between swf files
          Rothrock Level 5
          The main.swf (and the first swf no matter what it is called) into _level0. (That is a zero.) So if sub.swf needs to get something from main it would be like this.

          if(_level0.myVariable == "bonus"){}

          Or if you need to have to have a movie on the main timeline of main.swf play you would do.

          _level0.myInstance.play();

          And so forth.
          • 2. Re: Communicating between swf files
            ewon15 Level 1
            alright...but when i asked the movie clip in the sub swf file to do this:

            movieClip.onRelease = function (){
            _level0.myVariable.goDoThis();
            }

            it refers back to level 0 of the sub swf...not the main swf that it loads into...
            • 3. Re: Communicating between swf files
              Rothrock Level 5
              It shouldn't. If sub.swf is truly loaded into _level1 then it has no _level0, really this is correct!

              Are you sure you are loading into a _level and not onto a depth? Many folks mix the two up.

              If you are having a lot of trouble with this it is generally a good idea to set your current project aside for the moment and start with a fresh slate. I created two swf files.

              test1.swf has a blue square and code to load an external clip into _level1 the code is:

              loadMovieNum("test2.swf",1);

              test2.swf has a movieclip instance of a red circle and the following actionscript:

              myClip.onRelease=function(){
              _level0._alpha=50;
              }

              When test1.swf is run I see both my blue square and my red circle. When I click on the red circle only the blue square (the art work on _level0 from the original swf) is made 50 percent opaque. The red circle remains as it was.

              You might want to try a similar test, starting with something like I have and moving it toward what you are trying to achieve. I'm not sure I understand your

              _level0.myVariable.goDoThis()

              syntax. myVariable seems like a property and properties don't usually have methods so I don't quite get it. If myVariable is a variable defined in the sub.swf then maybe you need this:

              _level0[myVariable].goDoThis();

              ???
              • 4. Re: Communicating between swf files
                ewon15 Level 1
                you rock! thank you so much...i got it to work...on to my next item to fix :-)