Tips & Tricks 7: Create Popup Windows in Flash – ActionScript 3.0

A couple of days ago a fellow asked me how can he makes a popup window in Flash for his website. I showed him how and I was thinking why not to share with you also. It’s an easy and very powerfull trick.

Here we go (this example is for Actionscript 3.0):

1. Create a MovieClip and give an instance name (e.g: myMovie)

2. Add an event listener to the movie you created:

myMovie.addEventListener("mouseDown",mousePress);

3. Create the mousePress function like so:

function mousePress(e:MouseEvent){

var url ="javascript:window.open('http://www.yoursite.com','title',
'width=800,height=600,toolbar=no,resizable=no,menubar=no,
status=no,scrollbars=no');void(0);";

var request1:URLRequest = new URLRequest(url);

	try {
  navigateToURL(request1);
         }
      catch (e:Error) {
  trace("Error occurred!");
}
}

4. Publish the movie and preview it in your browser.

Hi, there! I'm Alin the founder of Flashuser.net. My passions are related to web and graphic design, photography and climbing. You can find me at Twitter and Facebook

Tags: , ,

Related Posts

Wordpress Themes

6 Comments

  1. samBrown

    good stuff! thanks for the tip

  2. samBrown

    quick question: stated playing around with this, kicks out

    “1095: Syntax error: A string literal must be terminated before the line break.” regarding the var url string.

    also never seen “mousedown” as the event type. I’m used to addEventListener(MouseEvent.MOUSE_DOWN, mousePress)…. is that a different way to event type a listener?

  3. flashuser

    The error appears because I put two Enter keys in the attached string for “url” variable so all the example code to be displayed. When you test it in Flash write it in a single line. Also a “}” is missing for the function to be ended.

    For the MouseEvent you can use both the string like I do or the longer version, i’m used with the first one:)

  4. flashuser

    I added the missing bracket to the example code.

  5. samBrown

    cool, you learn something everyday: I never knew you could put a string as the Event type. Thanks.

    Trackbacks

  1. Daily Trick 7: Create Popup Windows in ActionScript 3.0 | Flash User | Adobe Tutorials

Leave a Reply