A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Actionscript to close an .SWF file.

  1. #1
    Junior Member
    Join Date
    May 2003
    Posts
    8

    Actionscript to close an .SWF file.

    Is it possible to apply actionscript to a button that when pressed will close an .SWF file?

    (example as to why one may want to use this action: Someone is watching a movie you’ve made to open and play in fullscreen mode. They may be unaware of the need to press the ESC key to reduce the window at the end of the movie. The button would give them an obvious and easy escape route.

    If this can be produced, and you’re up for it, would you please run me through the complete procedure (bearing in mind I’m a Flash novice) of what the script is and how/where to apply it to perform this action?

    Thanks in advance.

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    You can try this. Put it on the close button.

    on (release) {
    getURL("javascript:window.close();void(0);");
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    Junior Member
    Join Date
    May 2003
    Posts
    8
    Originally posted by pellepiano
    You can try this. Put it on the close button.

    on (release) {
    getURL("javascript:window.close();void(0);");
    }

    Thanks a lot... I'll try it right now.

  4. #4
    Junior Member
    Join Date
    May 2003
    Posts
    8
    Ok, the close window script you gave is to do with closing a webpage window & I failed to mention that I am dealing only with .SWF files that are viewed with the Flash internal player that can be sent and viewed by other people with the Flash programme.

    Is there an actionscript for this situation?

  5. #5
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Then it depends on if you are loading into levels ot target movieclips.
    You might consider making a projector file too, as people dont need the Flashplayer to view it. then

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  6. #6
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    If you mean closing the main ( and only) swf file.

    on(release){
    fscommand("quit");
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  7. #7
    Junior Member
    Join Date
    May 2003
    Posts
    8
    Originally posted by pellepiano
    If you mean closing the main ( and only) swf file.

    on(release){
    fscommand("quit");
    }
    You told me exactly what I needed to know... Excellent... Thanks a lot.

  8. #8
    Member
    Join Date
    Dec 2007
    Posts
    71

    Unhappy Close button

    Hi,

    I've tried using the fscommand("quit"); but it wont work for me.

    I have an X which I turned into a button symbol and named the instance close_btn. Then in the main Actionscript frame I put the following:

    close_btn.onRelease = function() {
    fscommand("quit");
    }

    When I render into a swf by pressing ctrl + enter, the button doesn't work. (I have applied a color change at rollover in the button itself and that works but not the close command that is in the main actionscript). Also, when I change the above code to read:

    getURL("javascript:window.close();"); instead of fscommand("quit"); - this tends to work in the sense that it opens a browser and then tries to close it, giving me a prompt. But I am trying to close the swf. I have a feeling that it will work in exe projector - why isn't it working in swf? I am working in FLA 9, with publishing settings set on Actionscript 1 & 2. Should this setting be different?

    Thanks.

  9. #9
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Its for standalone player use, not for swf embedded in a html page.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  10. #10
    Member
    Join Date
    Dec 2007
    Posts
    71

    Talking Thanks pellepiano

    Thanks for the input. The only thing is that the fscommand seems to work in the EXE without a problem, and the other buttons toggle in the swf, but the "X" doesn't close, although it toggle to a different colored like I've programmed it to. In EXE everything works. Even the javascript close window function worked when I clicked on the "X" in the swf. I just think that it may be a bug. I will try downshifting to Flash 8 (this has worked for me before on a different occassion). I will report a success if one was acheived.

    Thanks again, and don't give up on me...

  11. #11
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    An exe is a standalone player ( projector ) so it will work there, as its supposed to. But not when the swf is embedded in html.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  12. #12
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Just in case someone finds this thread and still needs an answer...

    I believe that in order to close the containing browser window you could use ExternalInterface like so:

    if(ExternalInterface.available){
    ExternalInterface.call("javascript:window.close(); void(0);");
    }

  13. #13
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Correction

    I tested this and determined that this is the best way to accomplish closing the containing browser window:

    getURL("javascript:window.opener=self;window.close ();");

  14. #14
    Junior Member
    Join Date
    Apr 2010
    Posts
    19
    Hi all !

    I was searching over the net google and forums and I still didn't get my problem solved.

    What Im trying to do is:

    1-I have a Flash website

    2-inside of my flash website I created a section where the user will be clicking on a picture and an swf movie pop's up and become a slide show swf movie.

    3- I created the slide show and saved it in SWF format and its called genova.swf

    4-I created a button (called in instance g1_btn)over the picture in my main website and in the actions layer I insterted the following script:

    g1_btn.onRelease = function () {
    loadMovie("genova.swf",3);
    }

    5- in the .fla file where the slide shows has been made, i created a button with an "X" shape and inserted the following script into its action:

    on (release) {
    getURL("javascript:window.opener=self;window.close ();");
    }


    The problem

    I go to my website, I click on the picture and a popup comes out, its my genova.swf slideshow and its over my main website not in a separated window witch I want so ! Ok... now I need to close this slide show so I press on its "X" button, and unfortunately the whole window closes including my website.

    QUESTION:

    How can I ONLY close the swf slideshow without having to close the whole browser ?

    Thanks in advance.

  15. #15
    :
    Join Date
    Dec 2002
    Posts
    3,518
    'genova' has a button on the first frame of the main timeline, instance name 'close_btn' (no code on this button)

    This code goes in the file that loads 'genova'.
    Code:
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(this);
    
    function onLoadInit(mc:MovieClip) {
    	mc.close_btn.onRelease = function() {
    		mcLoader.unloadClip(mc);
    	};
    }
    g1_btn.onRelease = function() {
    	mcLoader.loadClip("genova.swf",3);
    };

  16. #16
    Junior Member
    Join Date
    Apr 2010
    Posts
    19
    @ dawsonk:

    Thanks a lot matey !
    The method you posted works perfectly well.

    Cheers

  17. #17
    Junior Member
    Join Date
    Apr 2010
    Posts
    19
    Quote Originally Posted by dawsonk View Post
    'genova' has a button on the first frame of the main timeline, instance name 'close_btn' (no code on this button)

    This code goes in the file that loads 'genova'.
    Code:
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(this);
    
    function onLoadInit(mc:MovieClip) {
    	mc.close_btn.onRelease = function() {
    		mcLoader.unloadClip(mc);
    	};
    }
    g1_btn.onRelease = function() {
    	mcLoader.loadClip("genova.swf",3);
    };

    Thanks Matey it worked perfectly well ! really nice

    Now I was wondering ... i would like to know if:

    1- I can make the picture in the main site go to specific frame in genova.swf without have to pass by the first one.

    2- I need to have genova.swf opening and blocking the use of the buttons in the main site when its still open unless user closes it with the "X" button.


    Thanks again

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center