YUI Library Home

YUI Library Examples: SWF Utility: Simple SWF Utility Example

SWF Utility: Simple SWF Utility Example

This is a simple example of the YUI SWF Utility's features.

Note: This example of the YUI SWF Utility usage requires Flash Player 9.0.115 or higher. The latest version of Flash Player is available at the Adobe Flash Player Download Center.

The version of the Flash player installed on your computer is outdated. Please download and install the newest version.

Simple SWF Utility Example

In this example, we demonstrate how to embed a SWF on a page and pass it some configuration parameters.

First, include the following JS source files:

1<!-- Dependencies --> 
2<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/yahoo-dom-event/yahoo-dom-event.js"></script> 
3<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/element/element-min.js"></script> 
4 
5<!-- Source files --> 
6<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/swf/swf-min.js"></script> 
view plain | print | ?

Next, create a container where the SWF will be placed. The size of the container will be the size of the SWF (in this case, we set it to 400 by 200 pixels). The current (HTML) content of the container is what will be displayed if there is no Flash installed on the user's machine, or if the version of the Flash player installed does not match the minimum required.

1<div id="swfContainer" style="width:400px;height:200px"
2  The version of the Flash player installed on your computer  
3  is outdated. Please download and install the latest version. 
4</div> 
view plain | print | ?

Now, create an object with the necessary parameters to pass to the SWF. In this case, we specify the minimum version of Flash player required, whether to use the ExpressInstall capability of the Flash player, and a few SWF-specific fixed attributes, namely the scale attribute (which specifies whether to shrink or stretch the Flash content to fit the viewport; in this case, no shrinking or stretching is allowed), and the salign attribute (which specifies how to align the content in the viewport; in this case, we align it to top left):

1var params = {version: 9.115, 
2              useExpressInstall: false
3              fixedAttributes: 
4              {scale: "noscale", salign: "TL"
5             }; 
view plain | print | ?

Finally, create an instance of the SWF, passing the name of the container in which to embed it, the URL of the SWF, and the parameter object created above:

1var newswf = new YAHOO.widget.SWF("swfContainer""assets/SWFExampleSimple.swf", params); 
view plain | print | ?

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

YUI Logger Output:

Logger Console

INFO 459ms (+459) 7:57:28 AM:

LogReader instance0

LogReader initialized

INFO 0ms (+0) 7:57:28 AM:

global

Logger initialized

More SWF Utility Resources:

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings