5 Replies Latest reply on Oct 15, 2007 4:35 PM by ZakNinja

    accessing variables and functions between loaded external swfs?

    ZakNinja
      Using AS 3.0: Say I have a menu.swf that loads a content.swf below it using the following

      var newContent:Loader = new Loader();
      newContent.load(new URLRequest("fowContent.swf"));
      addChildAt(newContent,0);

      Now say I have a frame label in newContent that is an animation ending the display of that swf. Upon clicking of another menu button in menu.swf, can I access the content's ending sequence by:

      newContent.gotoAndPlay(newContent.endingSequence);

      Also can you use while loops in AS 3.0? I would like to have a boolean variable "ended" in the newContent that becomes true after the ending animation has played.



      while ( newContent.ended != true)
      {
      //wait
      }

      then have it run the function to load and display the new content.swf
        • 1. Re: accessing variables and functions between loaded external swfs?
          kglad Adobe Community Professional & MVP
          use the content property of your loader's contentloaderinfo property to access the main timeline in fowContent.swf. you'll need to cast it as a movieclip or the compiler will complain.
          • 2. Re: accessing variables and functions between loaded external swfs?
            ZakNinja Level 1
            quote:

            Originally posted by: kglad
            use the content property of your loader's contentloaderinfo property to access the main timeline in fowContent.swf. you'll need to cast it as a movieclip or the compiler will complain.


            that one went a little over my head. I think I get what you're saying in the first part, what does such a statement look like? also how would I cast it as a movieclip?
            • 3. Re: accessing variables and functions between loaded external swfs?
              kglad Adobe Community Professional & MVP
              :

              p.s. you can't use a for-loop and you can't use a while-loop to effect any time delays. they both execute from beginning to end before anything is updated on-stage and no other code can execute outside of those loops (unless called from within the loop).
              • 4. Re: accessing variables and functions between loaded external swfs?
                ZakNinja Level 1
                quote:

                Originally posted by: kglad
                :

                p.s. you can't use a for-loop and you can't use a while-loop to effect any time delays. they both execute from beginning to end before anything is updated on-stage and no other code can execute outside of those loops (unless called from within the loop).


                Thank you very much for the help.

                Would I need to declare a MovieClip variable before using that statement or does that automatically cast newContent as a movieclip and go to the frame?

                So in order to achieve the flow I'm looking for.

                I'll have this in the menu.swf looking for clicks. It will run a function in the content.swf that runs the ending sequence and receives a string variable which is a concatenation of the buttonclicked (which is also the filename of next content) and .swf. (can I cast the event.target.name into a string the same way you casted the other into a movieclip?)
                ---------------------------------------

                function buttonClick(event:MouseEvent):void //in the menu.swf
                {
                var nextFile:string = string(event.target.name) + ".swf";
                MovieClip(newContent.contentLoaderInfo.content).endSequence(nextFile)
                }
                fowContent.addEventListener(MouseEvent.CLICK, buttonClick);

                ----------------------------------
                In the content.swf I will have a public variable nextContent and the function that the menu.swf calls, which begins the ending sequence.

                public var nextContent:string;

                function endSequence(nextFile:string)
                {
                nextContent = nextFile;
                gotoAndPlay(endingSequence);
                }

                -------------------------------------------

                Then at the end of the movie sequence I could call this function that passes back the variable that was modified by the previous function and runs the loader.

                parent.loadNext(nextContent) //in the content.swf

                ------------------------

                function loadNext(nextContent:string) //function in menu.swf
                {
                newContent.load(new URLRequest(nextContent));
                addChildAt(newContent,0);
                }

                -----------------------------

                I'm sure theres a better way to do this, and I don't even know if this will work. But I'd like to make sure it makes sense before I try to implement it.
                • 5. Re: accessing variables and functions between loaded external swfs?
                  ZakNinja Level 1
                  I'm sorry my knowledge is about a week old. I bought a hands on training book and I'm just kind of winging it.