views:

107

answers:

3

I am having in issue with IE passing 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"&gt;&lt;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.

A: 

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"&gt;&lt;param name="allowScriptAccess" value="sameDomain" /><embed src="http://www.myURL.com/controlledScale.swf" width="750" height="200" allowScriptAccess="sameDomain"></embed></object>
Makram Saleh
I am still working on this, and thought of that as well . I have edited the above code to reflect what's there now.Unfortunately, the issue still exists.
Gopherism
A: 
jolyonruss
I have had timing issues in the past in relation to load orders and the availiablity of java, and the readiness of the string I want to pass, so firing the script on an ENTERFRAME event seemed logical.Would a timer event seem more reasonable in that case (1 sec intervals)?The event is removed once the string is successfully read, not for the life of the swf in the browser.If I include an alert in the Javascript, I get spammed with the alert box, @ the framerate and need to end the browser from the task manager, so I'm not sure if that's it either.
Gopherism
If you're having timing issues, it might be better to have Flash listen for call from JS instead of Flash calling a method on JS so often, after all ExternalInterface is bi-directional :-)Flash -> JS every frame/every second - bad ideaJS -> Flash when the data is ready - better ideaOn a recent project we had a big Flash header that did an initial load, then some jQuery waited for the rest of the page to fully load before calling a method to load the rest of it's assets.Also edited my answer above for more clarity to my points above
jolyonruss
A: 

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.

Gopherism