04-28-2012, 03:59 PM
|
#1
|
|
Registered User
Join Date: Apr 2011
Posts: 10
|
Move tween back and forward
I am trying this simple animation but I am unable to get it right. I want my movie clip to move forward and backward and stop at a point for each button. Buttons 1-5 each have a stopping point.
I attached the file.
Basically, if I click 4, I want the playhead to move to that frame either back or forward, depending on where it is. Here is the code that doesn't work:
ActionScript Code:
stop();
step1_btn.addEventListener(MouseEvent.CLICK, step1);
step2_btn.addEventListener(MouseEvent.CLICK, step2);
step3_btn.addEventListener(MouseEvent.CLICK, step3);
step4_btn.addEventListener(MouseEvent.CLICK, step4);
step5_btn.addEventListener(MouseEvent.CLICK, step5);
function step1(e:Event):void {
if (currentFrame <= 1 && currentFrame > 121) {
prevFrame();
} else {
stop();
}
}
function step2(e:Event):void {
if (currentFrame < 21 && currentFrame > 101) {
prevFrame();
} else if (currentFrame <= 1 && currentFrame > 19){
play();
} else {
stop();
}
}
function step3(e:Event):void {
if (currentFrame < 41 && currentFrame > 101) {
prevFrame();
} else if (currentFrame <= 1 && currentFrame > 39){
play();
} else {
stop();
}
}
function step4(e:Event):void {
if (currentFrame < 61 && currentFrame > 101) {
prevFrame();
} else if (currentFrame <= 1 && currentFrame > 59){
play();
} else if (currentFrame == 60){
stop();
}
}
function step5(e:Event):void {
if (currentFrame < 81 && currentFrame > 101) {
prevFrame();
} else if (currentFrame <= 1 && currentFrame > 79){
play();
} else {
stop();
}
}
I really need some help please! I have tried many methods and none are working for me.
Last edited by shelleyh; 04-28-2012 at 04:03 PM.
|
|
|
04-28-2012, 09:34 PM
|
#3
|
|
Site Contributor
Join Date: Jun 2006
Posts: 3,160
|
Snickelfitz,
I don't know if you downloaded and/or looked at the file, but shelleyh here is using Flash's timeline for the tweens. I don't think TweenMax can tween Flash's playhead, or can it? You seem to be saying so, but I think you mean that TweenMax can easily tween its OWN playhead for a given tween.
shelleyh,
So, I too would recommend doing scripted tweens using TweenMax, as it's much easier to do effects like reversing the playback. But to do so, you would have to give up your current approach of using Flash's timeline to do your animations. For example, instead of using Flash's timeline to make your blueIndicator object expand and contract, you would get rid of the timeline tween, and just use TweenMax to tween its width.
Also, the reason your code isn't working is because your code is inside the menu_mc MovieClip, but all your buttons are one level up in the main timeline. You have to either provide the correct path to the buttons, or (better) move the code to the main timeline so that it's in the same scope as the buttons.
|
|
|
04-28-2012, 10:19 PM
|
#4
|
|
Senior Member
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,888
|
Yeah, TweenMax can move the playhead within a MovieClip with the "frame" property.
Can be used to alter the duration of a timeline tween, make it "yoyo", loop a specific number of times, run backwards, etc...
Another useful feature is the ability to call methods at the start and/or end of the tween.
|
|
|
04-28-2012, 10:21 PM
|
#5
|
|
TweenMax Salesman
Join Date: Jan 2012
Posts: 474
|
Quote:
Originally Posted by Mazoonist
Snickelfitz,
I don't know if you downloaded and/or looked at the file, but shelleyh here is using Flash's timeline for the tweens. I don't think TweenMax can tween Flash's playhead, or can it? You seem to be saying so, but I think you mean that TweenMax can easily tween its OWN playhead for a given tween.
|
No, snickelfitz is correct - TweenMax can tween a movieclip's timeline back and forth via FramePlugin.
|
|
|
04-28-2012, 10:34 PM
|
#6
|
|
Site Contributor
Join Date: Jun 2006
Posts: 3,160
|
Okay, just checked it out. I guess I am giving away that I have been neglecting the greensock library, or I would have known.
Anyway, yeah, the property is either frameForward or frameBackward, not frame, and it does indeed work if you activate the plugin(s), which are the FrameForwardPlugin and the FrameBackwardPlugin.
|
|
|
04-28-2012, 11:11 PM
|
#7
|
|
Senior Member
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,888
|
Interesting, I've always used frame; maybe an update I haven't downloaded.
frame still works though.
ActionScript Code:
import com.greensock.*;
TweenMax.to(mc, 1, {frame:mc.totalFrames, yoyo:true, repeat:-1});
|
|
|
04-29-2012, 02:44 PM
|
#8
|
|
Registered User
Join Date: Apr 2011
Posts: 10
|
Well, I don't know anything about TweenMax but I seemed to get this working:
ActionScript Code:
import com.greensock.*;
import com.greensock.easing.*;
stop();
menu_mc.step1_btn.addEventListener(MouseEvent.CLICK, step1);
menu_mc.step2_btn.addEventListener(MouseEvent.CLICK, step2);
menu_mc.step3_btn.addEventListener(MouseEvent.CLICK, step3);
menu_mc.step4_btn.addEventListener(MouseEvent.CLICK, step4);
menu_mc.step5_btn.addEventListener(MouseEvent.CLICK, step5);
function step1(e:Event):void {
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.09});
}
function step2(e:Event):void {
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.3});
}
function step3(e:Event):void {
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.5});
}
function step4(e:Event):void {
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.71});
}
function step5(e:Event):void {
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.93});
}
The only problem I'm having is that if I go straight from step 1 to step 5 it goes faster than from step 1 to 2 because the amount of seconds. I can live with that.
|
|
|
04-29-2012, 04:06 PM
|
#9
|
|
Registered User
Join Date: Apr 2011
Posts: 10
|
I've changed to this because I needed to add a function to move the main timeline so the content can change.
Thanks for the help.
ActionScript Code:
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.Event;
stop();
menu_mc.step1_btn.addEventListener(MouseEvent.CLICK, stepSelection);
menu_mc.step2_btn.addEventListener(MouseEvent.CLICK, stepSelection);
menu_mc.step3_btn.addEventListener(MouseEvent.CLICK, stepSelection);
menu_mc.step4_btn.addEventListener(MouseEvent.CLICK, stepSelection);
menu_mc.step5_btn.addEventListener(MouseEvent.CLICK, stepSelection);
function stepSelection( pEvent:MouseEvent):void
{
if( pEvent.target == menu_mc.step1_btn )
{
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.09,onComplete:this.gotoAndStop,onCompleteParams:["step1"]});
}
if( pEvent.target == menu_mc.step2_btn )
{
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.3,onComplete:this.gotoAndStop,onCompleteParams:["step2"]});
}
if( pEvent.target == menu_mc.step3_btn )
{
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.5,onComplete:this.gotoAndStop,onCompleteParams:["step3"]});
}
if( pEvent.target == menu_mc.step4_btn )
{
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.71,onComplete:this.gotoAndStop,onCompleteParams:["step4"]});
}
if( pEvent.target == menu_mc.step5_btn )
{
TweenMax.to(menu_mc.bar_mc, 1.5, {scaleX:0.93,onComplete:this.gotoAndStop,onCompleteParams:["step5"]});
}
}
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 01:23 PM.
///
|
|