A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Please - need help how to make a close button

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    16

    Please - need help how to make a close button

    Hi,

    I have some simple animation.
    I want to add to it a close button (X) that will close the SWF when i click on it.

    It's possible? i really need it.

    Thanks for the help!!

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    If it is for a flash standalone executable, you can use fscommand("quit");

    If it is for an animation on an html website, you can use
    on (release) {
    getURL("javascript:window.opener=self;window.close ();");
    }
    on the button.

    If it is for a Flash website (AS2), then you can load the SWF inside an empty movieclip, and when you press the "[X]" button or whatever trigger, you can either remove the movieclip (if it was created dynamically):

    _root.myContainer.removeMovieClip();

    or put it visible

    on(release)
    {
    _root.myContainer._visible = false;
    }
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    16
    Hi,
    Thanks a lot for your reply!
    I want to close the SWF window after i make publish - so i should use the first command you wrote: fscommand("quit"); ?
    I just copy it to the Action window of my button?
    Sorry - i don't know AS2 very well.

    Thanks again.

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    The fscommand("quit") it's only for a standalone flash projector, it's like a program, an application. When you publish the movie, it plays the swf file, so there is no way of closing the swf file with actionscript.

    If you want your animation to be run like a program in any computer, then you have to publish your movie as a Windows or Mac Projector in the flash publish options menu and use the The fscommand("quit") in the action window of your button.

    If you want your animation to be viewed in a website, then you have to make an empty swf that will act as a container, and then load your animation .swf file inside an empty movieclip, then when pressing the [X] button, it will closes or remove the loaded swf.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    You may want to create a flash projector, so users can download your animation an view it in their computers, and then you can have the [X] close button to close the flash projector. Also, you may want to give users the SWF file embeded within a html (web) file. This method doesn't need the close button, because the html file already has one, so the user close the html file on the [X], and the SWF is also closed.

    The last method is to embed the swf in a html page, and host it in a server, and users will view your animation directly on the web with any browser(chrome, firefox, etc.) This method doesn't need a close button either, because the html page has it.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Missed this one,

    There are things you can do, if you have the swf in a div, you can hide it, like so.

    In the swf file have a button or use it at the end of your animation by calling the function!!
    PHP Code:
    import flash.external.*;

    myButton.onPress = function()
    {
        
    ExternalInterface.call("hideFlash");
    }; 
    and inside your html page
    Code:
    <script type="text/javascript">
    function hideFlash() 
    {
       document.getElementById("myFlashDiv").style.display = "none";
    }
    </script>
    you could probably remove the div by using some sort of DOM code, but I haven't looked into it so far.

    If you are using <param name="wmode" value="transparent" /> within your html embed tags then you could also just make the swf go back to frame 1, where frame 1 has nothing in it, swf on top with no background, using z-index:

    z-index: is kind of the layering within flash, 0 is the base level.

  7. #7
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Hi fruitbeard

    I didn't miss that. I just didn't mention it because our friend didn't talk about embeding the SWF in an html, he/she wanted just to "close the SWF when TEST MOVIE" in flash (thing that , as i know, is not possible). So I gave him/her some possible solutions, and i was waiting feedback from him/she in order to help further. I already knew about closing the swf inside an html page with ExternalInterface.call("hideFlash"); but i don't think he/she were planning about embeding the swf... but now he/she has ALL the recipe from both of us take care
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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