getUrl() method of Flash throws tons of security warnings in Internet Explorer. As a Web Developer, highly unfortunately, you still might have to consider Internet Explorer if you intend to keep your job.
Other alternatives to
getUrl() like, for instance the
fscommand action doesn't work either.
fscommand is a depreciated action for telling ActiveX or your Web browser what to do. Moreover,
fscommand is almost 7 generations of Flash old. So let's forget about it quickly again.
As it turns out in Flash with ActionScript 3 we can make use of another object and its method, namely the
To be able of invoking the method correctly, there are a few things we have to consider first.
A major issue is that you have to put your Flash and the HTML site into a live server environment. A friendly reminder to all the lazy ones out there to finally set up that IIS (seriously?), apache or nginx locally.
Let's give it the name
JSTestFunction. We can also pass our
JSTestFunction a string or an object.
Luckily with AS3 everything has become significantly better. Loose typing and global variables by default are long gone. In the code above we used some of AS3's new feautures. We did import the
flash.external package and declared the type of
JSvalue. Then we used the
call method of the
Return a value back to Flash
Now if you run your Flash application and invoke the method
call of the class
ExternalInterface, the variable
You can verify this by using a decent debugging tool, I used Arthropod years ago, but the package is not available anymore, therefore I would recommend Thunderbolt AS3
Why am I not using a built-in tracer? In my opinion the days of annoying
alert(); pop-ups are long gone.
callFlash. The name of the function is not important, just make sure you call the method
addCallback of the class
flashObject is the unique identifier I gave my SWF object inside of HTML. I passed the integer
1 over to Flash which then will get passed on to the object
myObj of the function
As always I welcome you to drop any suggestions in the comments below or link to this article as a token of your appreciation for my work.