FlashHelper - a wrapper for the SwfObject js class
What it does
It gives you a oneliner to embed flash into your views as easy as the HtmlHelper::image lets you embed pictures. It does this using a javascript class called SwfObject [1]
Requirements
- This helper in ur /app/views/helpers folder (it's found on next page)
- The helper added to your controller's helpers property
- The javascript file in ur /app/webroot/js folder (found [2])
How to use it
The helper has only two public functions and one of them is optional.
init($options)
The optional init function has the job of linking the document to the required javascript,
but as long as the helper is able to use the layouts $scripts_for_layout, calling this method
multiple times is not a problem.
The other feature of this method is taking in options that subsequent calls of renderSwf
will use, ie for reusing a set of options for multiple flash embeds, set them here. Note, that if you
do not call this method, the renderSwf will.
renderSwf($swfFile,$width,$height,$divDomId,$options)
This is used once per flash file you wish to embed. Think of it as the flash equalent of $html->image. The parameters are pretty straight forward, but let me explain the few interesting aspects.
The first parameter is a string of the swf files name, relative to the webroot.
The width and height may be set through the options array of the init function, if you wish.
The divDomId parameter defaults to false, which will make the helper not look for an existing div, but render one at the place the helper is called. If you wish the helper to use a div of your choosing, supply the dom id.
Note : The div is replaced by the flash, make another wrapper div for styling
If you wish to have alternate content that is displayed if the flash may not be embedded or javascript is disabled, put that content in the div with the supplied dom id.
The options array is a nested array with 3 first level keys that it looks for;
- flashvars
- params
- attributes
The documentation for what valid keys and values these three accepts may be found at [3]
Examples
Download code
<div id="flashy"><p>No flash loaded</p></div>
<?php echo $flash->renderSwf('test.swf',400,200,'flashy');?>
Download code
<?php
$flash->init(array('width'=>200,'height'=>100));
echo $flash->renderSwf('test1.swf');
echo $flash->renderSwf('test12swf');
?>
Download code
<?php
echo $flash->renderSwf('fl_countdown_v3_3.swf?mo=1&da=24&snd=off&co=AA3333',800,250,false,array('params' => array('movie'=>'?mo=1&da=24&snd=off&co=AA3333')));
?>
Feedback
Please leave a comment or report any issue / improvements to me [4] and I will try to keep the helper updated
Comments
Comment
1 Awesome
Good job
Comment
2 Great !
A few days ago I read this Adobe article which is also about SWFObject: http://www.adobe.com/devnet/flashplayer/articles/alternative_content.html
SWFObject seems to be the best way to include flash in webpages, and is supposed to become a standard, according to another article from the same author, Bobby van der Sluis. See http://www.adobe.com/devnet/flashplayer/articles/swfobject.html
So thanks for Flash Helper!
P.S. : I was wondering if there is any place where we can follow future developments of Flash Helper (if any) and more precisely, know about its future releases?
I saw your page at http://code.google.com/p/alkemann/issues/entry but I was not able to browse the code. Am I wrong? Or maybe Flash Helper is in the Cakeforge (http://cakeforge.org/)]?
Comment
3 Re: Maxim
I have also set up a SVN now which you can get at http://code.google.com/p/alkemann/source/checkout
Comment
4 I belive your 3rd example is not accurate
View Template:
<?php
echo $flash->renderSwf('fl_countdown_v3_3.swf?mo=1&da=24&snd=off&co=AA3333',800,250,false, array('flashvars' => array('mo' => 1, 'da' => 24, 'snd' => off, 'co' => 'AA3333')));
?>
as opposed to this...
View Template:
<?php
echo $flash->renderSwf('fl_countdown_v3_3.swf?mo=1&da=24&snd=off&co=AA3333',800,250,false,array('params' => array('movie'=>'?mo=1&da=24&snd=off&co=AA3333')));
?>
Question
5 flash helper in js
How can I use flash helper to create an object which can be assigned to a javascript variable in my view?? I want to do dhtml.
Something like:
//inside my view on top of all html
var obj= 'renderSwf('veppa_photo_album2.swf?xml='+path+'gallery_x1.xml',600,400,false,array('params'=>array('movie'=>'veppa_photo_album2.swf?xml='+path+'gallery_x1.xml'))));?>';
& I can use this obj for dhtml. I hope i am clear. Thanks!!