Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  JavaScript Popup Window

JavaScript Popup Window

By CyanBlue | Published 12/27/2006 | Beginner | Rating:
JavaScript Popup Window

This is a very simple tutorial that gives you one simple thing to learn.

  • Calling the JavaScript function with arguments.
Take a look at the final version. I am sure you've seen this alot. Unfortunately, there might be some computers that won't allow the new popup due to the popup blockers, and I do not know of any way to circumvent that problem.
Here is the ActionScript part.
  1. siteName1 = "http://www.FlashVacuum.com";
  2. w1 = 780;
  3. h1 = 550;
  4. siteName2 = "http://www.ActionScript.org";
  5. w2 = 600;
  6. h2 = 400;
  7. this.launch1_btn.onRelease = function ()
  8. {
  9. trace("siteName1 = " + siteName1);
  10. getURL("javascript:launchMyWindow('" + siteName1 + "','" + w1 + "','" + h1 + "');");
  11. }
  12. this.launch2_btn.onRelease = function ()
  13. {
  14. trace("siteName2 = " + siteName2);
  15. getURL("javascript:launchMyWindow('" + siteName2 + "','" + w2 + "','" + h2 + "');");
  16. }
Line 1 ~ 7 siteName1 = "http://www.FlashVacuum.com";
w1 = 780;
h1 = 550;

siteName2 = "http://www.ActionScript.org";
w2 = 600;
h2 = 400;
I am sure you know what those lines are for. I am merely defining several variables that I can use for each button when it needs to call the JavaScript function.
Line 9 ~ 13 this.launch1_btn.onRelease = function ()
{
trace("siteName1 = " + siteName1);
getURL("javascript:launchMyWindow('" + siteName1 + "','" + w1 + "','" + h1 + "');");
}
This is where I am defining the action to the first button. Mind you that I am using the onRelease function rather than attaching the action to the button directly. I am doing this so that I know where all my codes are, which is the frame 1 of my movie. It is whole lot easier this way to manage the movie especially when you have more complex movie structure.
Two thing you will need to make sure of. Make sure of the quotes that you are using. Double quotes are for Flash and single quotes are for JavaScript. Another thing is that you've got to use onRelease rather than onPress to avoid the erratic behavior of the Google popup blocker.
Here is the JavaScript function.
  1. <script language="JavaScript">
  2. <!--
  3. function launchMyWindow(site, w, h)
  4. {
  5. // alert('site = ' + site + ' w = ' + w + ' h = ' + h);
  6. window.open(site,'','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=' + w + ', height=' + h + ', left=50, top=50');
  7. }
  8. -->
  9. </script>
Line 5 alert('site = ' + site + ' w = ' + w + ' h = ' + h);
I HAD used this alert() function to make sure that I am getting the right value from the Flash. It's always a good idea to use that function when you test your code and simply disable it when you are deploying the file.
Line 6 window.open(site,'','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=' + w + ', height=' + h + ', left=50, top=50');
This is the actual line which opens up a new window with three arguments, URL, width and height of the new window.
Well, that's about it, I guess. See if you can understand what I just said and post the question to the forum if you have any or if you have suggestion/correction.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent

Verification:
Enter the security code shown below:
img


Add comment

Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Attachments
Comments
  • Comment #1 (Posted by agi - agione at gmail.com)
    Rating
    Doesn't seem to Work in Firefox 2.0.0.2 ...
     
  • Comment #2 (Posted by stann - midijunky at hotmail.com)
    Rating
    This creates a JS error in IE 6.0 and similarly doesn't work in Firefox 2.0+.
     
  • Comment #3 (Posted by an unknown user)
    Rating
    is not working in firefox 1.5.0.11
     
  • Comment #4 (Posted by Robert Barlow - act_of_bob at hotmail.co.uk)
    Rating
    If you reduce the page size in IE (bottom right), the scroll frame <pre> only shifts the code numbers and some of the script is completely obliterated.
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.