O'Reilly logo

Programming Social Applications by Jonathan LeBlanc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inserting Flash Movies in Your Gadget

The JavaScript feature libraries also offer you the capability to embed a .swf Flash video into your gadget. Doing so allows you to quickly, and with minimal code, include a standards-compliant Flash movie.

To integrate this feature, you need to take the following steps:

  1. Within the ModulePrefs node of the gadget spec file, add a Require element to enable the JavaScript flash library.

    • Include: <Require feature="flash"/>

  2. When you wish to insert a new Flash movie into your gadget, call the embedFlash() method of the gadgets.flash object.

    • Method call: gadgets.flash.embedFlash(...);

The flash library also includes several methods under gadgets.flash for working with and displaying Flash movies, listed in Table 4-2.

Table 4-2. Methods included under gadgets.flash

Method

Description

embedFlash

Embeds a .swf Flash movie, loaded from a provided URL, into a specified DOM node within the gadget. Parameters include:

url (string)

A URL to a .swf flash movie

container (string)

The ID of the container in which to insert the Flash movie

params (object)

Returns true if successful; false if unsuccessful

embedCachedFlash

Embeds a cached Flash movie into the specified DOM node. Parameters and return type are the same as embedFlash.

getMajorVersion()

Returns the major version of the Flash player or 0 if not available.

<Module>
   <ModulePrefs>
      <Require feature="flash" />
   </ModulePrefs>
   <Content view="canvas">
      <![CDATA[
      <div id="insertFlash">Loading Flash Movie ...</div>

      <script type="text/javascript">
      if (gadgets.flash.getMajorVersion() === 0){
         //flash player not available
         var msg = "Flash player check failed - please download flash player";
         document.getElementById('insertFlash').innerHTML = msg;
      } else {
         //flash player available
         var flashURL =
            "http://developer.yahoo.com/yui/examples/swf/assets/SWFExampleSimple.swf";
         gadgets.flash.embedFlash(flashURL, "insertFlash", {
            swf_version: 9,
            id: "flashObj",
            width: 400,
            height: 350
         });
      }
      </script>
      ]]>
   </Content>
</Module>

In this example, we include the Require node to load the flash library for us to use. The Content section contains a default div node in which we will attempt to insert the Flash movie. We then check to see if Flash player is currently available on the user’s system. If not, we insert a “Please download Flash” message; if so, we embed a Flash movie into the div node.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required