Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : play clip, remove clip, load new clip


Chris Waters
2/28/2004 11:32:28 PM
I have an empty 'container' MC that has a MovieClip load into it when a
button is pressed.....when another button is pressed, it should play the
fade out tween of the current loaded MovieClip, remove it and then load the
new MovieClip into the container.

I am so close and I've tried all different ways that i can think of to get
it to work. The closest I have got is to do nearly what i want, only the new
movieclip loads and starts playing over the top of the existing movieclip as
it plays its fade out tween, which obviously doesn't look very nice.

Here is the current script I have on a button:

on (release) {
_root.container.cont.gotoAndPlay ("outro"); //"outro" is my fade out
tween//
_root.container.profb.gotoAndPlay ("outro");
_root.container.profc.gotoAndPlay ("outro");
_root.container.car.gotoAndPlay ("outro");

if (done=true) { //done=true is set at the end of the 'outro' sequence,
but does not have any effect at present//
_root.container.cont.unloadMovie ();
_root.container.profb.unloadMovie ();
_root.container.profc.unloadMovie ();
_root.container.car.unloadMovie ();
_root.container.attachMovie ("prof1", "profa", 1); //this loads the new
movieclip that is relevent to the pressed button //
}
}

PLEASE NOTE: all my movieclips are in the same flash file and are not
externally loaded swf's

If anyone has an idea of what i'm trying to do and can help, then i would be
most grateful....further info available if needed.

Regards

Chris W


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.587 / Virus Database: 371 - Release Date: 12/02/04

Chris Waters
2/29/2004 12:16:06 AM
sorry...I do have double = in place but forgot to include that in my last
posting of my code:

if (done==true);


Please help as Im getting a serious headache with this one as i know i'm
close!

:)



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.587 / Virus Database: 371 - Release Date: 13/02/04

Longest
2/29/2004 12:33:41 AM
Obviously you think that "if (done=true)" waits until "done" switches to true.
Thats not the case. It just checks once (at the moment you release the button)
and then executes the code inside the brackets or not.
Try to move the code inside the "if" brackets at the place where you would set
the "done" variable to true.

Greetings, Longest
Chris Waters
2/29/2004 12:40:01 AM
Hi Longest,

firstly, thanks for your suggestion.

however, I can't move the code that's inside the 'if' brackets to the place
where I set done=true because that code inside the 'if' brackets loads the
movieclip that is relevant to the button that was pressed....if i move it to
the place you suggested (which is at the end of every 'outro' sequence of
each movieclip) then it would not know which buton has been pressed and
therefore which movieclip to load

any suggestions?

regards

chris w

Chris Waters
2/29/2004 12:55:28 AM
Hi John

thanks for that...I did have a feeling about the unloadMovie being useless
and knew that loading a movieclip into the same level removes the existing
one.

could yoy please tell me how i can get two actions to take place on one
mouse event. eg.

on (release) {
_root.container.cont.gotoAndPlay ("outro"); //this plays the current
loaded movieclip's 'outro' sequence
_root.container.profb.gotoAndPlay ("outro");
_root.container.profc.gotoAndPlay ("outro");
_root.container.car.gotoAndPlay ("outro");

_root.container.attachMovie ("prof1", "profa", 1); //this loads the new
movieclip
}

however, it instantly loads the new movieclip and does not show the 'outro'
sequence....i need it to wait till the 'outro' sequence has finished playing
before it loads the new movieclip....the closest i had played the 'outro'
sequence but also played the 'intro' sequence of the newly loaded movieclip
at the same time, so you saw them both over the top of each other....not
what i wanted :(

any ideas?

thanks

chris w

stwingy
2/29/2004 12:57:47 AM
I think the method outlined by longest is correct but another way is just to
set up a function to test if done is true.
btn1.onPress = function() {
myInterval = setInterval(checky, 50);
};
function checky() {
if (container.mc2.done == true) {
trace("done");
clearInterval(myInterval);
}
}
//on the last frame of mc2
//this.done = true
Laiverd.COM
2/29/2004 1:47:33 AM
First of all; if all if no movie is external and all are inside the
movieclip then unLoadMovie is useless as this is only for loaded movies not
for attached or duplicated mc's. To remove attached or duped mc's use
removeMovieclip() method. But ... if you attach the to the same movieclip
over and over again; there's no need for a removemovieclip as on each new
attach the old clip will be removed as long as you attach it to the same
depth. So in the following code:

container_mc.attachMovie("Symbol1","blah",1);
black_mc.onRelease = function(){
container_mc.attachMovie("Symbol2","blah1",1);
}

Symbol 2 will replace Symbol 1 because it is attached to the same movieclip
at the same depth.

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Laiverd.COM
2/29/2004 2:34:48 AM
Put:

_root.container.attachMovie ("prof1", "profa", 1); //this loads the new
movieclip

at the end of the outro animation at the point where it's finished. That
would be the easiest solution (depending on the setup, you'd have some
pathadjusting to do, but that shouldn't be too hard). The more complicated
solution would involve continuous checking of _currentframe of the outro and
if that has a certain value, then do the attachmovie.

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

AddThis Social Bookmark Button