开发者

Flash and JavaScript communication within IE

I am having in issue with IE pass开发者_如何学Pythoning a string back into an swf using the EternalInterface class in Flash CS4.

I have an swf with the following code:

var externalString:String = ExternalInterface.call("IncomingJS")

which is inside an event listener attached to an Event.ENTERFRAME and an if statement waiting for ExternalInterface.available.

The IncomingJS function looks like:

function IncomingJS() {
   return stringFromHTML;
}

and sits on the HTML page with the swf.

I am able to successfully get the externalString variable and procceed with the rest of the AS3 script in Firefox, Safari and Chrome, but not in IE.

If I add in an alert (stringFromHTML) before the return statement in the Javascript, I get the value of the stringFromHTML spammed, which looks like Flash is firing the function at the right rate.

The embed code in HTML for the swf is a little simple:

<object width="750" height="200" id="controlledScale"><param name="movie" value="http://www.myURL.com/controlledScale.swf"><param name="allowScriptAccess" value="sameDomain" /><embed src="http://www.myURL.com/controlledScale.swf" width="750" height="200" allowScriptAccess="sameDomain"></embed></object>

Any help or advice would be greatly appreciated.

Thanks, DavidB

Edit

I realise how poor the SWF embed code is. Unfortunately, the HTML code is actually working within a 3rd party HTML generator, and one of it's limitations is that I can only have a single line (with unlimited length) of html at a time.

Are the other options (swfObject etc) able to run either with no line breaks in the code, or would I be asking for trouble with Javascript and the SWF to, instead of embedding the SWF directly, use something like an iFrame and refer to a 'proper' flash delpoyment html file?

Kind of at a point on this one where I'm not even sure where the problem is actually located. The swf's are find sending out to Javascript across all browsers, just not getting info back in IE only.


You must add an id to the object tag to work in IE.

<object width="750" id="myflash" height="200"><param name="movie" value="http://www.myURL.com/controlledScale.swf"><param name="allowScriptAccess" value="sameDomain" /><embed src="http://www.myURL.com/controlledScale.swf" width="750" height="200" allowScriptAccess="sameDomain"></embed></object>


I pretty sure there is a security "feature" in IE that stops JS being called too many times from Flash, to stop it crashing the browser.

Is there a reason why you have to call it every frame?

I'd suggest against this at all costs as it's putting a LOT of extra stress on the browser.

***** EDIT *****

If you want to call an ExternalInterface method from JS -> Flash in IE you have to reference the object slightly differently, like this:

function thisMovie(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}

Then once you're sure the string you want to pass is constructed correctly you can call it like this from the JS:

thisMovie( "theFlashElementID" ).giveMeMyStringAlready();

Then in your Flash you would have something like this:

if( ExternalInterface.available ) 
{
  ExternalInterface.addCallback( "giveMeMyStringAlready", handleTheStringFromJS );
}
  else
{
  handleTheFactIDontHaveExternalInterfaceAvailable();
  // the only reason this would be is if container that 
  // is embedding the swf isn't fully loaded by the browser
}

The standout line from the AS3 docs regarding ExternalInterface is this:

Note: When using the External API with HTML, always check that the HTML has finished loading before you attempt to call any JavaScript methods.


This:

Unfortunately, the HTML code is actually working within a 3rd party HTML generator

is the problem.

The swf is sitting inside a <form> tag. At the browser stage, there is a huge volume of really verbose code, and I missed the tags at the very beginning and end of the html code.

Thanks for the help. If I have learnt nothing else from the experience, it's to be full with the question and look well beyond the immediate problem, breaking each element down as fully as I can.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜