The problem of the interaction between JS and AS3

Source: Internet
Author: User
Tags api manual

I think it's time to correct some of the pitfalls, that is, how JS in HTML gets the SWF object of Flash and interacts with AS3.

The official wording should be to return the id attribute of the OBJECT tag in Internet Explorer, or return the name attribute of the embed tag in Netscape (AS3 API manual).

function Thismovie (moviename) {   if (navigator.appName.indexOf ("Microsoft")! =-1)        {  return  window[moviename];    Else {        return  document[moviename];}   }

But this kind of writing is problematic, especially in the late Firefox, if the object inside the embed tag, it must be returned embed object (this object is the function form), and embed is unable to obtain AS3 Addcallback method. So there are a lot of people on the internet called FF inside JS can not interact with AS3, it is not true.

After testing several browsers, I found that they were compatible with Window[id] and Document[name] as follows

Use HTML code:

<ObjectClassID= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"ID= "Externalinterfaceexample"width= "$"Height= "375"codebase= "Http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">         <paramname= "movie"value= "externalinterfaceexample.swf" />         <paramname= "Quality"value= "High" />         <paramname= "bgcolor"value= "#869ca7" />         <paramname= "allowScriptAccess"value= "Samedomain" />         <Embedsrc= "externalinterfaceexample.swf"Quality= "High"bgcolor= "#869ca7"width= "$"Height= "375"name= "Externalinterfaceexample"Align= "Middle"Play= "true"Loop= "false"Quality= "High"allowscriptaccess= "Samedomain"type= "Application/x-shockwave-flash"pluginspage= "Http://www.macromedia.com/go/getflashplayer">         </Embed>     </Object>

IE8 is a later version of the upgrade.

As you can see, the SWF object can be obtained by all browsers using Document[id], but FF and opera cannot get the method of AS3 outward exposure. Using Window[name] Chrome/opera/safari is not able to obtain AS3 Addcallback method. If the two methods are compatible with opera still Can't get As3 method (in fact, not opera can't get embed elements, but these two writing does not work, if use $ ("Embed[name= ' swfimg ')") [0] can be obtained SWF object, Just can't interact with action). The biggest highlight is IE, which can get objects and interact with AS3, regardless of the method used.

If we use our usual document.getElementById, the results are very surprising.

All browsers have access to object tag objects, and all have access to the Addcalback method of AS3 exposure.

Let's look at the browser in the first table, the embed tag is the Firefox/chrome/opera/safari browser, these browsers are updated very fast, smooth upgrade of the modern browser. Since they all support the object tag, there is no need to worry about embedding the Embed object.

If the embed label is removed, the wording becomes

<ObjectClassID= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"ID= "Externalinterfaceexample"width= "$"Height= "375"codebase= "Http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">         <paramname= "movie"value= "externalinterfaceexample.swf" />         <paramname= "Quality"value= "High" />         <paramname= "bgcolor"value= "#869ca7" />         <paramname= "allowScriptAccess"value= "Samedomain" />     </Object>

Results

In fact, the embed tag is not a standard tag for HTML 4.01, but many browsers support it, but the level of support is different. In HTML5, embed has become a standard, it can embed video, audio and Flash, but in some devices such as the ipad is not able to play flash, the object tag is not.

So, if you do not consider the forward browser compatibility, just use object embedded flash, to get flash elements, interactive words document.getElementById enough.

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.