Flash Banner - ActionScript & Javascript
Ok! Now we need to create a flash banner but hell o! we have loads of methods to achieve it.
Flash brought in the ExternalInterface for easy communication between Actionscript and Javascript.
I am not going to explore this here. However what I am going to explain now is the old method of creating a banner compatible in most browsers and yet is very simple. A method invented way back in 2000 and is still going on.....
The requirements are...
1) The banner should support image and swf played at regular intervals
2) The banner should be compatible in most browsers
3) The banner should be able to communicate with Javascript and vice versa
How do we achieve this?
1) Create a banner.swf file. This swf will be embedded in the browser and will now form the container for loading any image or swf into it dynamically.
2) Use javascript + Actionscript to communicate to and from the banner and voila! there it the trick.
Process:

Create something as seen above with the following actionscript within each frame.
Frame 1:
var bSourceObtained=false;
mcClicker.enabled=false;
Frame 2:
onEnterFrame()
{
if(trigger=="reset")
{
mcClicker.enabled=true;
mcMovie.loadMovie(source);
bSourceObtained=true;
trigger="init";
}
}
Frame 3:
gotoAndPlay(2);

The flash would contain three dynamic texts and two movieclips. One movieclip would act as a loader to load the content into it. And the other would handle the onRelease Event and process the information in holds. And hence we have three layers.
Layer 1 containing the Clicker MovieClip (A Transparent movieclip stretched to the size of the banner)
Layer 2 containing the Dynamic Texts and three frames with actionscripts within them
Layer 3 containing the Movie MovieClip - (A red box movieclip that will hold the content loaded)
The only thing then pending is an actionscript for the onRelease event of the clicker movieclip. Focus on the clicker movieclip Press F9 and paste the following script
on(release)
{
mcClicker.enabled=false;
if(_root.bSourceObtained==true)
{
getURL("javascript:invoke()");
_root.bSourceObtained=false;
getURL(_root.url,"_blank");
}
}
This is what goes into the Javascript
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);
}
}
function invoke()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
var url=flashMovie.GetVariable("/:url");
}
function SendDataToFlashMovie(url,source,id)
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.SetVariable("/:url", url);
flashMovie.SetVariable("/:source", source);
flashMovie.SetVariable("/:trigger","reset");
}
Insert this javascript into the page and there you go. You should be set and running.
getFlashMovieObject gets the object of the flash included into the html.
SendDataToFlashMovie Sends information from Javascript to Flash.
invoke Gets information from Flash to Javascript. All through the dynamic texts we created in flash.
Ensoy.
Flash brought in the ExternalInterface for easy communication between Actionscript and Javascript.
I am not going to explore this here. However what I am going to explain now is the old method of creating a banner compatible in most browsers and yet is very simple. A method invented way back in 2000 and is still going on.....
The requirements are...
1) The banner should support image and swf played at regular intervals
2) The banner should be compatible in most browsers
3) The banner should be able to communicate with Javascript and vice versa
How do we achieve this?
1) Create a banner.swf file. This swf will be embedded in the browser and will now form the container for loading any image or swf into it dynamically.
2) Use javascript + Actionscript to communicate to and from the banner and voila! there it the trick.
Process:

Create something as seen above with the following actionscript within each frame.
Frame 1:
var bSourceObtained=false;
mcClicker.enabled=false;
Frame 2:
onEnterFrame()
{
if(trigger=="reset")
{
mcClicker.enabled=true;
mcMovie.loadMovie(source);
bSourceObtained=true;
trigger="init";
}
}
Frame 3:
gotoAndPlay(2);

The flash would contain three dynamic texts and two movieclips. One movieclip would act as a loader to load the content into it. And the other would handle the onRelease Event and process the information in holds. And hence we have three layers.
Layer 1 containing the Clicker MovieClip (A Transparent movieclip stretched to the size of the banner)
Layer 2 containing the Dynamic Texts and three frames with actionscripts within them
Layer 3 containing the Movie MovieClip - (A red box movieclip that will hold the content loaded)
The only thing then pending is an actionscript for the onRelease event of the clicker movieclip. Focus on the clicker movieclip Press F9 and paste the following script
on(release)
{
mcClicker.enabled=false;
if(_root.bSourceObtained==true)
{
getURL("javascript:invoke()");
_root.bSourceObtained=false;
getURL(_root.url,"_blank");
}
}
This is what goes into the Javascript
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);
}
}
function invoke()
{
var flashMovie=getFlashMovieObject("myFlashMovie");
var url=flashMovie.GetVariable("/:url");
}
function SendDataToFlashMovie(url,source,id)
{
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.SetVariable("/:url", url);
flashMovie.SetVariable("/:source", source);
flashMovie.SetVariable("/:trigger","reset");
}
Insert this javascript into the page and there you go. You should be set and running.
getFlashMovieObject gets the object of the flash included into the html.
SendDataToFlashMovie Sends information from Javascript to Flash.
invoke Gets information from Flash to Javascript. All through the dynamic texts we created in flash.
Ensoy.
Comments