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:
Within the
ModulePrefs
node of the gadget spec file, add aRequire
element to enable the JavaScriptflash
library.Include:
<Require feature="flash"/>
When you wish to insert a new Flash movie into your gadget, call the
embedFlash()
method of thegadgets.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
<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>
Note
The full code for this sample is available at https://github.com/jcleblanc/programming-social-applications/blob/master/chapter_4/inserting_flash_in_gadget.xml.
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.
Get Programming Social Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.