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.
Tags: actionscript 3, flash, popup
Using Caurina Tweener Class AS3
Eyes following mouse cursor AS3
Free Flash Template – Sunset
Freebie: Scrolling Image Menu
Build an image slideshow in Flash
good stuff! thanks for the tip
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?
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:)
I added the missing bracket to the example code.
cool, you learn something everyday: I never knew you could put a string as the Event type. Thanks.