Jump to content
Search Community

reverse and mulitple tween

chefkeifer test
Moderator Tag

Recommended Posts

i have a button that i want to get two tweens to append right after the other and then reverse on roll over and rollout.

 

this isnt working not sure how to add that second tween

 

import com.greensock.*;
import com.greensock.plugins.*;
import com.greensock.easing.*;


var btns:Array = [btn1, btn2, btn3, btn4, btn5, btn6];
var activeTween:TweenLite;

for (var i:int = 0; i < btns.length; i++) {
  btns[i].buttonMode = true;
  btns[i].addEventListener(MouseEvent.ROLL_OVER, over);
  btns[i].addEventListener(MouseEvent.ROLL_OUT, out);
}

function over(event:MouseEvent):void {
  activeTween = new TweenLite(event.currentTarget.board1, .25, {x:50});
  activeTween = new TweenLite(event.currentTarget.board2, .25, {x:75});
}

function out(event:MouseEvent):void {
  activeTween.reverse();
}

Link to comment
Share on other sites

It looks like you're tweening two different objects, but you've only got one TweenLite object and you're immediately overwriting it. Maybe you want to do this:

 

import com.greensock.*;
import com.greensock.plugins.*;
import com.greensock.easing.*;


var btns:Array = [btn1, btn2, btn3, btn4, btn5, btn6];
var activeTween1:TweenLite;
var activeTween2:TweenLite;

for (var i:int = 0; i < btns.length; i++) {
  btns[i].buttonMode = true;
  btns[i].addEventListener(MouseEvent.ROLL_OVER, over);
  btns[i].addEventListener(MouseEvent.ROLL_OUT, out);
}

function over(event:MouseEvent):void {
  activeTween1 = new TweenLite(event.currentTarget.board1, .25, {x:50});
  activeTween2 = new TweenLite(event.currentTarget.board2, .25, {x:75});
}

function out(event:MouseEvent):void {
  activeTween1.reverse();
  activeTween2.reverse();
}

Link to comment
Share on other sites

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()

Link to comment
Share on other sites

Those errors simply mean that the target you fed TweenLite is null. In this case, event.currentTarget.board1 and/or event.currentTarget.board2 resolved to null.

 

Also, are you trying to sequence the two tweens or should they occur simultaneously?

 

You might want to look into using a TimelineLite for this because it makes it really easy to manage multiple tweens (and sequence them). Check out the basics video at http://www.greensock.com/timeline-basics/

Link to comment
Share on other sites

i would like for them to happen one after the other just like an append would go. Jack i was using a previous code you suggested for another application thought that I could just add another tween and it would fine..not having much luck...

 

i just want to add another tween to the activeTween. i was going to use a Timelinemax and then reverse it in the out function but that didnt work either...

Link to comment
Share on other sites

There was a typo in your code. You named the actual instance inside your MovieClip "board3" but in your code, you referenced "board2", hence the null object error.

 

If you want to sequence the tweens and they're static (you're not changing the destination values dynamically or anything), I'd recommend just setting up your tweens/timelines at the beginning and then just play() and reverse() them. That's a more optimized way of doing it because there's no need to keep re-creating the tween/timeline instances. Here's what the code would look like:

 

var btns:Array = [btn1, btn2, btn3, btn4, btn5, btn6];
var activeTween:TimelineLite;

for (var i:int = 0; i    btns[i].buttonMode = true;
  btns[i].addEventListener(MouseEvent.ROLL_OVER, over);
  btns[i].addEventListener(MouseEvent.ROLL_OUT, out);
  activeTween = new TimelineLite({paused:true});
  activeTween.append( new TweenLite(btns[i].board1, 0.25, {x:50}) );
  activeTween.append( new TweenLite(btns[i].board2, 0.25, {x:75}) );
  btns[i].tween = activeTween;
}
activeTween = null;

function over(event:MouseEvent):void {
  activeTween = event.currentTarget.tween;
  activeTween.play();
}

function out(event:MouseEvent):void {
  activeTween.reverse();
}

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