By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

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

P: 3
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:

Expand|Select|Wrap|Line Numbers
  1. on press{
  2. unloadMovie (1);
  3. }
..or...

Expand|Select|Wrap|Line Numbers
  1. on press{
  2. unloadMovie (".swf");
  3. }
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).

Expand|Select|Wrap|Line Numbers
  1. on (release) { 
  2. if (_root.currMovie == undefined) { 
  3. _root.currMovie = "main"; 
  4. container.loadMovie("main.swf"); 
  5. } else if (_root.currMovie != "main") { 
  6. if (container._currentframe >= container.midframe) { 
  7. _root.currMovie = "main"; 
  8. container.play(); 
  9.  
-----------------------------------------------------------------------------------
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(_root.currMovie+".swf")
------------------------------------------------------------------------------------

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.
Sep 4 '07 #1
Share this Question
Share on Google+
6 Replies


xNephilimx
Expert 100+
P: 213
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:

Expand|Select|Wrap|Line Numbers
  1. var home:MovieClip = this;
  2.  
  3. //to load:
  4. var movie:MovieClip = home.container.loadMovie(home.currMovie);
  5.  
  6. //to unload:
  7. home.container.unloadMovie(movie);
  8.  
  9. //------------- OR -------------
  10.  
  11. //to unload:
  12. home.container.unloadMovie(home.currMovie);
  13.  
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


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:

Expand|Select|Wrap|Line Numbers
  1. on press{
  2. unloadMovie (1);
  3. }
..or...

Expand|Select|Wrap|Line Numbers
  1. on press{
  2. unloadMovie (".swf");
  3. }
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).

Expand|Select|Wrap|Line Numbers
  1. on (release) { 
  2. if (_root.currMovie == undefined) { 
  3. _root.currMovie = "main"; 
  4. container.loadMovie("main.swf"); 
  5. } else if (_root.currMovie != "main") { 
  6. if (container._currentframe >= container.midframe) { 
  7. _root.currMovie = "main"; 
  8. container.play(); 
  9.  
-----------------------------------------------------------------------------------
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(_root.currMovie+".swf")
------------------------------------------------------------------------------------

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.
Sep 6 '07 #2

P: 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.



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:

Expand|Select|Wrap|Line Numbers
  1. var home:MovieClip = this;
  2.  
  3. //to load:
  4. var movie:MovieClip = home.container.loadMovie(home.currMovie);
  5.  
  6. //to unload:
  7. home.container.unloadMovie(movie);
  8.  
  9. //------------- OR -------------
  10.  
  11. //to unload:
  12. home.container.unloadMovie(home.currMovie);
  13.  
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
Sep 6 '07 #3

elamberdor
P: 39
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:)
Expand|Select|Wrap|Line Numbers
  1. this.onEnterFrame = function() {
  2.     if (swf_loader._alpha = 100) {
  3.         swf_loader._alpha = 0;
  4.     }
  5. };
  6.  
or is levels better?
Thanks!
=)
Sep 6 '07 #4

xNephilimx
Expert 100+
P: 213
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

Expand|Select|Wrap|Line Numbers
  1. on(release) {
  2.     _root.container.unloadMovie();
  3. }
  4.  
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:

Expand|Select|Wrap|Line Numbers
  1. //frame with code
  2. /*what you wanted to do is a button to toggle the display?
  3. 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.
  4. */
  5.  
  6. toggleBtn.onRelease = function() {
  7.     if(swf_loader._visible = true) {
  8.         swf_loader._visible = false;
  9.     } else {
  10.         swf_loader._visible = true;
  11.     }
  12. }
  13.  
  14.  
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

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.
Sep 6 '07 #5

elamberdor
P: 39
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..
Expand|Select|Wrap|Line Numbers
  1. _root.swf_loader.loadMovie("flash/blank_movie_with_no_buttons.swf");
  2. _root.stop();
  3.  
I know I know it's a terrible option, but for any future projects I will definitley plan them better with that way!
Thanks!!
=)
Sep 16 '07 #6

elamberdor
P: 39
I will definitley plan them better with that way!
I mean not my way!
=)
Sep 16 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.