3 Replies Latest reply on May 6, 2008 1:51 AM by Parthian

    How to control SWF Video using JavaScript?

    Parthian Level 1
      Hi,

      I'm developing a web page which will use Flash Videos. I need to control the video without using a typical skin. The current tool I'm using to convert my wmv to SWF FLV is Coffee Cup. A hex edit suggests this is a Version 8 SWF.

      I am trying to write some javascript to control which Frame is displayed. I have seen code such as movie.TGotoFrame(...); and movie.GotoFrame, movie.StopPlay() etc. Unfortunately I cannot seem to use these methods. Eventually I suspected that my SWF simply did not make these methods available and when I run my video in my web page a RightClick shows a Context Menu that has no Reverse, Forward, Back options. Other SWF videos do have these options (obviously). This seems to prove that nothing I could code would make the GotoFrame work (ie no Forward (by one frame) option in menu suggests it could never work from javascript).

      Some Questions

      Is there a tool to examine a SWF to see what methods are available to javascript control? (expose the API) and is there a setting required in the <object> setup to enable javascript interaction?

      Is there something about SWF V8 files that is the problem or is likely that the CoffeeCup Web Video Player can only make partially functioning SWF Videos?

      What is the difference between GotoFrame and TGotoFrame and have these perhaps been superceeded by something else (there is an Adobe page which suggests they are only available up to Version 5 (not sure if that means Version 5 of SWF files or Version 5 of the FlashPlayer - to add to my confusion).


      I'm not currently a Flash type developer and have no tools to speak off and don't know ActionScript. I'm thinking of heading in the Flash direction but not sure how to move forward.

      Cheers
      Stuart
        • 1. Re: How to control SWF Video using JavaScript?
          Level 7
          On Fri, 2 May 2008 17:52:33 +0000 (UTC), "Parthian"
          <webforumsuser@macromedia.com> wrote:

          > Is there a tool to examine a SWF to see what methods are available to
          >javascript control?

          You only can see if your SWF contains many frames or it is only
          one-frame SWF. Or do any similar investigations like if it contains an
          embedded video or not. You can use any tools like this
          http://home.flashdig.com to investigate SWF files.

          >(expose the API) and is there a setting required in the
          ><object> setup to enable javascript interaction?

          Yes, it is. It's "allowscript" parameter of the <object> tag.

          > Is there something about SWF V8 files that is the problem or is likely that
          >the CoffeeCup Web Video Player can only make partially functioning SWF Videos?

          Just look at your SWF with a tool like above, and you'll see if it
          works with an external FLV stream or has an embedded video. Also
          please take into account, that embedded video has a limited duration
          of 16000 frames only. FLV has no such limits.

          > What is the difference between GotoFrame and TGotoFrame

          It's in calling interface, AFAIR, but you can check it in the docs.

          > and have these perhaps
          >been superceeded by something else (there is an Adobe page which suggests they
          >are only available up to Version 5 (not sure if that means Version 5 of SWF
          >files or Version 5 of the FlashPlayer - to add to my confusion).

          Version 5 of SWF is equal to version 5 of FlashPlayer.

          Whatever would be supported or not, it is very easy to add a small
          script into the root timeline of your SWF file, which will control its
          playback, as you like. In general you don't need any special other
          "external" API functions, because you always can create your own using
          only two Flash player API functions GetVariable() and SetVariable(),
          which are definitely available in every Flash player version since 5.

          Just one little example: you told you need a "gotoframe()" function
          externally visible (I'm writing from my memory, so please check the
          syntax carefully).

          In your JavaScript:

          function SkipToFrame(nfr) {
          self.document.myflash.SetVariable("skip", nfr);
          }

          In your SWF's root timeline:

          _root.onEnterFrame = function() {
          if (this.skip >= 1) {
          // to prevent from possible multiple call
          var tmp = this.skip;
          this.skip = 0;
          // here is our action
          this.gotoAndStop(tmp);
          }
          }

          That's all, it should work. Of course, you can tell me that your movie
          already has an onEnterFrame() eventhandler at the root timeline.
          What's a problem? Just create an empty movieclip and add this script
          into its frame 1 (it maybe the only frame). But do not forget to
          change "this.xxxx" to "_root.xxxx" within such script.

          > I'm not currently a Flash type developer and have no tools to speak off and
          >don't know ActionScript. I'm thinking of heading in the Flash direction but not
          >sure how to move forward.

          You need to learn o move forward :)

          HTH!
          • 2. Re: How to control SWF Video using JavaScript?
            Parthian Level 1
            Thanks Alex,

            quote:

            You need to learn to move forward :)


            I have a Greek friend who when I asked him how he was getting on with his dissertation project stated "in Greece we have a saying - every start is different".

            In this case my start is to dip a toe in the Flash water and not get scalded.

            Anyhow,

            One clarification from the CoffeeCup forum helped me to understand that my SWF used an external FLV and that may explain why the rightclick context menu did not have the more movie specific Back, Forward etc. Sounds plausible. So assume external FLV.


            quote:

            it is very easy to add a small script into the root timeline of your SWF file


            A little hand holding here would be appreciated. I have downloaded the Flex SDK. Can I use this free tool to do what you suggest? Using MXML and ActionScript. If so, a little bit more info would help.

            quote:


            That's all, it should work. Of course, you can tell me that your movie
            already has an onEnterFrame() eventhandler at the root timeline.
            What's a problem? Just create an empty movieclip and add this script
            into its frame 1 (it maybe the only frame). But do not forget to
            change "this.xxxx" to "_root.xxxx" within such script.



            Hhhmmm. A bit stumped. I've had a look at the SWF using FlashDig. I noticed what appears to be Assembly Language (Push, Pops, Jumps etc) and presumably in amongst all of that may be an onEnterFrame. Perhaps linked to a DefineFunction2 node. Unfortunately the SWF is very large (60K) and there is no search/find tool so that makes finding functions a bit harder than expected. Struggling a little with the concept of _root and Level0 etc.
            I assume you are suggesting manually building a replacement SWF (empty movieclip?) if the onEventHandler happens to be used for something else. Presumably set/getVariables only interacts with this function so if it is 'booked' in my SWF I would be in a spot of bother with your suggested approach?


            I wonder if you are assuming I have some sort of Flash tool. Possibly like this one shown in this tutorial
            WebWasp Panorama tutorial

            Note. The panorama is actually close to what I eventually want to do except I intend to make a video of a scene by rotating clockwise by 360 degrees. Then add buttons onto the SWF (or DHTML) which communicates with the SWF to move forward or back through the video. Moving forward would be like a clockwise rotation and moving back would create anticlockwise rotation. This explains the need to GotoFrame (or similar). From that perspective I don't need to become a Flash guru (for now) and can't justify buying all the expensive flash tools for this one (apparently) simple task: Frame by Frame control of an external FLV via the SWF.

            Note. I've started using SWFObject. Might this library help?

            In summary.
            How do I add the onEnterFrame ActionScript sample (or something similar) into a SWF using only the Flex SDK command line tools or similar in order to control an external FLV?


            Cheers
            Stuart
            • 3. Re: How to control SWF Video using JavaScript?
              Parthian Level 1
              Does anyone have a link to a simple tutorial or similar that describes how a beginner who has no flash tools except the free Flex SDK can get into updating a SWF programmatically to add code as per the _root.onEnterFrame example in this thread?

              And what Flash tool is it that enables the building of SWF files with control of level0, root, timeline etc. such that the SWF can be built as required. Are there 3rd party tools that do this or does Adobe have a monopoly.

              Still trying to decide if Flash is the route to go.

              Cheers