SpellCoder

Welcome to SpellCoder Sign in | Join | Help
in Search

Beckham

JavaScript - Flash Communication

I used to work with flash all the times, in fact we used it in almost every project through college. You can do amazing things with flash very easily and honestly I love action scriptBig Smile [:D]. Whenever you work with flash you will find yourself need to make flash communicate with other applications.
 In action script you can communicate with a host application (in my case the Browser) through External Interface.

To do that you to write a little JavaScript Code:

 First you need to get the name of the flash movie and as usual this name differs along with the browser you are using so here is a method that I found here to get you the name of the flash movie whatever the browser is:
function getFlashMovieObject(movieName) {
if (window.document[movieName]) {
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet") == -1) {
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(movieName);
}
}

// Now Call the function on your flash movie.

function SendDataToFlashMovie(data) {
var flashMovie = getFlashMovieObject("myFlashMovie");
flashMovie.JStoAS(data);}


then you have to write alittel Action Script code:
Now you have to register a callback method to respond to your method call from javascript.

import flash.external.ExternalInterface;
ExternalInterface.addCallback
("JStoAS", getDataFromJavaScript);
function getDataFromJavaScript(data:String):void {
// Dod whatever you want with data here
}

and that's how it's done Wink [;)]

Beckham
Published Saturday, August 29, 2009 4:28 AM by beckham
Filed Under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Dody Gunawinata said:

Check out spellcoder.org. Let me know if you want to migrate. Community Server cannot be upgraded anymore.
September 16, 2009 9:09 AM

What do you think?

(required) 
(optional)
(required) 

This Blog

Post Calendar

<August 2009>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

Syndication