SWFObject: Javascript-based Flash Media Version Detection and embedding Module

Source: Internet
Author: User

Original article:SWFObject: Javascript Flash Player detection and embed script
Translation:Awflasher.com
Chinese address:Http://www.awflasher.com/flash/articles/swfobj.htm-Update to SWFObject 1.5 official document (Updated to 1.5 @ 070318)

SWFObject is an independent and agile JavaScript module used to insert Adobe Flash Media resources (*. swf files) in HTML. The JavaScript script in this module can automatically detect the support of Flash plug-ins by mainstream browsers on PCs and Mac machines. It makes inserting Flash Media resources as simple and secure as possible. In addition, it is very consistent with the search engine optimization principles. In addition, it can avoid non-standard tags such as object and embed in your HTML and XHTML, so as to conform to more standards.
(That is, the page is responded through text/html, rather than application/xhtml + xml)

Note:For legal reasons, FlashObject has been renamed to SWFObject. For details, seeHere.

Content Guide

  • New Features
  • Implementation Principle
  • SWFObject example
  • Apply ExpressInstall in SWFObject
  • Download
  • Unique Advantages
  • FAQs
New Features

Detailed update records can be found inSWFObject 1.5 blog postHere.

Implementation Principle

[For users eager to downloadClick here to directly view the JS Code]

SWFObject is very simple to use and only needs to containswfobject.jsThis js file can be embedded with Flash Media resources by inserting some simple JS code in the DOM. The following is a simple example:

<script type="text/javascript" src="swfobject.js"></script>  <div id="flashcontent">  This text is replaced by the Flash movie.</div><script type="text/javascript">   var so = new SWFObject("movie.swf", "mymovie", "200", "100", "7", "#336699");   so.write("flashcontent");</script>

Let's see how the code works.

<div id="flashcontent">[...]</div>

First, we need to reserve an HTML node for the SWF resource. All content in this HTML node will be replaced by Flash resources on the client. When Flash player is not installed on the client, the content will be displayed. This feature is essential for SEO and user experience.

var so = new SWFObject(swf, id, width, height, version, background-color
 [, quality, xiRedirectUrl, redirectUrl, detectKey]);

Create a new SWFObject instance and input the following parameters:

  • Swf-SWF file path
  • Id-the id value you allocated for this SWF file. It will be used to set the name attribute for the embed and object labels so that you can easily supportswliveconnectSuch as dynamically passing in Variables
  • Width-width
  • Height-height
  • Version-the version number required by Flash Player. It can be detailed with the main version number. Minor version number. For example:"6.0.65". Generally, you only need to input the main version. For example:"6".
  • Background-color-background color of Flash resources, in hexadecimal format

In addition, the following optional parameters are available:

  • Quality-image quality. The default value is"high".
  • XiRedirectUrl-see ExpressInstall
  • RedirectUrl-the target address that is automatically redirected after the player of the corresponding version is not installed
  • DetectKey-this is the variable to be searched in the url address when the detection is ignored. The default value is "detectflash ".
so.write("flashcontent");

Apply the Flash resource to the DOM and display it in the browser.

Details

SWFObject is very flexible. You can write other HTML parts in advance, and then add the Flash content. In this way, the user will not get nothing if the client does not have Flash. It can also ensure the keyword optimization for the search engine. You don't have to worry about the client as before.

SWFObject is compatible with various mainstream browsers, such as IE5, Netscape 5.5, Firefox, Mozilla, and Opera on PC. IE5.2, Safari, Firefox, Netscape 6/7, Mozilla, and Opera 7.5 + on Mac will be supported in later versions of various browsers.

SWFObject detects the Flash Player version from 3 to the latest version, and eliminates the trouble of "activating" in IE. Here we haveBackground.

SWFObject allows you to easily check version details. For example, if you need v.6.0 r65 (or 6, 0,) to process SWF resources, you can add the following code:

var so = new SWFObject("movie.swf", "mymovie", "200", "100", "6.0.65", "#336699");

SWFObject version detection can be manually ignored. If you do not want SWFObject to detect the version number in a specific environment, you only need to pass a parameter on the HTML page. SWFObject can capture this parameter and skip detection, directly writing Flash embedded code to the DOM. The variable name used to ignore version check is "detectflash". The following is an example:

<a href="mypage.html?detectflash=false">Bypass link</a>
SWFObject example

The examples we have come up with are all the most basic. Next we will list some other features, especially the frequently used behaviors of input parameters and variables.

A simple example of passing in Flash inline Parameters
<script type="text/javascript">   var so = new SWFObject("movie.swf", "mymovie", "200", "100%", "7", "#336699");   so.addParam("quality", "low");   so.addParam("wmode", "transparent");   so.addParam("salign", "t");   so.write("flashcontent");</script>

Here we can see the list of inline parameters supported by Flash:Full list of the current parameters and their possible values(Official adobe.com resources)

Input variables using the "Flashvars" parameter

Flash vars is the best practice for data input during Flash pre-loading. The syntax format is very similar to the GET variable string, for example:variable1=value1&variable2=value2&variable3=value3SWFObject helps you make this work clearer

<script type="text/javascript">   var so = new SWFObject("movie.swf", "mymovie", "200", "100", "7", "#336699");   so.addVariable("variable1", "value1");   so.addVariable("variable2", "value2");   so.addVariable("variable3", "value3");   so.write("flashcontent");</script>

These variables will be saved in_rootIn this MovieClip object.

SWFObject can also easily pass parameters directly from the URL into Flash. For example, you have a URL:http://www.example.com/page.html?variable1=value1&variable2=value2. UsegetQueryParamValue()You can easily obtain these parameters and pass them into Flash. For example:

<script type="text/javascript">   var so = new SWFObject("movie.swf", "mymovie", "200", "100", "7", "#336699");   so.addVariable("varia

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.