0

I am trying to use the ExternalInterface.call function in my ActionScript(2.0) to get a javascript var value set in the wrapping document. The following seems to work in FireFox and in Chrome but, naturally, it does not work in IE(8). Can anyone suggest another method for getting the value stored at this variable? Thanks!

var linkPath = ExternalInterface.call("function(){return window.customLinkLocation;}", null);

JavaScript:

<head>
    <script type="text/javascript">
    var customLinkLocation = "http://localhost/file.xml";
    </script>
</head>

Could it be the way I am embedding my swf??

 <body>
<object width="550" height="400" id="mySwf">
<param name="movie" value="mySwf.swf">
<embed src="mySwf.swf" width="550" height="400">
</embed>
</object>
1
  • Any reason you're using an anonymous function? Commented Nov 5, 2010 at 15:15

6 Answers 6

1
ExternalInterface.call("window.customLinkLocation.toString");
Sign up to request clarification or add additional context in comments.

3 Comments

Are you sure about this? I thought you can only call functions.
No reason. I thought that the call function required the first param to be a function. The above answer does not seem to make a difference.
@Alin: window.customLinkLocation.toString is a function. @Nick: OK. I wasn't convinced it would work anyway because your original code should work, so there must be something else wrong.
1

are you embedding swf with id provided?

http://forums.adobe.com/message/2638459#2638459

1 Comment

I added an 'id' attribute to my object tag and it did not make a difference. Although this makes me suspect the way I am embedding the flash. I will update my question to show this. Thanks
1

From my understanding of the documentation and some (but not too much) previous experience: You need to call a function by supplying its name. You can't execute custom code from ActionScript. In you case you need to create a function in JavaScript that returns the values you need.

function getCustomLinkLocation(){
    return customLinkLocation;
}

and call

ExternalInterface.call("getCustomLinkLocation");

I don't know why Firefox and Chrome allow you to call an anonymous function, but the ExternalInterface reference doesn't say anything about it.

From ActionScript, you can do the following on the HTML page:

  • Call any JavaScript function.
  • Pass any number of arguments, with any names.
  • Pass various data types (Boolean, Number, String, and so on).
  • Receive a return value from the JavaScript function.

3 Comments

That's why I am using an anonymous function. I do not want to implement a function in my javascript (client constraint).
Then you could try calling eval, and pass it the correct string. I'm not sure if you'll be prevented from doing this for possible security reasons.
Maybe IE8 has some security policy that doesn't allow you to use anonymous functions. Calling an anonymous function allows you to run any code you want. It may be possible that IE8 considers that too much of a threat.
1

Got it. The problem is that IE requires that you use the classid attribute on the 'object' element.

<object width="550" height="400" id="mySwf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<param name="movie" value="mySwf.swf">
<embed src="mySwf.swf" width="550" height="400">
</embed>
</object>

Comments

0

Also make sure allowscriptaccess is set to 'always' in your embed code.

Comments

0

You can also do this:

ExternalInterface.call("eval","getVar=function(obj){return obj}");
var yourVar:String = ExternalInterface.call("eval","getVar(JSvar)");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.