9 Replies Latest reply: Nov 8, 2012 7:06 PM by Ned Murphy RSS

    Var doesn't work if I load external swf.

    nikolaig Community Member

      I have a set up with two pages or labeled sections on the main timeline. I brake the code corresponding to actions happening in each page/labeled section. On first page there is a var specified for each button

      var sourceVar:String;

      Then each button uses this var to load a video into FLV player (player itself is constructed in the second page/labeled section).

      function JTV_SatelliteCenterpiece_PlayVideoPopUp(event:MouseEvent): void {

          sourceVar="howto_popups/jtvs18w12_LG30.flv";

          gotoAndPlay("flv_pb");

      }

      where "flv_pb" is the label for the second page/labeled section. On this second page/labeled section there is an FLVPlayback component named "SWF_flv2" which uses this var

      SWF_flv2.source = sourceVar;

       

      All above works. My problem is that I decided to load externally all the items (image buttons) into the first section. So I saved them as an external SWF file, with all the code in that external swf file.

      Then I link the buttons to section "flv_pb" this way:

      function JTV_SatelliteCenterpiece_PlayVideoPopUp(event:MouseEvent): void {

          MovieClip(parent.parent.parent).sourceVar="howto_popups/jtvs18w07_LG30.flv";

          MovieClip(parent.parent.parent).gotoAndPlay("flv_pb");

      }

      The link to the "flv_pb" section works, which tells me that the set up with "MovieClip(parent.parent.parent)." is appropriate.

      However the code as before with the set up of (still being in the external swf file):

          sourceVar="howto_popups/jtvs18w12_LG30.flv";

          gotoAndPlay("flv_pb");

      works as well, I am not sure why?

       

      The problem seems to be in the var

      I have an error message 1120: Access of undefined property sourceVar

      It is referencing the code in the second page/labeled section "flv_pb"

      SWF_flv2.source = sourceVar;

       

      What are my actions?  I kept the code in the external swf file. Should I move it to the main timeline if it is possible? Should I only reference the var in the main time line?

      Should all the code be kept in the beginning of the time line, rather be sectioned into the sections?

        • 1. Re: Var doesn't work if I load external swf.
          Ned Murphy CommunityMVP

          The way you say you have redone things, you should still be declaring the sourceVar in the main timeline of the main file as you originally had it so that it is available to both sections of the main file.  Your loaded swf is already targeting it there.

           

          There are a variety of ways you could approach the design, so it's up to you in that respect.  You could have the main file deal with all the code and target the loaded swf to assign whatever interactions are required of it.

          • 2. Re: Var doesn't work if I load external swf.
            nikolaig Community Member

            Thank you for your reply.

            Please let me know if all the animation code should be left in the external SWF file (which is being loaded) and all the linkage code on the main time line?

            If so then the code block specifying the link and loading on the botton:

            var sourceVar:String;

             

            //JTV_SatelliteCenterpiece_btn////////////////////////////////////////////////////

            //event listener//

            howTo_mainInfo.JTVs.JTV_SatelliteCenterpiece_btn.addEventListener(MouseEvent.CLICK, JTV_SatelliteCenterpiece_PlayVideoPopUp);

             

            function JTV_SatelliteCenterpiece_PlayVideoPopUp(event:MouseEvent): void {

                //MovieClip(parent.parent.parent).sourceVar="howto_popups/jtvs18w07_LG30.flv";

                sourceVar="howto_popups/jtvs18w07_LG30.flv";

                gotoAndPlay("flv_pb");

            }

            Should be left as it is on the main time line or only the function part and event listener put in the external SWF file?

            I tried this way puttin the var and function on the main time line and it brings me to the proper page/labeled section but doesn't load the video.

            In the OUTPUT Panel I have an error message:

             

             

            VideoError: 1000: Unable to make connection to server or to find FLV on server

                at fl.video::VideoPlayer/stop()

                at fl.video::FLVPlayback/stop()

                at acolyte46_howTo_Loader_fla::mainsite_mc_2/stopF2()[acolyte46_howTo_Loader_fla.mainsite_mc _2::frame283:49]

                at flash.display::MovieClip/gotoAndPlay()

                at acolyte46_howTo_Loader_fla::mainsite_mc_2/onClick_closeXhowToVideos_btn()[acolyte46_howTo _Loader_fla.mainsite_mc_2::frame283:28]

             

            Frame 283 is "flv_pb" page/labeled section to where the links properly works but video is not being loaded?

            Same code perfectly worked without any error message before I moved things into an external SWF file.

             

            __________________________________________________________________________________________ ____________________________________

             

            I am also confused why both ways are working out of the loaded SWF file:

                MovieClip(parent.parent.parent).sourceVar="howto_popups/jtvs18w07_LG30.flv";

            and

                sourceVar="howto_popups/jtvs18w07_LG30.flv";

             

            shouldn't only one be the correct one?


            • 3. Re: Var doesn't work if I load external swf.
              Ned Murphy CommunityMVP

              If things that worked previosuly are no longer working then it is likely you are just confusing the design as you keep shifting things around.

               

              For you own peace of mind, why don't you keep all of the code in the main file.  Just load the external file and after it is loaded, assign the code to whatever elements it needs from the main file.  If the loaded swf only has buttons that need to be clicked, then you can add the event listeners to those buttons from the main file after the swf has finished loading.  This will get you back closer to the orginal coding which you indicate worked properly.

              • 4. Re: Var doesn't work if I load external swf.
                nikolaig Community Member

                If my code on the main time line was

                howTo_mainInfo.JTVs.JTV_SatelliteCenterpiece_btn.addEventListener(Mous eEvent.CLICK, JTV_SatelliteCenterpiece_PlayVideoPopUp);

                 

                function JTV_SatelliteCenterpiece_PlayVideoPopUp(event:MouseEvent): void {

                    //MovieClip(parent.parent.parent).sourceVar="howto_popups/jtvs18w07_L G30.flv";

                    sourceVar="howto_popups/jtvs18w07_LG30.flv";

                    gotoAndPlay("flv_pb");

                }

                How I would access the elements if they were moved into the externally loaded SWF file. The file is named "howTo2_Q90imgs_Loader.swf"

                and being loaded through the greensock's SWF loader this way:

                loader_howToLoader = new SWFLoader("supporting files/building blocks/updated/howTo2_Q90imgs_Loader.swf",

                 

                could you give me a sample code to access those elements from the main timeline?

                • 5. Re: Var doesn't work if I load external swf.
                  Ned Murphy CommunityMVP

                  You'll need to look into the properties of the SWFLoader class to see how to target the loaded content.  I have not worked with that class so I'd be doing the same research you need to do to find out how to target the loaded item.  It might have a property named "content" if it resembles the AS3 Loader in any way, which is what you would use to target the swf for the AS3 Loader class.

                  • 6. Re: Var doesn't work if I load external swf.
                    nikolaig Community Member

                    Could you give me a code example if I were to use AS3 Loader (UILoader) I will try that and see if I can modify the code to greensock platform?

                    • 7. Re: Var doesn't work if I load external swf.
                      Ned Murphy CommunityMVP

                      If you want to use the UILoader component, then its "content" property is what points to the swf file that you load into it. 

                      • 8. Re: Var doesn't work if I load external swf.
                        nikolaig Community Member

                        Thanks, this method I know.

                        • 9. Re: Var doesn't work if I load external swf.
                          Ned Murphy CommunityMVP

                          You're welcome