Jump to content
Search Community

3 Tweens, 1 btn, 2 mc 3 states can't get last one to hold

ctnc test
Moderator Tag

Recommended Posts

Hello.

 

I am trying to control 2 mc each containing 3 images to respond to postions on the stage when 4 different invisible btns are mouse_over, mouse_out and click. I want the tween to hold position till the second click on the same button. Can this be done? Any help will be greatly appreciated. Thanks in advance.

 

-c.

 

import com.greensock.*;
import com.greensock.core.*;

import flash.utils.*;
import com.greensock.easing.*;

//cursor
//need to figure this out
//Legend
legend_mc.navigation_btn.addEventListener(MouseEvent.CLICK, clickL);

function clickL(event:MouseEvent):void{
if(legend_mc.currentFrame <<2) {
legend_mc.play();
} else{
legend_mc.gotoAndPlay(20);
}
}
//Farm
slideFarm.addEventListener(MouseEvent.MOUSE_OVER,onOverFarm)
     function onOverFarm(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:-780, y:0});        
    }
slideFarm.addEventListener(MouseEvent.MOUSE_OUT,onOutFarm)
     function onOutFarm(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:-760, y:0});        
   var myTween:TweenMax = new TweenMax(middle_mc, .25, {x:-760, y:0});
  }
slideFarm.addEventListener(MouseEvent.CLICK,onClickFarm)
     function onClickFarm(event:MouseEvent):void {
TweenMax.to(middle_mc, 1.25, {x:-1520, y:0});     

middle_mc.slideBackFarm.addEventListener(MouseEvent.CLICK,onClickBackFarm)
     function onClickBackFarm(event:MouseEvent):void {
TweenMax.to(middle_mc, 1.25, {x:-760, y:0}); 
  }}

//Coral
slideCoral.addEventListener(MouseEvent.MOUSE_OVER,onOverCoral)
     function onOverCoral(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:-740, y:0});        
    }
slideCoral.addEventListener(MouseEvent.MOUSE_OUT,onOutFarm)
     function onOutCoral(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:760, y:0});        
TweenMax.to(middle_mc, .25, {x:-760, y:0});        
var myTween:TweenMax = new TweenMax(middle_mc, .25, {x:-760, y:0});
  }
slideCoral.addEventListener(MouseEvent.CLICK,onClickCoral)
     function onClickCoral(event:MouseEvent):void {
TweenMax.to(middle_mc, 1.25, {x:0, y:0});     
  }
//Beach
slideBeach.addEventListener(MouseEvent.MOUSE_OVER,onOverBeach)
     function onOverBeach(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:-760, y:-20});
TweenMax.to(middleVert_mc, .25, {x:0, y:-490});  
    }
slideBeach.addEventListener(MouseEvent.MOUSE_OUT,onOutBeach)
     function onOutBeach(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:-760, y:0});
TweenMax.to(middleVert_mc, .25, {x:0, y:-460});  
} 
slideBeach.addEventListener(MouseEvent.CLICK,onClickBeach)
     function onClickBeach(event:MouseEvent):void {
TweenMax.to(middle_mc, 1.25, {x:-760, y:-460});
TweenMax.to(middleVert_mc, 1.25, {x:0, y:-920});  
    }
//Estuary
slideEstuary.addEventListener(MouseEvent.MOUSE_OVER,onOverEstuary)
     function onOverEstuary(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:-760, y:20});
TweenMax.to(middleVert_mc, .25, {x:0, y:-440});  
    }
slideEstuary.addEventListener(MouseEvent.MOUSE_OUT,onOutEstuary)
     function onOutEstuary(event:MouseEvent):void {
TweenMax.to(middle_mc, .25, {x:-760, y:0});
TweenMax.to(middleVert_mc, .25, {x:0, y:-460});  
    }
slideEstuary.addEventListener(MouseEvent.CLICK,onClickEstuary)
     function onClickEstuary(event:MouseEvent):void {
TweenMax.to(middle_mc, 1.25, {x:-760, y: 460});
TweenMax.to(middleVert_mc, 1.25, {x:0, y: 0});  
}

Link to comment
Share on other sites

I don't quite understand your objective, but I'll mention a few things I noticed:

 

1) You're creating multiple conflicting tweens of the same object - why? For example:

BAD:

TweenMax.to(middle_mc,.25,{x:760,y:0});
TweenMax.to(middle_mc,.25,{x:-760,y:0});
var myTween:TweenMax=new TweenMax(middle_mc,.25,{x:-760,y:0});

 

Only the last one will work. Are you trying to sequence these? If so, you need to either delay the 2nd and 3rd one so that the tweens start one-after-the-other, or use TimelineLite or TimelineMax and append() each one. http://www.greensock.com/timeline-basics/

 

2) Be very careful about using MOUSE_OVER/MOUSE_OUT instead of ROLL_OVER/ROLL_OUT because the former can be called many times during one rollover (every time a child is rolled over/out, MOUSE_OVER/MOUSE_OUT will be called)

 

3) Did you really mean to say "if (legend_mc.currentFrame

Link to comment
Share on other sites

hello. Thank you for helping me, I am a bit lost

 

Okay using multiple tweens is bad, but what if you want to control a movieclip several different ways? Roll_Over, Roll_Out, Click etc at different x:y locations.

 

I have tried the timelineLite and I want to use labels to control a part of the MC but I can't seem to make it work.

 

I am essentially trying to make this happen with my code:

 

an invisible button exists, when the user rolls over it they get to see a sneak peak of what is to come and when they roll out it goes away but if they click on it the whole MC plays and stops. Something like (this http://www.dayswithmyfather.com/)

 

the new code that does not work:

var timeline:TimelineLite = new TimelineLite();

timeline.insert(TweenLite.to(middle_mc, .25, {x:-760, y:0}));

 

slideFarm_btn.addEventListener(MouseEvent.ROLL_OVER, minSlide);

slideFarm_btn.addEventListener(MouseEvent.ROLL_OUT, minSlideOut);

 

timeline.addLabel("farmRoll",{x:-780, y:0});

 

function minSlide(event:MouseEvent):void {

timeline.gotoAndPlay("farmRoll");

}

 

function minSlideOut(event:MouseEvent):void {

timeline.reverse();

}

 

THANK YOU IN ADVANCE FOR ANY LIGHT YOU CAN SHED MY DIRECTION.

 

-c

Link to comment
Share on other sites

When you add a label, it has nothing to do with controlling the position - you did timeline.addLabel("farmRoll",{x:-780, y:0}) and for the time you used {x:-780, y:0} - that's not a time. Actually, I'm not even sure you should be using TimelineLite/Max here since it sounds like your values will be quite dynamic. TimelineLite/Max are for layout out linear sequences.

 

Frankly, since I'm not sure exactly what your FLA looks like or what you're trying to accomplish, I can't give you specific code. But it's probably best to just fire off new tweens when you need to instead of creating a linear sequence in a TimelineLite or TimelineMax.

Link to comment
Share on other sites

You must zip your files before posting them, that's all.

 

Oh, and be very careful about using MOUSE_OVER/MOUSE_OUT instead of ROLL_OVER/ROLL_OUT. A lot of people make that mistake and it can lead to odd behavior (MOUSE_OVER/MOUSE_OUT can fire many times on a single rollover of an object because they fire whenever the mouse rolls over/out of any of the object's children).

Link to comment
Share on other sites

Awesome, Yes I have heard that about mouse_out and mouse_over, Thanks! Is there a time you should use one over the other or always just use Roll_Over/Out?

 

Here is my file to give visual reference to the code I am having trouble with.

 

Many, Many Thanks!

C

Link to comment
Share on other sites

Sorry, I don't have time to pick this all apart and rebuild it for you properly - if you have a specific question about a particular part of this, I'd be happy to address that. You still have lots of competing tweens that you're creating at the same time which baffles me. Here's an example excerpt from your code:

 

BAD:

TweenLite.to(middle_mc, .25, {x:760, y:0});        
TweenLite.to(middle_mc, .25, {x:-760, y:0});        
var myTween:TweenLite = new TweenLite(middle_mc, .25, {x:-760, y:0});

 

So you're telling middle_mc.x to go to 760 AND you're telling it to go to -760 AND you're telling it to go to -760 again. Like I said, if you're trying to sequence things, you need to either use the "delay" property or use a TimelineLite or TimelineMax instance. If you're not trying to sequence things, I have no idea what that code was supposed to do. You watched the video at http://www.greensock.com/get-started-tweening/?

Link to comment
Share on other sites

Apologizes, I never intended for you to go through the whole thing or fix the code, I just wanted you to play the file so you could see the three tweens and why I have them that way because explaining it in words is complicated.

 

Nevermind, I'll do it without TweenLite, Thanks

-c

Link to comment
Share on other sites

After re-reading my post, I think that came across as more abrasive/frustrated than I intended. I wanted to help and was having a hard time deciphering the goal of your code, that's all, and that may very well be caused by my own thick-headedness. You don't need to do it without TweenLite - switching tweening engines won't solve the logic problems. I'd recommend backing up and trying to get something very simple working before you add a lot of moving parts. That way if you run into trouble, you can isolate it and ask a specific question that'll be easier for folks to troubleshoot.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...