Jump to content
Search Community

Tweenlite in TimelineLite ... Problem for me

jimmyneutron test
Moderator Tag

Recommended Posts

Hello,

thanks for sources and docs...

 

I'm using LoaderMax, ImageLoader, TweenLite and TimelineLite ...

 

But for the first image, the first tweenlite in my timelineLite don't work !?

 

I used onInit to set properties like alpha, x, ... and onStart to change image on my sprite

because i wish restart the timeline onComplete...

 

May be you could help me ... Thanks

 

var bg:Sprite = new Sprite();
addChild(bg);

var timeline:TimelineLite = new TimelineLite( { onComplete:timeLineComplete } );

function timeLineComplete():void
{

timeline.restart();

}

var loaderMax:LoaderMax = new LoaderMax( { name:"loader", maxConnections:1 } );
loaderMax.append( new XMLLoader( "config.php", { name:"xmlConfig", onComplete:xmlConfigComplete } ) );
loaderMax.load();

function xmlConfigComplete( e:LoaderEvent ):void
{

imgToLoad = e.target.content.background.image;
for each ( var url in imgToLoad )
{
loaderMax.append( new ImageLoader( url, { onComplete:imgComplete } ) );
}
loaderMax.load();

}

function imgComplete(e:LoaderEvent):void
{

(...)

timeline.appendMultiple
([
[b]TweenLite.to(bg, 5, {alpha:1, ease:Cubic.easeOut, onInit:onInitTween, onStart:onStartTween, onStartParams:[e.target.name]}),[/b]
TweenLite.to(bg, 5, {x:50, ease:Cubic.easeOut}),
TweenLite.to(bg, 4, {scaleX:1.05, scaleY:1.05, ease:Cubic.easeOut})
]);

(...)

}

function onInitTween( ):void
{

(...)
bg.alpha = 0;
bg.x = 0;
bg.scaleX = 1;
bg.scaleY = 1;

}

function onStartTween( imageLoaderName ):void
{

(...)
bg.addChild( loaderMax.getContent( imageLoaderName ) );

}

Link to comment
Share on other sites

Ok ... i solved my trouble by using {paused:true} for TimelineLite

and play() when i used appendMultiple() ... it's allright

 

My source ...

 

 

(...)

var imgToLoad:XMLList = new XMLList();
var imgToLoadNum:uint = new uint();

var t:Array = new Array();

addChild(fond);
fond.addChild(bg);

bg.alpha = 0;

var timeline:TimelineLite = new TimelineLite( { paused:true, onComplete:timeLineComplete } );

function timeLineComplete():void
{
if ( imgToLoadNum == 0 )
{
	timeline.restart();
}
}

var loaderMax:LoaderMax = new LoaderMax( { name:"loader", maxConnections:1 } );
loaderMax.append( new XMLLoader( "config.php", { name:"xmlConfig", onComplete:xmlConfigComplete } ) );
loaderMax.load();

function xmlConfigComplete( e:LoaderEvent ):void
{
imgToLoad = e.target.content.background.image;
imgToLoadNum = imgToLoad.length();
for each ( var url in imgToLoad )
{
	loaderMax.append( new ImageLoader( url, { centerRegistration:true, onComplete:imgComplete } ) );
}
loaderMax.load();
}

function imgComplete( e:LoaderEvent ):void
{
if ( timeline.getChildren().length )
{
	timeline.append( TweenLite.to( bg, 2, { alpha:0, ease:Cubic.easeOut } ) );
}

t = timeline.appendMultiple([
	TweenLite.to( bg, 2, { alpha:1, ease:Cubic.easeOut, onStart:onStartTween, onStartParams:[e.target.name] } ),
	TweenLite.to( bg, 4, { scaleX:1.05, scaleY:1.05, ease:Cubic.easeOut } ),
	TweenLite.to( bg, 5, { x:randomInRange( 10, 50 ), ease:Cubic.easeOut } )
]);

imgToLoadNum--;
if ( imgToLoadNum == 0 )
{
	timeline.append( TweenLite.to( bg, 2, { alpha:0, ease:Cubic.easeOut } ) );
}
timeline.play();
}

function onStartTween( imageLoaderName ):void
{
bg.x = 0;
bg.scaleX = 1;
bg.scaleY = 1;

if( bg.numChildren > 0 ) bg.removeChildAt( 0 );
bg.addChild( loaderMax.getContent( imageLoaderName ) );

t[2] = TweenLite.to( bg, 5, { x:randomInRange( 10, 50 ), ease:Cubic.easeOut } );
}

function randomInRange( start:int = 0, end:int = 10, useNegative:Boolean = true ):int
{
var r:int = Math.floor( Math.random() * ( 1 + start - end ) ) + end;
if ( useNegative && Math.random() < 0.5 ) r = -r;
return r;
}

 

if no Tween is added after Timeline's constructor ... must call play () method ?

Link to comment
Share on other sites

Don't be sorry. Could you explain the process?

 

I didn't see anything about this subject in AS Doc or Trip & Tricks.

If child of timelineLite is append/prepend on the same level, it play. But if child is declared in an other function or after ... timelineLite is paused ? Or there is a delay before it be paused.

 

Again ... sorry for bad level in english :?

Link to comment
Share on other sites

the timeline will play as soon as it is constructed.

if there are no tweens in the timeline, it will complete immediately.

 

adding tweens after it has completed does not make the timeline play or restart.

 

in your case the tweens aren't added until after the assets load, that is why you need to call play().

 

------

 

in this sort of situation i have found i best to pause timelines in the constructor and to tell them to play when everything is ready.

 

perhaps, the tips and tricks page could benefit from noting this behavior.

Link to comment
Share on other sites

the timeline will play as soon as it is constructed.

if there are no tweens in the timeline, it will complete immediately.

adding tweens after it has completed does not make the timeline play or restart.

in your case the tweens aren't added until after the assets load, that is why you need to call play().

I had think well

 

in this sort of situation i have found i best to pause timelines in the constructor and to tell them to play when everything is ready.

It's good. I choose this option.

 

perhaps, the tips and tricks page could benefit from noting this behavior.

I think it's a good idea ... perhaps just for me if I forget it :lol:

 

//

 

Oh, you have read my mail about an error in the example code of PathFollower ... you write Circle2D, but the class is CirclePath2D

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