swfobject 转载
What is SWFObject?SWFObject 2:
Why should you use SWFObject?SWFObject 2:
The A List Apart article Flash Embedding Cage Match describes the full rationale behind SWFObject 2. Why does SWFObject use JavaScript?SWFObject 2 primarily uses JavaScript to overcome issues that cannot be solved by markup alone; it:
Should I use the static or dynamic publishing method?SWFObject 2 offers two distinct methods to embed Flash Player content:
The advantages of the static publishing method are:
The advantages of the dynamic publishing method are:
How to embed Flash Player content using SWFObject static publishingSTEP 1: Embed both Flash content and alternative content using standards compliant markupSWFObject's base markup uses the nested-objects method (with proprietary Internet Explorer conditional comments. See Flash Embedding Cage Match) to ensure the most optimal cross-browser support by means of markup only,while being standards compliant and supporting alternative content (See Flash Embed Test Suite): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> ? <head> ? ? <title>SWFObject - step 1</title> ? ? <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> ? </head> ? <body> ? ? <div> ? ? ? <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780" height="420"> ? ? ? ? <param name="movie" value="myContent.swf" /> ? ? ? ? <!--[if !IE]>--> ? ? ? ? <object type="application/x-shockwave-flash" data="myContent.swf" width="780" height="420"> ? ? ? ? <!--<![endif]--> ? ? ? ? ? <p>Alternative content</p> ? ? ? ? <!--[if !IE]>--> ? ? ? ? </object> ? ? ? ? <!--<![endif]--> ? ? ? </object> ? ? </div> ? </body> </html> NOTE: The nested-objects method requires a double object definition (the outer object targeting Internet Explorer and the inner object targeting all other browsers),so you need to define your object attributes and nested param elements twice. Required attributes:
Required param element:
NOTE: We advise not to use the codebase attribute to point to the URL of the Flash plugin installer on Adobe's servers,because this is illegal according to the specifications which restrict its access to the domain of the current document only. We recommend the use of alternative content with a subtle message that a user can have a richer experience by downloading the Flash plugin instead. How can you use HTML to configure your Flash content?You can add the following often-used optional attributes to the object element:
You can use the following optional Flash specific param elements (more info):
Why should you use alternative content?The object element allows you to nest alternative content inside of it,which will be displayed if Flash is not installed or supported. This content will also be picked up by search engines,making it a great tool for creating search-engine-friendly content. Summarizing,you should use alternative content when you like to create content that is accessible for people who browse the Web without plugins,create search-engine-friendly content or tell visitors that they can have a richer user experience by downloading the Flash plug-in. STEP 2: Include the SWFObject JavaScript library in the head of your HTML pageThe SWFObject library consists of one external JavaScript file. SWFObject will be executed as soon as it is read and will perform all DOM manipulations as soon as the DOM is loaded - for all browsers that support this,like IE,Firefox,Safari and Opera 9+ - or otherwise as soon as the onload event fires: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> ? <head> ? ? <title>SWFObject - step 2</title> ? ? <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> ? ? <script type="text/javascript" src="swfobject.js"></script> ? </head> ? <body> ? ? <div> ? ? ? <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780" height="420"> ? ? ? ? <param name="movie" value="myContent.swf" /> ? ? ? ? <!--[if !IE]>--> ? ? ? ? <object type="application/x-shockwave-flash" data="myContent.swf" width="780" height="420"> ? ? ? ? <!--<![endif]--> ? ? ? ? ? <p>Alternative content</p> ? ? ? ? <!--[if !IE]>--> ? ? ? ? </object> ? ? ? ? <!--<![endif]--> ? ? ? </object> ? ? </div> ? </body> </html> STEP 3: Register your Flash content with the SWFObject library and tell SWFObject what to do with itFirst add a unique id to the outer object tag that defines your Flash content. Second add the swfobject.registerObject method:
TIPS
How to embed Flash Player content using SWFObject dynamic publishingSTEP 1: Create alternative content using standards compliant markupSWFObject's dynamic embed method follows the principle of progressive enhancement and replaces alternative HTML content for Flash content when enough JavaScript and Flash plug-in support is available. First define your alternative content and label it with an id: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> ? <head> ? ? <title>SWFObject dynamic embed - step 1</title> ? ? <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> ? </head> ? <body> ? ? ? ? <div id="myContent"> ? ? ? <p>Alternative content</p> ? ? </div> ? ? ? </body> </html> STEP 2: Include the SWFObject JavaScript library in the head of your HTML pageThe SWFObject library consists of one external JavaScript file. SWFObject will be executed as soon as it is read and will perform all DOM manipulations as soon as the DOM is loaded - for all browsers that support this,Safari and Opera 9+ - or otherwise as soon as the onload event fires: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> ? <head> ? ? <title>SWFObject dynamic embed - step 2</title> ? ? <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> ? ? ? <script type="text/javascript" src="swfobject.js"></script> ? </head> ? <body> ? ? <div id="myContent"> ? ? ? <p>Alternative content</p> ? ? </div> ? </body> </html> STEP 3: Embed your SWF with JavaScriptswfobject.embedSWF(swfUrl,id,width,height,version,expressInstallSwfurl,flashvars,params,attributes,callbackFn) has five required and five optional arguments:
NOTE: You can omit the optional parameters,as long as you don't break the parameter order. If you don't want to use an optional parameter,but would like to use a following optional parameter,you can simply pass false as its value. For the flashvars,params and attributes JavaScript Objects,you can also pass an empty object instead: {}. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> ? <head> ? ? <title>SWFObject dynamic embed - step 3</title> ? ? <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> ? ? <script type="text/javascript" src="swfobject.js"></script> ? ? ? ? <script type="text/javascript"> ? ? swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0"); ? ? </script> ? </head> ? <body> ? ? <div id="myContent"> ? ? ? <p>Alternative content</p> ? ? </div> ? </body> </html> How can you configure your Flash content?You can add the following often-used optional attributes to the object element:
Note: class is a reserved ECMA4 keyword and will throw errors in Internet Explorer unless it is surrounded by quotation marks (e.g. "class" or 'class'). For this reason,swfobject provides the styleclass keyword as a safe alternative syntax for class; if you use styleclass,swfobject will automatically insert it as class for you. Example: var attributes = { ? ?id: "myId", ? ?align: "left", ? ?styleclass: "myclass" }; If you would rather use class instead of styleclass,wrap the word class in quotes like this: var attributes = { ? ?id: "myId", ? ?"class": "myclass" }; You can use the following optional Flash specific param elements (more info):
How do you use JavaScript Objects to define your flashvars,params and object's attributes?You can best define JavaScript Objects using the Object literal notation,which looks like: <script type="text/javascript"> var flashvars = {}; var params = {}; var attributes = {}; swfobject.embedSWF("myContent.swf", "9.0.0","expressInstall.swf", flashvars, params, attributes); </script> You can add your name:value pairs while you define an object (note: please make sure not to put a comma behind the last name:value pair inside an object) <script type="text/javascript"> var flashvars = { ? name1: "hello", ? name2: "world", ? name3: "foobar" }; var params = { ? menu: "false" }; var attributes = { ? id: "myDynamicContent", ? name: "myDynamicContent" }; swfobject.embedSWF("myContent.swf", attributes); </script> Or add properties and values after its creation by using a dot notation: <script type="text/javascript"> var flashvars = {}; flashvars.name1 = "hello"; flashvars.name2 = "world"; flashvars.name3 = "foobar"; var params = {}; params.menu = "false"; var attributes = {}; attributes.id = "myDynamicContent"; attributes.name = "myDynamicContent"; swfobject.embedSWF("myContent.swf", attributes); </script> Which can also be written as (the less readable shorthand version for the die-hard scripter who love one-liners): <script type="text/javascript"> swfobject.embedSWF("myContent.swf", {name1:"hello",name2:"world",name3:"foobar"}, {menu:"false"}, {id:"myDynamicContent",name:"myDynamicContent"}); </script> If you don't want to use an optional argument you can define it as false or as an empty Object (NOTE: from SWFObject 2.1 onwards you can also use null or 0): <script type="text/javascript"> var flashvars = false; var params = {}; var attributes = { ? id: "myDynamicContent", attributes); </script> The flashvars Object is a shorthand notation that is there for your ease of use. You could potentially ignore it and specify your flashvars via the params Object: <script type="text/javascript"> var flashvars = false; var params = { ? menu: "false", ? flashvars: "name1=hello&name2=world&name3=foobar" }; var attributes = { ? id: "myDynamicContent", attributes); </script> TIPS
SWFObject 1.5 to SWFObject 2 migration tips
UFO to SWFObject 2 migration tips
Does SWFObject 2 support MIME type application/xhtml+xml?SWFObject 2 does NOT support XML MIME types,which is a design decision. There are a number of reasons why we are not supporting this:
Tutorials (beginner level)
CommentsThe comments functionality on this wiki has been switched off to avoid spam and abuse. If you have any questions/comments about SWFObject or its documentation,or have problems with an implementation:
If you find any bugs or want to request a future enhancement,you can fill in an issue report on the SWFObject issues page (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |