Jump to content
Search Community

onComplete - class methods work, instance methods don't

jr_blackridge test
Moderator Tag

Recommended Posts

This has to be a scope problem, but I'm a bit of an oop noob, and can't figure out what's going on.

 

Essentially I'm trying to encapsulate the approach used in the Physics2D plugin example (where tweenDot calls tweenDot through an onComplete)

 

But in the class I've created, the TweenLite onComplete call isn't working unless the methods and properties are static (and of course I need instance properties).

 

It appears to call the method, but none of the instance properties are available (exist?), so the recursion doesn't work.

I've tried using "this" to reference my instances, and I've also tried making a property to store a reference to the instance of the class and use that in the onComplete.

 

Any guidance on how to make my onComplete work in my class instances?

TIA

Link to comment
Share on other sites

man, this was driving me nuts. haven't touched as2 too much lately with TweenLite.

 

you were absolutely correct in your assessment and after my tests I could confirm that yes the scope was getting mangled as references to your iteration and bladeX vars were getting lost.

 

fortunately greensock thought of this and I found the answer here: viewtopic.php?f=1&t=2843&p=10799&hilit=oncomplete+scope+as2#p10799

 

the solution is you have to set the scope with onCompleteScope:this

 

so use this:

 

myTimeline.insert(new TweenLite(blade, particleDuration, { physics2D:{velocity:getRandom(particleV1, particleV2), angle:getRandom(particleAngle1, particleAngle2), accelerationAngle:accAngle, acceleration:acc }, delay:delay, onComplete:tweenBlade, onCompleteParams:[blade, 0], onCompleteScope:this, onStart:showBlade, onStartParams:[blade, 100]}), myTimeline.currentTime+delay);

 

I got tweenBlade to recurse and all the NaNs and undefined's went away!

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