Groups | Blog | Home
all groups > flash actionscript > may 2007 >

flash actionscript : Button Controlling Movie Clip


Grim38
5/20/2007 10:34:03 PM
I have a button on the main timeline controlling an animation residing in a
movie clip. I have a mask in the movie clip that opens to show an image when
the button is in the rollOver state. I want the the mask to close on the
rollOut state. If I make a tween with it opening and a tween with it closing,
when the user rollsOut of the button prematurely it jumps to the last portion
of the open animation. I want it to be fluid. I'm not sure how to do this with
actionscript and I want all my code to be on the main timeline. Here is a
sample of the code:

tv_btn.onRollOver = function () {
tv_mc.gotoAndPlay("open");
}
tv_btn.onRollOut = function () {
tv_mc.gotoAndPlay("close");
}
kglad
5/20/2007 11:02:22 PM
often with two opposite tweens (like open and close), there will be a
predictable correspondence between the two tweens.

for example, if the two tweens have the same number of frames, frame 1 of the
open tween may correspond to the last frame of the close tween, frame 2 of the
open tween may correspond to the next to last frame of the close tween etc.
this makes it easy to seemlessly transition between the two tweens even when
one has not completed. do you have such a correspondence?
Grim38
5/20/2007 11:31:33 PM
The problem I'm having is that I need it to close wherever the animation is and
not it to jump to the most open portion and then begin it's close. I think I
need some type of variable or onEnterFrame action somewhere.
Grim38
5/21/2007 12:00:00 AM
Ok, that didn't work. It opens fine of course but the shade doesn't close
onRollOut. Do I need onEnterFrame for this thing to keep firing. I found this
chunk of code but the code is within in the Movie Clip. Is there any way to
alter it for the main timeline?

this.onEnterFrame = function(){

if(rewind == true){

prevFrame();

}

}

this.onRollOver = function(){

rewind = false;
play();

}

this.onRollOut = function(){

rewind = true;

}
kglad
5/21/2007 1:22:34 AM
re-read my above post. you're looking to jump from a given frame in your open
tween to an appropriate frame in your close tween. if the open tween starts on
frame 1, the close tween starts on frame N and the tweens contain the same
number of frames (T) and have the same easing you can use:



tv_btn.onRollOver = function () {
tv_mc.gotoAndPlay("open");
}
tv_btn.onRollOut = function () {
tv_mc.gotoAndPlay(T+N-tv_mc._currentframe);
}
Grim38
5/21/2007 2:29:22 AM
kglad
5/21/2007 3:05:28 AM
1. what frame number is "open"?
2. what frame number is "close"?
3. how many frames in the open tween?
Grim38
5/21/2007 3:27:41 AM
kglad
5/21/2007 3:30:13 AM
use:



tv_btn.onRollOver = function () {
tv_mc.gotoAndPlay("open");
}
tv_btn.onRollOut = function () {
tv_mc.gotoAndPlay(41-tv_mc._currentframe);
kglad
5/21/2007 3:03:22 PM
no, that code will work if tv_mc's 1st frame is the "Open" and it goes to 20.
Frame 21 starts the "Close" animation and reaches frame 40.

post a link to your fla if you can't get the code i gave to work correctly.
Grim38
5/21/2007 3:10:42 PM
Ok this is the water downed version of it. But the .fla can be found here. I've
altered the code a little, feel free to change it anyway you want. Thanks.

http://www.3rdistudio.com/sample_animation.fla
Grim38
5/21/2007 3:34:39 PM
i figured it out, here is the code i used.

tv_mc.onEnterFrame = function(){
if(rewind == true){
tv_mc.prevFrame();
}
}

circle_btn.onRollOver = function(){
rewind = false;
tv_mc.play();
}

circle_btn.onRollOut = function(){
rewind = true;
}

kglad
5/21/2007 3:58:19 PM
Grim38
5/21/2007 4:37:17 PM
kglad
5/21/2007 4:58:53 PM
Grim38
5/21/2007 5:31:07 PM
kglad
5/21/2007 5:36:57 PM
AddThis Social Bookmark Button