public
Description: Rails plugin: treat your Adobe Flash swf files like any other asset (images, javascripts, etc...) and embed them using SWFObject 2.2
Homepage:
Clone URL: git://github.com/marcandre/swf_fu.git
Click here to lend your support to: swf_fu and make a donation at www.pledgie.com !
marcandre (author)
Sat Jun 20 15:10:36 -0700 2009
commit  8401a39f90bc3e767c1279be7c5a60a9eb9841e1
tree    99e2ab0a6756d67964b6ba93a6b689a7b53c9a9a
parent  cf5a589756e964d1368cdf185dcdf13e8f3fe167
swf_fu /
name age message
file CHANGELOG.rdoc Sat Jun 20 15:10:36 -0700 2009 Updated to SWFObject v2.2 Change should not be... [marcandre]
file LICENSE Thu Dec 25 12:07:46 -0800 2008 Initial commit [marcandre]
file README.rdoc Sat Jun 20 15:10:36 -0700 2009 Updated to SWFObject v2.2 Change should not be... [marcandre]
file Rakefile Wed Jan 14 18:47:54 -0800 2009 v1.2.0, with better handling of flashvars (see ... [marcandre]
directory assets/ Sat Jun 20 15:10:36 -0700 2009 Updated to SWFObject v2.2 Change should not be... [marcandre]
file init.rb Fri Jan 02 15:52:58 -0800 2009 File reorganization. Fixed small bug with defau... [marcandre]
file install.rb Thu Dec 25 23:22:52 -0800 2008 Fixed installer [marcandre]
directory lib/ Sat Jun 20 15:10:36 -0700 2009 Updated to SWFObject v2.2 Change should not be... [marcandre]
directory test/ Sun May 24 15:09:06 -0700 2009 Doc update [marcandre]
file uninstall.rb Thu Dec 25 23:22:52 -0800 2008 Fixed installer [marcandre]
README.rdoc

swf_fu

With the swf_fu plugin, rails treats your swf files like any other asset (images, javascripts, etc…).

swf_fu (pronounced "swif-fu", bonus joke for french speakers) uses SWFObject 2.2 to embed swf objects in HTML and supports all its options. SWFObject 2 is such a nice library that Adobe now uses it as the official way to embed swf! SWFOBject’s project can be found at code.google.com/p/swfobject

swf_fu was inspired by FlashObject by Davide D’Agostino (www.lipsiasoft.com) and is and backward compatible with it (or can also be used together; see compatiblity notes at the end)

swf_fu has been tested with rails up to v2.3.2 and has good test coverage so rake test:plugins should reveal any incompatibility. Comments and pull requests welcome: github.com/marcandre/swf_fu

Install

If you are running a version of rails more recent than 2.0.2 and that you have git installed (check with <q>git version</q>) then:

  script/plugin install git://github.com/marcandre/swf_fu.git

Otherwise, this won’t work; you’ll can always download swf_fu from github.com/marcandre/swf_fu and then install it manually, like:

  script/plugin install ~/Downloads/swf_fu

Usage

Embedding in HTML

To embed a swf file, use swf_tag:

  <%= swf_tag "i_like_flashing" %>

Exactly like images and javascripts, swf_tag will use swf_path to determine the path of the swf file; it will assume it is in /public/swfs/ unless specified otherwise and it will add the ".swf" extension automatically.

You can specify alternate content either with the options :alt => "Get Flash!" or you can use swf_tag as a block:

  <% swf_tag "i_like_flashing" do %>
    Get Flash
  <% end %>

Options

  • :id - the DOM id of the flash object element that is used to contain the Flash object; defaults to the name of the swf in source
  • :width, :height - the width & height of the Flash object. Defaults to "100%". These could also specified using :size
  • :size - the size of the Flash object, in the form "400x300".
  • :mode - Either :dynamic (default) or :static. Refer to SWFObject’s doc
  • :flashvars - a Hash of variables that are passed to the swf. Can also be a string like "foo=bar&hello=world". Defaults to {:id => the DOM id}
  • :parameters - a Hash of configuration parameters for the swf. See Adobe’s doc
  • :alt - HTML text that is displayed when the Flash player is not available. Defaults to a "Get Flash" image pointing to Adobe Flash’s installation page. This can also be specified as a block (see embedding section)
  • :flash_version - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
  • :auto_install - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by swf_fu)
  • :javascript_class - specify a javascript class (e.g. "MyFlash") for your flash object. If it exists, the initialize method will be called.
  • :initialize - arguments to pass to the initialization method of your javascript class.
  • :div_id - the DOM id of the containing div itself. Defaults to "#{option[:id]}"_div
  • :switch_off_auto_hide_show - switch off SWFObject’s default hide/show behavior. SWFObject temporarily hides your SWF or alternative content until the library has decided which content to display. Defaults to nil.

You can override these default options with a global setting:

  ActionView::Base.swf_default_options = {:mode => :static}   # All swf_tag will use the static mode by default

Javascript

swf_fu will add ‘swfobject’ to the list of default javascript files. If you don’t include the default javascripts, a simple javascript_include "swfobject" is needed.

swf_path

swf_tag implements and relies on swf_path which behaves in a similar fashion to image_path, javascript_path, etc…:

  swf_path("example")                            => /swfs/example.swf
  swf_path("example.swf")                        => /swfs/example.swf
  swf_path("fonts/optima")                       => /swfs/fonts/optima.swf
  swf_path("/fonts/optima")                      => /fonts/optima.swf
  swf_path("http://www.example.com/game.swf")    => http://www.example.com/game.swf

It takes into account the global setting asset_host, like any other asset:

  ActionController::Base.asset_host = "http://assets.example.com"
  image_path("logo.jpg")                         => http://assets.example.com/images/logo.jpg
  swf_path("fonts/optima")                       => http://assets.example.com/swfs/fonts/optima.swf

Compatibility with FlashObject

If you _don’t_ currently use FlashObject, congrats, you’re done reading!

If you do use FlashObject, you can choose to:

1) keep both. They won’t interfere and flashobject_tag will continue to use the older SWFObject 1.5 library.

2) remove FlashObject:

  script/plugin remove flashobject_helper

You can also manually remove javascripts/flashobject.js

swf_fu will take over the flashobject_tag and will use the new SWFObject 2.2 library. This should not have impacts as long as:

  • your swf path is absolute (e.g. "/path/to/my_flash.swf"). If it is relative, move your swf file from ‘public/’ to the new ‘public/swfs/’ asset folder
  • you include the default javascripts (otherwise you need to include ‘swfobject’ explicitely and stop including ‘flashobject’)
  • you don’t use the javascript object before the page is loaded. SWFObject 2.2 makes the changes to the web page later
  • you don’t rely on the verify_file_exists option (it doesn’t do anything anymore)

In either case 1 or 2, you change existing calls to flashobject_tag for swf_tag at your leisure. The interface is similar and the main differences are some options name changes:

  :flash_id  => :id
  :variables => :flashvars
  :background_color => options[:parameters][:bgcolor]

Moreover, the following defaults are gone:

  :flashvars[:lzproxied]
  :parameters[:scale]
  :parameters[:bgcolor]

Copyright © 2008 Marc-AndrĂ© Lafortune, released under the BSD license