About SWFObject 2
SWFObject 2 is a standards-based library that embeds SWF
files in HTML pages. It abstracts implementation details about Plugin
detection, embedding, and other features so that you only need to
call a single method to embed your SWF file. The default template
included with Flex SDK and Flash Builder embeds the SWFObject 2
functionality with the following <script> tag:
<script type="text/javascript" src="swfobject.js"></script>
To embed a SWF file built with Flex, the HTML wrapper creates
a number of properties and objects, and then passes them to the swfobject.embedSWF() method.
The embedSWF() method has the following signature: embedSWF(
swfUrlStr:String,
replaceElemIdStr:String,
heightStr:String,
widthStr:String,
swfVersionStr:String,
xiSwfUrlStr:String,
flashvars:Object,
params:Object,
attributes:Object
)
The following is an example of the embedSWF() method
in an HTML wrapper:
swfobject.embedSWF("TestProject.swf", "flashContent","100%", "100%", "10.0.0", "playerProductInstall.swf", flashvars, params, attributes);
You set the values of several of these arguments in the HTML
wrapper’s script prior to passing them to the embedSWF() method.
The following table describes these arguments.
Argument
|
Description
|
swfUrlStr
|
Defines the location of the application
built with Flex. In most cases, this is the name of the output SWF
file. If you use Flash Builder to generate a wrapper, the default
value is “project_name.swf”.
|
replaceElemIdStr
|
The name of the alternative content that
appears if Flash Player is not available.
You define the alternative
content in a <div> tag. For an example, view the
source of HTML wrapper that is generated by Flash Builder.
|
heightStr
|
The height of the application built with
Flex.
If you use Flash Builder to generate a wrapper, this
argument is the value of the {height} token.
|
widthStr
|
The width of the application built with
Flex.
If you use Flash Builder to generate a wrapper, this
argument is the value of the {width} token.
|
swfVersionStr
|
The minimum version of Flash Player that
is required to run the application built with Flex. The default
value is “10.0.0”. Set this property to “0” to disable version detection.
If
you use Flash Builder to generate a wrapper, this value is made
up of the {version_major}, {version_minor},
and {version_revision} tokens.
|
xiSwfUrlStr
|
Enables Express Install. Set this argument
to the location of the playerProductInstall.swf file. The default
value is “playerProductInstall.swf”. This SWF file is in the same
directory as the HTML wrapper. If you deploy it to another location,
change the value of the xiSwfUrlStr argument to
the new path.
To disable Express Install, set the value of
this argument to an empty string.
If you use Flash Builder
to generate a wrapper, this argument is the value of the {expressInstallSwf} token.
|
flashvars
|
Adds flashVars variables
to your template. To do this, attach dynamic properties to the flashvars
object in the HTML template.
The following example adds firstName and lastName as
dynamic properties to flashvars object: var flashvars = {};
flashvars.firstName = "Nick";
flashvars.lastName = "Danger";
For more information
about using flashVars variables in applications built
with Flex, see Passing request data with flashVars properties.
|
params
|
Sets parameters for the SWF object. These
properties typically define how it interacts with the HTML wrapper
or appears in the browser.
You can set the values of the following
properties by using the params argument: menu
quality
scale
salign
wmode
bgcolor
base
flashvars
devicefont
allowscriptaccess
seamlessstabbing
allowfullscreen
allownetworking
For
more information about these properties, see the property’s description
in About the object and embed tags.
The following example adds
several parameters to the params object in the
HTML wrapper: var params = {};
params.quality = "high";
params.bgcolor = "${bgcolor}";
params.allowscriptaccess = "sameDomain";
|
attributes
|
Sets attributes for the SWF object.
You
can set the values of the following properties with the attributes argument:
The id and name properties
are required.
For more information about these properties,
see the property’s description in About the object and embed tags.
The following example adds
the id, name, and align properties
to the attributes object. var attributes = {};
attributes.id = "${application}";
attributes.name = "${application}";
attributes.align = "middle";
|
For more information about using SWFObject 2, see: http://code.google.com/p/swfobject/wiki/documentation.
|
|