This site is optimised for Firefox 2.0 or Internet Explorer 7.

AS3 close window

yushosha has no avatar
yushosha
 
Post Count: 4
Joined: Fri Sep 05, 2008 4:07 am
Flash Version: Adobe Flash CS3

AS3 close window

Postby yushosha on Mon Oct 06, 2008 7:32 pm

Hello Everyone!

I am having a difficult time trying to figure out, how to close a window in AS3. I have a page that comes up that is in AS3 and I have a close window Movie Clip in the corner. And what I am trying to figure out, is how to close the window by clicking the Movie Clip in AS3. can someone help me figure this out?

User avatar
vernbaby
 
Post Count: 190
Joined: Thu Jul 31, 2008 10:55 pm
Location: Seattle, WA.
Flash Version: Adobe Flash CS4

Re: AS3 close window

Postby vernbaby on Mon Oct 06, 2008 7:52 pm

hey yushosha...

i just ran into an issue with this and figured out how to go about it. basically... you just need to put a javascript call into your AS to close out the active window. something like this...
Code: Select all
var jscommand:String = "window.close();";
var req:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(req, "_self");


that should accomplish what you're looking for. make sure you add the corresponding import statements if you're doing this from within a Class...

hope this helps...
vern
...if "progress" means moving forward... what's "congress"?

yushosha has no avatar
yushosha
 
Post Count: 4
Joined: Fri Sep 05, 2008 4:07 am
Flash Version: Adobe Flash CS3

Re: AS3 close window

Postby yushosha on Mon Oct 06, 2008 8:31 pm

Cool Thanks Vern.

One last Question, I am a complete novice when it comes to AS3. How would I add that code to a Movie Club as a button?

I am use to
mistermovie_mc.onRelease () {
getURL ("http://www.thepage.com", "_self");

But with AS3 I have no clue how to add a click event I Guess?

User avatar
vernbaby
 
Post Count: 190
Joined: Thu Jul 31, 2008 10:55 pm
Location: Seattle, WA.
Flash Version: Adobe Flash CS4

Re: AS3 close window

Postby vernbaby on Mon Oct 06, 2008 8:58 pm

hey yushosha...

it's pretty simple... here's an example where your button has an instance name of "mistermovie_mc"...
Code: Select all
// add an EventListener to the button
mistermovie_mc.addEventListener(MouseEvent.CLICK, buttonClick);

// the function that runs when after button was clicked
function buttonClick(e:MouseEvent):void {
  var jscommand:String = "window.close();";
  var req:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
  navigateToURL(req, "_self");
}

that's about it.

hope this helps...
vern
...if "progress" means moving forward... what's "congress"?

yushosha has no avatar
yushosha
 
Post Count: 4
Joined: Fri Sep 05, 2008 4:07 am
Flash Version: Adobe Flash CS3

Re: AS3 close window

Postby yushosha on Mon Oct 06, 2008 10:31 pm

Thanks Vern!!! You helped me alot today! I appreciate it!

User avatar
dougburnett
 
Post Count: 26
Joined: Fri Oct 31, 2008 4:24 am
Flash Version: Adobe Flash CS4

Re: AS3 close window

Postby dougburnett on Wed Dec 24, 2008 7:57 pm

If you are trying to close a window in an AIR application, just assign this code (Fill in the "movieClipName" with your own instance name). (Note: I use this when I create an AIR application that has a custom chrome.)


movieClipName.addEventListener(MouseEvent.MOUSE_DOWN, closeWin);

function closeWin(e:Event):void
{
stage.nativeWindow.close();
}


I just modified Lee's code for the moveWin on his tutorial files for "Green Screen Video Fundamentals". I haven't tested it in anything besides and AIR application.

StefanoBCN has no avatar
StefanoBCN
 
Post Count: 1
Joined: Wed Dec 31, 2008 10:29 pm
Flash Version: Adobe Flash CS3

Re: AS3 close window

Postby StefanoBCN on Wed Dec 31, 2008 10:36 pm

Using exatly the same code on Flash CS3, MACS os X 10.6.5, Firefox 3.0.5, it happen that the button open a new window.
Why...?

arigato has no avatar
arigato
 
Post Count: 2
Joined: Mon Jun 15, 2009 3:01 pm
Flash Version: Adobe Flash CS4

Re: AS3 close window

Postby arigato on Mon Jun 15, 2009 3:05 pm

OK, I'm a little late to this discussion.
:D

I'm working on something similar, if all you want to do is close the popup, this works:

Code: Select all
function mouseUpHandler(event:MouseEvent):void {
   ExternalInterface.call("self.close()");
        }


I'm trying to figure out how to close the popup and load a new page in the parent.

"website.com" is a dummy url. I don't have access to the js file that opens the popup so I have no idea what the parent page's name is.

Code: Select all
function mouseUpHandler(event:MouseEvent):void {
   var url:String = "http://www.website.com";
   ExternalInterface.call("window.opener.location.href='" + url + "'");
   ExternalInterface.call("self.close()");
   }




Closing the popup works, but not the url load,even if I comment out the line that closes the popup.

Thoughts?

arigato has no avatar
arigato
 
Post Count: 2
Joined: Mon Jun 15, 2009 3:01 pm
Flash Version: Adobe Flash CS4

Re: AS3 close window

Postby arigato on Tue Jun 16, 2009 1:24 pm

Got it, nevermind.

Code: Select all
function mouseUpHandler(event:MouseEvent):void {
   var jscommand:String = "window.opener.location='http://www.website.com';self.close();";
   var req:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
   navigateToURL(req, "_self");
}


Return to Actionscript 3.0

Who is online

Users browsing this forum: Kirone and 5 guests