Jump to content
Search Community

totalDuration reporting different on as2 vs as3

rob_v_5712 test
Moderator Tag

Recommended Posts

Hello all,

I'm hoping someone can explain this one to me.

 

I have make this as simple as possible to show the issue I'm seeing.

 I have a timeline that starts a tween at frame 15 and goes for 30 frames.  I then call a function on frame 100.

 

When I run this in AS3 it performs as expected.

The first tween happens 15, then at 100 the function executes.

myTimeline.totalDuration() reports 100 frames

 

Now when I run this in AS2 - 

The first tween happens at 15, then at 45 (when the tween ends) the function theEnd is called

and myTimeline.totalDuration() reports 45 frames

 

If I add a "dummy" tween at 100 for the AS2 version - it then reports it as 100

(the dummy tween being : .to(titleTop,0,{},100)  )

 

Its as if AS2 does not see time to execute the .call as being part of the timeline.

 

Also for another test - I added it between 2 tweens and the .call executed directly after the tween before it finished, ignoring the time I gave it to execute.

 

 

Here is the code below :

 

AS3 code:

myTimeline = new TimelineMax({useFrames:true,onUpdate:checkFrame});

myTimeline.add("titleBar", 15)
.fromTo(titleTop,30,{alpha:0,y:titleTop.y - 100},{alpha:1,y.titleTop.y},"titleBar")
.call(theEnd,['slide 1'],100);

AS2 code:

var myTimeline = new TimelineMax({useFrames:true,onUpdate:checkFrame});

myTimeline.add("titleBar", 15)
.fromTo(titleTop,30,{_alpha:0,_y:titleTop._y - 100},{_alpha:100,_y:titleTop._y},"titleBar")
.call(theEnd,['slide 1'],100);

AS2 Code with "dummy" tween

myTimeline.add("titleBar", 15)
	.fromTo(titleTop,30,{_alpha:0,_y:titleTop._y - 100},{_alpha:100,_y:titleTop._y},"titleBar")
	.call(theEnd,['slide 22'],50)
	.to(titleTop,0,{},100)
	.call(theEnd,['slide 1'],100);

the 2 functions

function checkFrame()
{
	var currentTime = myTimeline.time();
	var theTotalDur = myTimeline.totalDuration();;
	
	trace('this._currentFrame : '+currentTime +'/'+theTotalDur );
}

function theEnd(_slide:String)
{
	trace('the end : '+_slide);
}

Any help on this one would be great!!

 

Thanks

-Rob

Link to comment
Share on other sites

Hi,

 

I'm having a tough time trying to glue all this together in my head. It seems like you are just having a problem with the AS2 file. Please post a zip of a very simple fla that will clearly illustrate the issue.

 

 

Thanks

Link to comment
Share on other sites

The problem is simply that you forgot to define the scope parameter (well, you put the position parameter in the wrong spot). Unfortunately, AS2 does not maintain scope whereas AS3 does, thus we had to allow folks to define one specifically. That's what the 3rd parameter is for. Here's a note from the docs:

 

JavaScript and AS2 note: - Due to the way JavaScript and AS2 don't maintain scope (what "this" refers to, or the context) in function calls, it can be useful to define the scope specifically. Therefore, in the JavaScript and AS2 versions the 3rd parameter is scope, but that parameter is omitted in the AS3 version.

 

 

Here is the method signature:

//AS3:
.call(callback:Function, params:Array, position:*):TimelineMax

//AS2:
.call(callback:Function, params:Array, scope:Object, position:*):TimelineMax

So basically you were defining scope as 100 and the position was empty, thus it defaulted to the end of the timeline. 

 

The solution is to simply add the scope parameter. 

.call(theEnd, ['slide 1'], this, 100);
  • Like 2
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...