3 Replies Latest reply on Feb 22, 2013 10:56 AM by ggaarde

    Can Javascript trigger an action in a swf file?

    ggaarde Level 1

      Earlier I was able to create flash buttons in a swf object in a widget on a Jive page, and have each of them trigger a separate Javascript function.

       

      That worked well.I used this in Flash:

       

       

      import flash.external.ExternalInterface;

       

       

      Now I would like to be able to do the opposite.

       

      I would like a Javascript function to trigger a swf to go to a particular frame in the movie.

       

      Is that possible, and if so, How do I do it?

       

      There are several widgets with each their own Flash object on the page. The Widgets can be adressed separtely by their H3 title.

       

       

      The reason for wanting to do this is to stop flash playback without unloading the swf with another movie in a different widget is started.

        • 1. Re: Can Javascript trigger an action in a swf file?
          Nabren Level 3

          You definitely can do this.

           

          You register it like this:

           

          ExternalInterface.addCallback("jsFunctionName", yourFunction);

           

          and call it like this from JS:

           

          document["flashcontent"].jsFunctionName();

          • 2. Re: Can Javascript trigger an action in a swf file?
            ggaarde Level 1

            Hi Nabren

            Thank you for your reply.

             

            If the flash is brought in via an iframe, is this still possible, and if so how do you reach the swf content?

             

            ggaarde

            • 3. Re: Can Javascript trigger an action in a swf file?
              ggaarde Level 1

              Hi Nabren

               

              Let me explain a bit more in detail what I am doing:

               

              The page includes several HTML widgets, let us say they are called:

               

              widget_1  importing flash_file_1.swf

              widget_2  importing flash_file_1.swf

              widget_3  importing flash_file_1.swf

              widget_4  importing flash_file_1.swf

               

              My navigation is a widget with a separate swf file where the buttons trigger a Javascript function that hides or reveals the widgets I want to show below.

              All the widgets are loading on page load but only some of them are visible.

               

              The swfs are essentially flash files that have sub navigation buttons.

              lets say:

              button_1

              button_2

              button_3

              This is my  way to get multiple pages to be accessible in one widget.

              Clicking a button takes you to a different frame with a different page layout.

              Some of the pages contain Flash video which auto starts. (they are located each in their own movie clip)

               

              My objective is to be able to stop any video that might be running when clicking another button for another widget.

               

              Currently each swf is delivered in an iFrame that calls up a HTML page with the Flash object in it.

               

              This allows me to send the content of each iFrame to about:blank when clicking another button (essentially unloading the iframe content) and load it again on demand.

               

              This however causes the iFrame content to disappear for a moment and reload, which is not a very elegant user experience.

              It kills the benefit of the content  preloading.

               

               

              Therefor I would much rather be able to control the timeline in each individual swf from a add callback function in Javascript.

              The Flash object could be located directly in the HTML widget  if that would work better.

               

              That way I could say something like this:

               

               

              function f1(){

               

              onclick:

              widget_1  importing flash_file_1.swf :  go to and play frame 1

              widget_2  importing flash_file_2.swf :  go to and stop on frame 15.

              widget_3  importing flash_file_3.swf :  go to and stop on frame 10.

              widget_4  importing flash_file_4.swf :  go  to and stop on frame 20.

              }

               

              function f2(){

               

              onclick:

              widget_1  importing flash_file_1.swf :  go to and stop on frame 10.

              widget_2  importing flash_file_2.swf :  to and play frame 1

              widget_3  importing flash_file_3.swf :  to and stop on frame 10.

              widget_4  importing flash_file_4.swf :  to and stop on frame 20.

              }

               

              -and so on…

               

              This would be beautiful!  I would be able to keep the swfs loaded at all time and be ready to play as soon as the next button is clicked.

               

              Question 1:  Would I have to add any code to the flash files?

               

              Question 2:  Would you be able to help with the correct code/ syntax to make the javascript work?

               

               

              Thank you for your time!

               

              ggaarde