I was very pleasantly surprised to find that Appcelerator Titanium has the ability to embed Flash objects into a Titanium window.

For a normal web browser, before the browser can display a Flash object, the Flash player needs to be installed as a plugin on the computer first. Titanium, however, has got the Flash player included already, which means that when working with Flash, you never need worry about showing a message asking the user to install the plugin before they can view the site. It just always works.

There are two ways in which a Flash object can be embedded into a page. It can either be done with an <object> tag, or using the Javascript swfobject object.

Using the HTML tag:

   <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
         width="780" height="420">
      <param name="src" value="media/sample.swf" />
      <object type="application/x-shockwave-flash" data="media/sample.swf"
            width="780" height="420">
       </object>
   </object>

In the above example, the classid of the object must always be set to the value in the sample code. The movie parameter is also the only required parameter, and points to URL of the Flash object you want to display

Here is some sample code of including a Flash object using Javascript:

<script type="text/javascript" src="js/swfobject.js"></script>

   <p id="sampleFlash">Flash will go here</p>
   <script type="text/javascript">
      var flashvars = {
         var1: 'Hello World',
         anotherVar: '7'
      };

      swfobject.embedSWF(
         'media/sample.swf', // path to the widget
         'sampleFlash', //id of HTML element to replace
         '200', // width of the widget
         '200', // height of the widget
         '8', //Flash version
         null, //express install path - not needed since Flash installed
         flashvars, //Variables to pass to Flash object
         {scale: 'noscale', wmode: 'transparent'} //parameters to pass
      );
   </script>

The first thing to notice here is the the swfobject.js file, which can be obtained from the swfobject project site, needs to be included on the page, as this contains the necessary Javascript for the swfobject object.

Then you need to add an HTML element on the page which will be replaced by the Flash object.

Finally, we need to add the Javascript code to add the object to the page. We embed the Flash object with the swfobject.embedSWF() function.

Titanium also allows the Flash object to be either a local file or a remote file, thus using Flash in Titanium is pretty much limitless.

Visit the swfobject project site for more information on using the swfobject object.

Share