Code snippets for symfony 1.x


Refine Tags

Snippets tagged "lightwindow"

LightWindow, SwfObject and Flash together

Hi, buddies!

It's my first snippet here, and, please, let me know if there's some bad or wrong code in your testings. Also, let me know if I make any mistakes about concepts here, or anything else. :-)

Well, this snippet is about how to get LightWindow, a wonderfull library, and Flash (I mean Adobe's) working together. This can be accomplished by using sfUFOPlugin as unobstrusive Flash content placement and ActionScript 2 inside the Flash animation, but I'll use sfSwfObjectHelperPlugin and ActionScript 3, which are my favorite ones. So, I'm assuming that you have these installed on your Symfony project:

and also knows how to program in ActionScript 3.

Now, let's start with the LightWindow portion of this snippet. If you are already using this plugin's helpers in the view, you don't need to do anything, since the library and CSS will be already loaded. If not, use the helper function, to load the resources, inside the view:

use_helper('LightWindow'); // load the LW helpers
_lwAddResources(); // load the LW resources (JS and CSS)

Alright, now the library is available for use by some JavaScript calls that we'll put inside our Flash project. But wait, there's a little catch here: I do not advise one to put a direct call to a LightWindow JS function as a command under an event listener, on Flash, because by the time the ActionScript is read in the compiled SWF the LW library may not be fully loaded; Instead of the direct call, I recommend you to create a simple JS function, right inside the view, that will delegate the call to the LW function, such as this:

echo javascript_tag('
function showWindowFromJS()
   myLightWindow.activateWindow({href: "path/to/my/image.extension"}); // auxiliary function to be called from inside ActionScript

The path can be assigned to a PHP variable, of course – normally I use $sf_request->getRelativeUrlRoot() to get to the root of the web folders, so that I can access my images easilly -. Also, read the API documentation on LW site to know more about the options to go inside the argument's object.

Now, how about some ActionScript? Let's say:

function showWindowFromFlash(event:MouseEvent):void
{'showWindowFromJS'); // using EI to communicate to the outside world
mMyLightWindowLauncher.buttonMode = true; // just to make the user sure that it's clickable.
mMyLightWindow.addEventListener(MouseEvent.CLICK, showWindowFromFlash); // assigning the function to the button event

We're almost there! Now, just load the Flash movie (SWF file) inside the view using sfSwfObjectHelperPlugin:

$id = 'flash_container_id'; // div to be replaced by Flash content.
$params = array( 'id'               => 'flash_object_id',
                 'movie'            => 'path/to/my/movie.swf'
                 'size'             => 'WIDTHxHEIGHT', // replace the dimensions here
                 'version'          => '9',
                 'background_color' => '#ffffff',
                 'params'           => array(
                   'allowScriptAccess' => 'sameDomain',
                   'wmode'             => 'transparent',
                   'quality'           => 'high' ),
                 'variables'        => array(
                   // a bunch of variables, can be an array with links to several images, just catch the vars inside the movie and use them passing as arguments in the ExternalInterface code.
                 'create_proxy'     => true );

That's it!

See you later, guys!

by Diogo Baeder on 2008-03-24, tagged ajax  flash  lightwindow  plugin  swfobject 
(1 comment)