If you want to be able to open customised pop up windows from within
a flash (.swf) movie, using a few lines of simple Javascript. With this
code you will be able to open new browser windows with specific attributes,
with or without scroll bars, address bars, status bars, set widths and
heights. This tip aims to show you how easy this is to achieve
with a few simple lines of code. To achieve this you
will only need to use the actionscript getURL command in your flash movie
and you will need to embed a simple Javascript function within the <head>
</head> of your web page.
Relevant reading: Resizing
a browser window from flash & Open
a window with specific attributes
This Flash Javascript tip assumes that you know how to make simple
buttons in Flash and you know how to use the getURL actionscript
command. If so, lets begin with making a simple button in a flash movie
and adding the code below to your button. (copy and paste)
This actionscript code simply calls a Javascript function called OpenMyPopUp
from within the html page that hosts the flash movie. Within this function
we will define the new windows properties and attributes that will be
activate when a user clicks the flash button.
The javascript function
This script simply calls the Javascript function OpenMyPopUp() which
will be embedded in your html page that will open the new browser window.
Now open your html web page that will host the flash movie and add the
code below between the <head> </head> tags.
This simple function once called will open our new web browser window
with these specific attributes and dimensions specified in the variable
windowFeatures. You can easily change
these values to suit your particular popup window needs. Below lists
and briefly explains the attributes used in our script:
| Attribute |
Brief Description |
| Width |
The new windows Width (numerical value
in pixels) |
| Height |
The new windows Height (numerical value
in pixels) |
| Toolbar |
Shows or hides the browser buttons (0=hide
1=show) |
| Location |
Shows or hides the URL address bar (0=hide
1=show) |
| Status |
Shows or hides the status bar at the bottom.
(0=hide 1=show) |
| MenuBar |
Shows or hides the top menus i.e File,
Edit, etc. (0=hide
1=show) |
| ScrollBars |
Shows or hides the scrollbars. (0=hide
1=show) |
| Resizable |
Allows or disallows the window to be resized.
(0=disallow 1=allow) |
As with most optional features you can use 0 or 1, yes or no as the
defining values for off and on. The variable myWindowName defines the
name of the window and the self explanatory variable whichPage is the
page you wish to load up in your new window.
Once you have saved both your flash movie and your html page, give
them a test run and you will find that you can now open new customised
popup windows from within flash.
The benefit of this method
A great advantage of handling the window popup code outside
of the flash movie, is that you can control everything outside the movie,
which saves the time and trouble of editing and exporting your flash
movie each time you want to make a simple change.
Live example
Below we have prepared the code for a simple page to demo
the Javascript popup window feature, please copy and paste the code into
a blank page and test it out on your computer.
There are plenty of variations of what can be achieved with
these simple Javascript functions. We have included a very rough
page of the above scripts output
results.
Downloads: Download
Tip files (.zip)
Relevant reading: Resizing
a browser window from flash & Open
a window with specific attributes
Have fun ;0) |