Jump to content
Search Community

A little help on nesting?

booglebop test
Moderator Tag

Recommended Posts

I've combed through the forums and tried to piece together what I can but I'm getting an error:

 

"TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.greensock::TimelineLite/insert()

at New_Car_Micrositer1_fla::introAnimation_1/frame1()"

 

I'm lost. Here's the code:

var main_TL:TimelineMax = new TimelineMax();
main_TL.insert(dollarSign_TL, -1);

var dollarSign_TL:TimelineMax = new TimelineMax();
var cycles:uint = 3;
var spinDuration:Number = 1;
var spinTween:TweenMax = TweenMax.from(dollarSignContainer.dollarSign, spinDuration * 0.5, {transformMatrix:{skewY:-180}, paused:true, repeat:cycles * 3 + 1, yoyo:true, ease:Linear.easeNone});
dollarSign_TL.insert(TweenMax.to(spinTween, cycles * spinDuration, {totalTime:spinTween.totalDuration - spinDuration, ease:Back.easeOut}));
dollarSign_TL.insert(TweenMax.from(dollarSignContainer, 1, {scaleX:0, scaleY:0, ease:Back.easeIn}));

 

Also getting the same error when try something like this:

main_TL.append(dollarSign_TL.reverse());

 

Any help is appreciated. Thanks!

Link to comment
Share on other sites

I think you may be missing some key object-oriented concepts. The reason you were getting that first error was because you were trying to insert() dollarSign_TL before you even created it. So dollarSign_TL was null when you inserted it - TimelineMax will burp because it's saying "dude, how am I supposed to add a non-existent tween/timeline?"

 

Create your dollarSign_TL first, then insert() it into your other timeline.

 

Also, you cannot do main_TL.append(dollarSign_TL.reverse()) because append() expects you to pass in a valid tween/timeline reference but the reverse() method doesn't return anything. So again, it's the same as doing main_TL.append(null). You can, however, do dollarSign_TL.reverse() and then append dollarSign_TL.

 

Make sense now?

Link to comment
Share on other sites

Yup, I got it. Thank you. Can you point me in the right direction of simplifying this code? I'm not sure how to pass parameters to a tween of a tween.

var segment01_TL:TimelineMax = new TimelineMax({paused:false});

var cycles:uint = 3;
var spinDuration:Number = 1;
var tag_TL1:TimelineMax = new TimelineMax();
var tag_TL2:TimelineMax = new TimelineMax();
var tag_TL3:TimelineMax = new TimelineMax();
var tag_TL4:TimelineMax = new TimelineMax();
var spinTweenTag1:TweenMax = TweenMax.from(tag1container.tag1, spinDuration * 0.5, {transformMatrix:{skewY:-180}, paused:true, repeat:cycles * 1 + 1, yoyo:true, ease:Linear.easeNone});
var spinTweenTag2:TweenMax = TweenMax.from(tag2container.tag2, spinDuration * 0.5, {transformMatrix:{skewY:-180}, paused:true, repeat:cycles * 1 + 1, yoyo:true, ease:Linear.easeNone});
var spinTweenTag3:TweenMax = TweenMax.from(tag3container.tag3, spinDuration * 0.5, {transformMatrix:{skewY:-180}, paused:true, repeat:cycles * 1 + 1, yoyo:true, ease:Linear.easeNone});
var spinTweenTag4:TweenMax = TweenMax.from(tag4container.tag4, spinDuration * 0.5, {transformMatrix:{skewY:-180}, paused:true, repeat:cycles * 1 + 1, yoyo:true, ease:Linear.easeNone});
tag_TL1.insert(TweenMax.to(spinTweenTag1, cycles * spinDuration, {totalTime:spinTweenTag1.totalDuration - spinDuration, ease:Back.easeOut}));
tag_TL1.insert(TweenMax.from(tag1container, 1, {autoAlpha:0}));
tag_TL2.insert(TweenMax.to(spinTweenTag2, cycles * spinDuration, {totalTime:spinTweenTag2.totalDuration - spinDuration, ease:Back.easeOut}));
tag_TL1.insert(TweenMax.from(tag2container, 1, {autoAlpha:0}));
tag_TL3.insert(TweenMax.to(spinTweenTag3, cycles * spinDuration, {totalTime:spinTweenTag3.totalDuration - spinDuration, ease:Back.easeOut}));
tag_TL1.insert(TweenMax.from(tag3container, 1, {autoAlpha:0}));
tag_TL4.insert(TweenMax.to(spinTweenTag4, cycles * spinDuration, {totalTime:spinTweenTag4.totalDuration - spinDuration, ease:Back.easeOut}));
tag_TL1.insert(TweenMax.from(tag4container, 1, {autoAlpha:0}));

segment01_TL.appendMultiple([tag_TL1,tag_TL2,tag_TL3,tag_TL4],0.15,-3.25);

 

I've got a bunch more MCs I need to apply this basic "spin" animation to, but they have slightly different parameters etc... Please share you wisdom :)

Link to comment
Share on other sites

It was a little hard to figure out what you wanted to do, but i think this should work.

var segment01_TL:TimelineMax = new TimelineMax({paused:false});

var cycles:uint = 3;
var spinDuration:Number = 1;
var tags:Array = [tag1container, tag2container, tag3container, tag4container];
var stagger:Number = 0;

for (var i:int = 0; i < tags.length; i++) 
{
var timeline:TimelineLite = new TimelineLite();
var vars:Object = { transformMatrix: { skewY: -180 }, paused:true, repeat:cycles * 1 + 1, yoyo:true, ease:Linear.easeNone };

timeline.insertMultiple([TweenMax.from(tags[i].["tag" + int(i + 1)], spinDuration, vars), TweenMax.from(tags[i], 1, { autoAlpha:0 } ) ] );
segment01_TL.append(timeline, stagger);

stagger -= 3.15;
}

Link to comment
Share on other sites

You could create a function that does it for you, and do something like:

 

segment01_TL.insert( buildSpin(tag1container, tag1container.tag1, cycles, spinDuration), 0.15);
segment01_TL.insert( buildSpin(tag2container, tag1container.tag2, cycles, spinDuration), 0.30);
segment01_TL.insert( buildSpin(tag3container, tag1container.tag3, cycles, spinDuration), 0.45);
segment01_TL.insert( buildSpin(tag4container, tag1container.tag4, cycles, spinDuration), 0.60);

function buildSpin(container:Sprite, tag:Sprite, cycles:uint, spinDuration:Number):TimelineMax {
var tl:TimelineLite = new TimelineLite();
var tween:TweenMax = TweenMax.from(tag, spinDuration * 0.5, {transformMatrix:{skewY:-180}, paused:true, repeat:cycles * 1 + 1, yoyo:true, ease:Linear.easeNone})
tl.insert( TweenMax.to(tween, cycles * spinDuration, {totalTime:tween.totalDuration - spinDuration, ease:Back.easeOut}) );
tl.insert( TweenMax.from(container, 1, {autoAlpha:0}) );
return tl;
}

 

Or if you'd prefer to loop through an array, you could do something like:

 

var tags:Array = [tag1container.tag1, tag2container.tag2, tag3container.tag3, tag4container.tag4];
var containers:Array = [tag1container, tag2container, tag3container, tag4container];
var segment01_TL:TimelineMax = new TimelineMax();

for (var i:int = 0; i 	var tl:TimelineMax = new TimelineMax();
var tween:TweenMax = TweenMax.from(tags[i], spinDuration * 0.5, {transformMatrix:{skewY:-180}, paused:true, repeat:cycles * 1 + 1, yoyo:true, ease:Linear.easeNone})
tl.insert( TweenMax.to(tween, cycles * spinDuration, {totalTime:tween.totalDuration - spinDuration, ease:Back.easeOut}) );
tl.insert( TweenMax.from(containers[i], 1, {autoAlpha:0}) );
segment01_TL.insert( tl, 0.15 * (i + 1));
}

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