HTML insert Flash full compatibility perfect solution-swfobject

Source: Internet
Author: User

Flash embedding problems Friends may think it is very simple, but specific to some of the problems, it is not so simple, such as: IE browser to flash block virtual box how to remove? Is the FF, OP, NS, and other browsers compatible? is the code in line with the standard?? Wait a minute

Below I would like to share someone else's paper, study together

I. The traditional approach

<ObjectClassID= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"codebase= "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"width= "550"Height= "The "ID= "Untitled-1"Align= "Middle"> 
<paramname= "allowScriptAccess"value= "Samedomain" /> 
<paramname= "movie"value= "mymovie.swf" /> 
<paramname= "Quality"value= "High" /> 
<paramname= "bgcolor"value= "#ffffff" /> 
<Embedsrc= "mymovie.swf"Quality= "High"bgcolor= "#ffffff"width= "550"Height= "The "name= "Mymovie"Align= "Middle"allowscriptaccess= "Samedomain"type= "Application/x-shockwave-flash"pluginspage= "Http://www.macromedia.com/go/getflashplayer" /> 
</Object>

This method is embedded using the object and embed tags, careful to find that many of the parameters of object and embed many of the properties are duplicated, why do you do this? For browser compatibility, some browsers support object, some support embed, which is why to change the parameters of Flash two places to change the reason.

This method is Macromedia has been the official method, the maximum guarantee the function of Flash, no compatibility issues. But it's not that good anymore: it can't be verified, because the embed tags embedded for compatibility are not compliant. Of course, if you do not care about what norms are not standardized, another matter.

Microsoft for various reasons, after SP2 restrictions on the use of IE ActiveX mode, that is, in the page ActiveX has a virtual box, users need to click once to normal interaction. Flash is embedded as an ActiveX in the Web page, so it will also be implicated, only by JS embedded Flash to solve this problem.

No flash version detection, if the version browser Flash plugin version is not enough, or can not display your SWF file normally, or will pop up an ActiveX confirmation installation box-this box for many users is very scary.

Second, the method of embedding with JS

With JS embedding is each have each embedding method, there is good inlay is not well embedded. Someone with Document.Write Direct write, this way to tell the truth is not good, feel hack ingredient more, a bit to verify and verify the meaning, and did not reflect what JS advantage. I think a good JS embedded script, in order to ensure that the flash should be functional basis, to play the advantages of JS should have version detection, to be able to solve the accessibility problem (that is, users can not browse the Flash content or to disable JS when the problem should be handled), to be easy to re-use.

What we're going to talk about here is the SWFObject solution:

"SWFObject" is the use of JavaScript to insert Flash, the benefits of a lot, the code is concise, will not appear under the IE6 "Click here to activate the control" prompt, and can be verified through the. Different from the traditional "object" method of inserting flash.

SWFObject in the new 2.x version, its simplest invocation is just a word, and does not need to wait for the page to be loaded, which means you can write this sentence anywhere on the page. It's much simpler than the previous version. Here are a few simple and common calling methods:

1, the simplest, the most basic, as long as you want to insert Flash can use the classic word.

<DivID= "Swfid"></Div> 
<Scripttype= "Text/javascript"src= "Swfobject.js"></Script> 
<Scripttype= "Text/javascript">
swfobject.embedswf ("test.swf", "Swfid", " -", " -", "9.0.0", "expressinstall.swf");
</Script>

Note: The calling method embedswf--the SWF file, the parameter is the address of the @swf file, the ID of the container that is used to mount the SWF file (such as Div), the width of the @flash, and the height of the @flash (of course, the width of this place can be used such as 100% The minimum version required for the Flash to play normally, @ when the version is lower than required, execute the SWF file, which uses this flash to jump to the official download of the latest version of the Flash plugin. (This parameter can be omitted) when inserting multiple flash to different locations on the same page, simply repeat the above statement, using a different container ID.


2, to the SWF file to pass parameters, variables, properties of the call method

<Scripttype= "Text/javascript"src= "Swfobject.js"></Script> 
<Scripttype= "Text/javascript"> 
//1. Initialize variables, parameters, properties using JSON 
        varFlashvars= {
NAME1:"Hello",
Name2:" World",
Name3:"Foobar"
        };
varparams= {
Menu:"false"
};
varattributes= {
ID:"DynamicContent2",
Name:"DynamicContent2"
        };
swfobject.embedSWF ("test6_flashvars.swf", "Content2", " -", " -", "6.0.0","expressinstall.swf", flashvars, params, attributes);

//2, the traditional initialization settings, the same effect 
        varFlashvars={};
Flashvars.name1= "Hello";
Flashvars.name2= " World";
Flashvars.name3= "Foobar";
varparams={};
Params.menu= "false";
varattributes= {};
Attributes.id= "DynamicContent3";
Attributes.name= "DynamicContent3";
swfobject.embedSWF ("test6_flashvars.swf", "Content3", " -", " -", "6.0.0","expressinstall.swf", flashvars, params, attributes);
//3, directly written in the back, on a word, concise swift, not muddy 
swfobject.embedswf ("test6_flashvars.swf", "content5", " -", " -", "6.0.0","expressinstall.swf", {name1:"Hello", Name2:" World", Name3:"Foobar"}, {menu:"false"}, {ID:"dynamicContent5", Name:"dynamicContent5"});
</Script>

SWFObject Google Open source project http://code.google.com/p/swfobject/
SWFObject (2.2 edition): Http://swfobject.googlecode.com/files/swfobject_2_2.zip
SWFObject (2.0 edition): Http://swfobject.googlecode.com/files/swfobject_2_0.zip
The official blog:http://blog.deconcept.com/swfobject/of SWFObject
SWFObject 2.0 Official document (Chinese) http://www.admin10000.com/resource/1.html

Come as far as http://www.admin10000.com/Document/5.html

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.