4 Replies Latest reply on Jun 6, 2006 1:28 PM by g1r2e3g

    Passing variables between loaded clips

    g1r2e3g
      So i have one main swf, that dynamically loads in several copies of another swf.

      Within the Child movie there are buttons that call out to the HTML to various JavaScript functions, I need each instanct of the Child movie to have a unique ID variable set by the container film..

      Can someone show me a working version of the following as I cannot find anything that can pass a variable to the child.
        • 1. Re: Passing variables between loaded clips
          g1r2e3g Level 1
          maybe i didnt write that properly... what I mean is...

          i have several instances of one child movie containg the variable ' thisVar' , how can I apply a different value to each of the child movies??
          • 2. Re: Passing variables between loaded clips
            Level 7
            Not reliable to set variables in an external swf using loadMovie. The
            problem is that the load timing is dependent on the network and not the
            script. The loadMovie line does not pause the script until the external swf
            is loaded. Thus the next line looking for the external swf can and probably
            does execute before the movie is loaded.

            You want to look at MovieClipLoader Actionscript class as a technique for
            detecting when an external movie is loaded and ready for Actionscript.

            An overview appears at
            http://livedocs.macromedia.com/flash/8/main/00002538.html

            Probably the example for onLoadComplete is a good place to start:
            http://livedocs.macromedia.com/flash/8/main/00002543.html

            However if you want to start using before the entire movie is loaded, you
            can look ot onLoadInit also shown in the onLoadComplete example.

            In the onLoadComplete method you can have targe_mc.thisVar = 1;

            There are also other customized techniques using onEnterFrame and
            setInterval to monitor the presence of a loaded external swf that you can
            pursue.

            --
            Lon Hosford
            www.lonhosford.com
            Flash, Actionscript and Flash Media Server examples:
            http://flashexamples.hosfordusa.com
            May many happy bits flow your way!
            "g1r2e3g" <webforumsuser@macromedia.com> wrote in message
            news:e64iv5$mf3$1@forums.macromedia.com...
            So i have one main swf, that dynamically loads in several copies of another
            swf.

            Within the Child movie there are buttons that call out to the HTML to
            various
            JavaScript functions, I need each instanct of the Child movie to have a
            unique
            ID variable set by the container film..

            Can someone show me a working version of the following as I cannot find
            anything that can pass a variable to the child.


            _root.createEmptyMovieClip("child1",1);
            loadMovie("child.swf","child1");
            child1.thisVar = 1;

            _root.createEmptyMovieClip("child2",2);
            loadMovie("child.swf","child2");
            child2.thisVar = 2;


            • 3. Re: Passing variables between loaded clips
              Rothrock Level 5
              Most likely your problem is that you aren't waiting until "child.swf" has finished loading into child1. Any properties, code, variables attached to child1 will be replaced once the external file loads completely.

              You need a preloader to wait until the clip is completely loaded and then assign your ID. If you need help with that we can work it out.

              If you are publishing for Flash 7 or higher, I recommend using the MovieClipLoader class. You could then use the onLoadInit event to assign your ID.

              Of course I'm not understanding the need for a unique ID. If they all have unique names, e.g. child1, child2, etc., then that could be your unique ID. Just a thought!

              (PS why call it thisVar – a combination of two reserved words which is likely to cause confusion – when myID seems so much more sensible.)
              • 4. Re: Passing variables between loaded clips
                g1r2e3g Level 1
                I am pubilshing for flash 6. Also my variable wasn't actually caled thisVar, sorry about that. Also, calling it a unique ID may not have made sense..

                basically the child movie is a set of 24 buttons that represent time values (1 hour blocks) over a 24 hour period. This movie as I said is repeated many time as each new instance represents different activities that the user needs to specify as completed over the 24 hours.

                The flash is actually a replacement for an existing HTML form and for financial reasons the HTML is not being replaced completely by flash, therefore instead of the flash talking directly with the database via ASP or some other method I have it calling out to javascript functions that manipulate the HTML form which is now hidden with CSS.

                So in the child movie each of the buttons calls

                getURL("javascript:setCheckbox(" + _root.activityID + ",1);doSave();");

                How can I set the value activityID within each instance of the movie?