Browser Control From Flash

by Hiroshi on October 26, 2008

in Actionscript, Adobe Flash, Browser, Control, Tips

In this section you will learn how to do the following in Flash using ActionScript.

  • Close Browser From Flash
  • Without POPUP Alert (browser close)
  • With POPUP Alert (browser close)
  • With POPUP Alert (browser close)
  • Print From Flash
  • Add to Favourites From Flash
  • Launch Popup or Fullscreen Window From Flash
  • For Full Screen in Html Page Containing Swf
  • Open Many Popups From Flash (if u have many buttons and which indicate different windows to open)

and more…

Close Browser From Flash

With POPUP Alert (swf close)

fscommands will do the task. Write the following script on button in flash and you are done.
This script will close the swf and not the browser page.

on (release) 
{
fscommand("quit");
}
Without POPUP Alert (browser close)

Write the following script on button in flash and you are done.

on (release) 
{
getURL("javascript:window.opener=self;window.close(); ", "_self");
}
With POPUP Alert (browser close)
on (release) 
{
getURL("javascript:window.close()");
}
With POPUP Alert (browser close)
On Flash Button
on (release) 
{
getURL("JavaScript:close();");
}

In that webpage in body section write the following anywhere.

<a href=JavaScript:close();></a>

Print From Flash

There is print function in flash under printing action script menu, you can use that.

on (release) 
{
print(_root, "bmax");
}

It will print the whole _root timeline. If you want to specify frames (like one frame only put a label on the frame that says #p (hash sign + p) everything else will be excluded.

OR

on (release) 
{
printAsBitmapNum(0, "bmovie");
}

Printing can be customised and you can define area and other options for that i.e.

Check out following instructions

Add to Favourites From Flash

Following is the example of how to add to favorites from flash movie. You will have to add some actionscript at some button in flash and also some javascript code in webpage head section inwhich that flash movie is beingcalled.

On Flash Button
on (release) 
{
getURL("javascript:AjoutFavo()", "_self");
}
In Webpage Head Section
<SCRIPT LANGUAGE="JavaScript"> 
function AjoutFavo() {
if ((navigator.appName.indexOf("Microsoft",0)>=0) && (parseInt(navigator.appVersion)>=4)) {
window.external.AddFavorite("http://www.websiteurl.com","web site name" );
} 
}
</SCRIPT>

Launch Popup or Fullscreen Window From Flash

Popup From Flash

Script For Flash Button
on (release) 
{
getURL("javascript:openWin();");
}
For Html Page that Contain Swf with Button
<script language="javascript">
function openWin()
{
window.open('http://yahoo.com', 'win_ranking', 'width=320,height=400,toolbar=0,menubar=0,location=0,left=0,top=113,screenX=0,screenY=100,scrollbars=no');
}
</script>
For Full Screen in Html Page Containing Swf
<script language="javascript">
function openWin()
{
window.open('http://yahoo.com', 'win_ranking', 'toolbar=0,menubar=0,location=0,left=0,top=113,screenX=0,screenY=100,scrollbars=no,fullscreen=yes');
}
</script>
Open Many Popups From Flash (if u have many buttons and which indicate different windows to open)

Add following scripts to your flash buttons.

on (release) {
getURL("JavaScript: OpenWin('1.htm');");
}
on (release) {
getURL("JavaScript: OpenWin2('2.htm');");
}
on (release) {
getURL("JavaScript: OpenWin3('3.htm');");
}

and so on…

Add this script in the head of your page inwhich this swf is embedded.

<Script Language="JavaScript"> function OpenWin(fileName){
window.open(fileName,'mNew',"width=270,height=179,toolbar=0,menubar=0,location=0,left=0,top=113,screenX=0,screenY=100,scrollbars=no");	
}
function OpenWin2(fileName){
window.open(fileName,'mNew2',"width=172,height=268,toolbar=0,menubar=0,location=0,left=0,top=113,screenX=0,screenY=100,scrollbars=no");	
} function OpenWin3(fileName){
window.open(fileName,'mNew3',"width=411,height=270,toolbar=0,menubar=0,location=0,left=0,top=113,screenX=0,screenY=100,scrollbars=no");	
}
// and so on ................................
</script>

Related Posts

Previous post:

Next post: