views:

901

answers:

3

I'm downporting some ActionScript 3 to ActionScript 2 (some ad agencies sadly still refuse to embrace the future) and I've run into the issue that in ActionScript 2 ExternalInterface has no objectID property, as it does in ActionScript 3.

The code I'm working on calls a lot of JavaScript, and some of that code requires the script to know the ID of the Flash object/embed (for example to find the position on the page, and to resize the object/embed).

Is there a simple workaround to get hold of the object/embed ID in ActionScript 2?

I have managed to write some JavaScript code that basically searches all object and embed nodes on the page until it finds one with a special method (set with ExternalInterface.addCallback) and that way managed to get the ID into the ActionScript environment, but it feels like a hacky and unsafe method to rely on. Surely there is a simpler way?

Edit: I don't have control over the code that embeds the SWF, so passing in the ID doesn't work.

A: 

What about passing the ID to the SWF via FlashVars? You should know the ID when you embed it, so it should be easy enough to add it as one of the FlashVars variables passed to Flash. Then store that somewhere your code that calls ExternalInterface can get at it.

Herms
Should have mentioned that I don't have control over the code that embeds the SWF.
Theo
A: 

Try the Flash Javascript Integration kit http://weblogs.macromedia.com/flashjavascript/ . As far as I'm aware, the ExternalInterface class in AS3 was a formalisation of this AS2 solution.

It requires that you know the object ID beforehand.
Theo
+1  A: 

Is this what you looking for? Simple actionscript 2 class that find it owns flash html object id.

http://sourceblogg.se/lang/en/mina-projekt/isitme-get-flash-html-object-id-within-flash/

Stefan
It's more or less what I already do, but it's good to know someone else has come to the same conclusion.
Theo