TwelvestoneFlash

onMotionFinished callback


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
JERKSTORE
 
2009-05-26

I'm having scope problems in onMotionFinished when I set a bunch of tweens in a for loop: (AS2)

for (var i:Number=0; i<navSectionArray.length; i++){ var scope:MovieClip = mcNav["mc"+navSectionArray[i]]; if (navSectionArray[i] == selectedNav){ // selected this["bgTween"+i] = new Tween(scope.mcBG, "_width", Strong.easeOut, scope.mcBG._width, 100, .5, true); this["bgTween"+i].onMotionFinished = function(){ trace ("open: "+scope); }; } else { // others this["bgTween"+i] = new Tween(scope.mcBG, "_width", Strong.easeOut, scope.mcBG._width, 1, .5, true); this["bgTween"+i].onMotionFinished = function(){ trace ("close: "+scope); }; } }

The problem, obviously, is that they ALL trace the same scope, because the for loop has completed before any of the onMotionFinished functions have fired. I can't figure out how to be able to pass a target or a var or something through to the onMotionFinished function(s) that will persist until those functions actually fire.

Is there a way in onMotionFinished to get the target of the original tween?

JLM
 
2009-05-26

There is a DelegateWithArgs class that you could use.

Most tween engines like 'tweener' allow you to pass scope to the finished function, and you can always dump an object on the tweened objects scope as well

Probably the OOP way is to create a class

for (var i:Number=0; i<navSectionArray.length; i++){ var bgTweener: BgTweener = new BgTweener( mcNav["mc"+navSectionArray[i]], this["bgTween"+i] ); }

in haXe there is a callback that makes life very simple.

JERKSTORE
 
2009-05-26

Thanks, I guess I'll have to create a class for it or something.

JLM
 
2009-05-27

Well depends but it might be overkill...

For dealing with lots of buttons special Delegates are useful, quick google found this.. http://www.ultrashock.com/forums/actionscript/pass-movieclip-instance-name-95292.html

But for tweening built in tweens are really not the best way to go...

Tweener is the common approach for example see here...http://hosted.zeh.com.br/tweener/docs/en-us/parameters/onCompleteScope.html

Many are switching to tweenlite... //taken from examples page import gs.; import gs.easing.; TweenLite.to(clip_mc, 5, {_alpha:0.5, _x:120, ease:Back.easeOut, delay:2, onComplete:onFinishTween, onCompleteParams:[5, clip_mc]}); function onFinishTween(parameter1:Number, parameter2:MovieClip):void { trace("The tween has finished! parameters: " + parameter1 + ", and " + parameter2); } but its not strictly opensource so it may not fit you need, but prob will.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

onMotionFinished callback