Close button for External SWF's (Without loss of Container)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikes8arms
    New Member
    • Aug 2007
    • 3

    Close button for External SWF's (Without loss of Container)

    Version: Flash MX (A.S. 2.0)

    Hello.

    I haven't posted since signing on a few weeks ago. I've searched your site seeking an answer or answers to the concept of creating a "close button" for my external swf's. I've also searched engines; Ask.com, Yahoo.com, Lycos.com, etc.. I've tried the following methods of code as solutions, with no success:

    Code:
    on press{
    unloadMovie (1);
    }
    ..or...

    Code:
    on press{
    unloadMovie (".swf");
    }
    Here is the actual code for both the "main swf" (my homepage) and all external swf's which also contain my navigation buttons (about, contact, home = main.swf, etc).

    Code:
    on (release) { 
    if (_root.currMovie == undefined) { 
    _root.currMovie = "main"; 
    container.loadMovie("main.swf"); 
    } else if (_root.currMovie != "main") { 
    if (container._currentframe >= container.midframe) { 
    _root.currMovie = "main"; 
    container.play(); 
    } 
    } 
    }
    -----------------------------------------------------------------------------------
    For all external swf's the code..

    First Frame A.S.: (Intro)
    is whatever mid-frame number is (ex: 28)

    Middle Frame A.S.: (Mid)
    stop();

    End Frame A.S.: (Outro)
    _root.container .loadMovie(_roo t.currMovie+".s wf")
    ------------------------------------------------------------------------------------

    My objective is to create a " close button" or "x", right upper corner of each external swf, when clicked will close that individual swf, WITHOUT CLOSING the container or access to container on "main swf', leaving me with the ability to open that same swf again, after closing it. Some code that I received allowed me to "close" an swf but when I selected a different swf on my "main" stage, none of the other buttons (swf's) would respond to button click. I hope I've explained this well enough, if not please come back with question(s).

    Thanks,
    mikes8arms.
  • xNephilimx
    Recognized Expert New Member
    • Jun 2007
    • 213

    #2
    Hi, mikes8arms.
    you should load the movie into a variable, so you can use that variable to reference the movie and then use the unloadMovie with that variable, like this:

    [CODE=actionscri pt]
    var home:MovieClip = this;

    //to load:
    var movie:MovieClip = home.container. loadMovie(home. currMovie);

    //to unload:
    home.container. unloadMovie(mov ie);

    //------------- OR -------------

    //to unload:
    home.container. unloadMovie(hom e.currMovie);
    [/CODE]

    Two things, notice that i didn't used the _root directly, that prevents the movie for confusing the root if its going to be loaded inside another movie.
    Also try not to code in the actual buttons or movieclips, code in the frames, using the instance name of the objectos to make reference to them.

    Kind regards,
    The_Nephilim


    Originally posted by mikes8arms
    Version: Flash MX (A.S. 2.0)

    Hello.

    I haven't posted since signing on a few weeks ago. I've searched your site seeking an answer or answers to the concept of creating a "close button" for my external swf's. I've also searched engines; Ask.com, Yahoo.com, Lycos.com, etc.. I've tried the following methods of code as solutions, with no success:

    Code:
    on press{
    unloadMovie (1);
    }
    ..or...

    Code:
    on press{
    unloadMovie (".swf");
    }
    Here is the actual code for both the "main swf" (my homepage) and all external swf's which also contain my navigation buttons (about, contact, home = main.swf, etc).

    Code:
    on (release) { 
    if (_root.currMovie == undefined) { 
    _root.currMovie = "main"; 
    container.loadMovie("main.swf"); 
    } else if (_root.currMovie != "main") { 
    if (container._currentframe >= container.midframe) { 
    _root.currMovie = "main"; 
    container.play(); 
    } 
    } 
    }
    -----------------------------------------------------------------------------------
    For all external swf's the code..

    First Frame A.S.: (Intro)
    is whatever mid-frame number is (ex: 28)

    Middle Frame A.S.: (Mid)
    stop();

    End Frame A.S.: (Outro)
    _root.container .loadMovie(_roo t.currMovie+".s wf")
    ------------------------------------------------------------------------------------

    My objective is to create a " close button" or "x", right upper corner of each external swf, when clicked will close that individual swf, WITHOUT CLOSING the container or access to container on "main swf', leaving me with the ability to open that same swf again, after closing it. Some code that I received allowed me to "close" an swf but when I selected a different swf on my "main" stage, none of the other buttons (swf's) would respond to button click. I hope I've explained this well enough, if not please come back with question(s).

    Thanks,
    mikes8arms.

    Comment

    • mikes8arms
      New Member
      • Aug 2007
      • 3

      #3
      Hello xNephilimx,

      Thanks for your response. I should have included a bit more information in reference to my level of Flash/A.S. experience. Unfortunately I'm not an "expert" like yourself, I'm hanging on the label of intermediate flasher with varied actionscript experience. Having said that, questions to your response with code:

      1. Is the code you provided to be a replacement of the orginal code I used (Kirupa.com tutorial)?

      2. Is your code for my "main.swf" (homepage) or is this for the externals?

      3. If your response is YES to the above, then this would entain rewriting the original code?

      Thanks again,
      mikes8arms.



      Originally posted by xNephilimx
      Hi, mikes8arms.
      you should load the movie into a variable, so you can use that variable to reference the movie and then use the unloadMovie with that variable, like this:

      [CODE=actionscri pt]
      var home:MovieClip = this;

      //to load:
      var movie:MovieClip = home.container. loadMovie(home. currMovie);

      //to unload:
      home.container. unloadMovie(mov ie);

      //------------- OR -------------

      //to unload:
      home.container. unloadMovie(hom e.currMovie);
      [/CODE]

      Two things, notice that i didn't used the _root directly, that prevents the movie for confusing the root if its going to be loaded inside another movie.
      Also try not to code in the actual buttons or movieclips, code in the frames, using the instance name of the objectos to make reference to them.

      Kind regards,
      The_Nephilim

      Comment

      • elamberdor
        New Member
        • Mar 2007
        • 39

        #4
        Hi Hello!

        That sounds cool!!!!

        Say if your loading your external Swf's into one movie,
        how can you then adapt that script you have just written xNx to have a hide/dissapear function for that loaded movieclip - on an enter frame function?

        So it kinda works like this: (bad bad baaad example:)
        [code=actionscri pt]
        this.onEnterFra me = function() {
        if (swf_loader._al pha = 100) {
        swf_loader._alp ha = 0;
        }
        };
        [/code]

        or is levels better?
        Thanks!
        =)

        Comment

        • xNephilimx
          Recognized Expert New Member
          • Jun 2007
          • 213

          #5
          You're welcome.
          The code I gave you was an example of how could this be achieved, it isn't supposed to replace your code, but to combine with it. I'm sorry, I thought you would be able to put it togheter. I also forgot to tell you to be carefull with the variables environment (like if a variable is declared inside a function it can't be used outside that function).
          The code was entended for your main movie only.
          I also don't know why are you putting the navigation buttons in your home and in all your other movies... that doesn't sound correct.
          Anyway, here's a more intuitive version of the code you should attach to yours. The code to close a recently opend movie with the loadMovie, you can leave the code the way you did, just add this to the close button

          [CODE=actionscri pt]
          on(release) {
          _root.container .unloadMovie();
          }
          [/CODE]

          that way, any movie taht was loaded into the container movieclip will be unloaded.

          And hi elamberdor! How r u doing?
          Yes, something like that can be done, remember that the code in the first response to this post, was supposed to be for the ones that code in frames not in movieclips or buttons, so let's say you are writing that in the first frame,it should be like this:

          [CODE=actionscri pt]
          //frame with code
          /*what you wanted to do is a button to toggle the display?
          if that is the case, don't use onEnterFrame, remember that onEnterFrame will repeat endlessly untill you delet it or deactivate it eventually. So what you did will enter in an endless loop with no possible solution toggling the movie constantly and -after one or two seconds- will just crash.
          */

          toggleBtn.onRel ease = function() {
          if(swf_loader._ visible = true) {
          swf_loader._vis ible = false;
          } else {
          swf_loader._vis ible = true;
          }
          }

          [/CODE]

          Notice that I didn't use _alpha, that is because even if something has alpha 0 that only means that it will not be visible, but any buttons, textareas and stuff it has will still be clickable/writable/usable so it will interfere with the movie, it will still be there, but transparent, in contrast with _visible that totally hides it and all of its content functionality.

          Best regards,
          The_Nephilim

          Originally posted by mikes8arms
          Hello xNephilimx,

          Thanks for your response. I should have included a bit more information in reference to my level of Flash/A.S. experience. Unfortunately I'm not an "expert" like yourself, I'm hanging on the label of intermediate flasher with varied actionscript experience. Having said that, questions to your response with code:

          1. Is the code you provided to be a replacement of the orginal code I used (Kirupa.com tutorial)?

          2. Is your code for my "main.swf" (homepage) or is this for the externals?

          3. If your response is YES to the above, then this would entain rewriting the original code?

          Thanks again,
          mikes8arms.

          Comment

          • elamberdor
            New Member
            • Mar 2007
            • 39

            #6
            Hi, xNephilimx!

            Helpful as always!
            Well, for that project, I kind of bandaided an answer:
            Just loaded in a blank movie for the other menu pages..
            [code=actionscri pt]
            _root.swf_loade r.loadMovie("fl ash/blank_movie_wit h_no_buttons.sw f");
            _root.stop();
            [/code]
            I know I know it's a terrible option, but for any future projects I will definitley plan them better with that way!
            Thanks!!
            =)

            Comment

            • elamberdor
              New Member
              • Mar 2007
              • 39

              #7
              Originally posted by elamberdor
              I will definitley plan them better with that way!
              I mean not my way!
              =)

              Comment

              Working...