Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 3

Clicking a link to open in a new window


Example 1.

Download the FLA file

my_btn.addEventListener(MouseEvent.CLICK, gotoWebsite);
function gotoWebsite(myEvent:MouseEvent)
{
	var link:URLRequest = new URLRequest("http://www.google.com");
	navigateToURL(link, "_blank");
}

Example 2.

Download the FLA file

var js:URLRequest=new URLRequest();
js.url="javascript:window.open('http://www.google.com','popper1','width=540,height=360');newWindow.focus(); void(0);";

my_btn.addEventListener(MouseEvent.CLICK, gotoWebsite);
function gotoWebsite(evt:MouseEvent):void
{
	navigateToURL(js,'_blank');
}

Example 3. The Flash movie calls a JavaScript function in the HTML document, by adding a string to a URLRequest object. It doesn't work -- when tested in IE7, instead of Google.com opening in a new window, the following IE error message appears:
"Internet cannot download. Unspecified error."

Download the FLA file

Action Script:

my_btn.addEventListener(MouseEvent.CLICK, gotoWebsite);
function gotoWebsite(myEvent:MouseEvent)
{
	var link:URLRequest = new URLRequest("javascript:open_window()");
	navigateToURL(link);
}

Javascript in HTML:

function open_window()
{
  window.open('http://www.google.com','win','height=200,width=300,toolbar=no,scrollbars=yes');
}

Example 4.

Download the FLA file

Action Script:

my_btn.addEventListener(MouseEvent.CLICK, gotoWebsite);
function gotoWebsite(myEvent:MouseEvent)
{
	ExternalInterface.call("open_window()");
}

Javascript in HTML:

function open_window()
{
  window.open('http://www.google.com','win','height=200,width=300,toolbar=no,scrollbars=yes');
}

Example 5. wmode transparent. This has the Flash movie as a background image, with an HTML/CSS button overlaying the Flash movie. The Flash movie has a wmode of "transparent".

Download the FLA file

This example requires no Action Script. Here's the HTML and CSS for the button:

<style type="text/css">

#clickable-area
{
height:40px;
left:18px;
position:absolute;
top:39px;
width:145px;
}

#example5 
{
position:relative;
}

</style>

<script type="text/javascript">

click_me_off = new Image;
click_me_over = new Image;
click_me_down = new Image;

click_me_off.src = "../../images/flash/click_me_off.gif";
click_me_over.src = "../../images/flash/click_me_over.gif";
click_me_down.src = "../../images/flash/click_me_down.gif";

function open_window()
{
  window.open("http://www.google.com","win","height=200,width=300,toolbar=no,scrollbars=yes");
}
</script>

<div id="example5">
<div id="clickable-area">
<a target="_blank" href="http://www.google.com" onmouseover="window.document.images.my_button.src=click_me_over.src" onmousedown="window.document.images.my_button.src=click_me_down.src" onmouseout="window.document.images.my_button.src=click_me_off.src"><img name="my_button" src="../../images/flash/click_me_off.gif" /></a>
</div>

(flash movie code goes here, if you'd like to see it, right click on this web page and view source for Example 5)

</div>


 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM