开发者

ActionScript - Trace Update Value from Tweener

tweener doesn't update myValue while passing the param while tweening. why?

public var myValue:Number = 0.0;

Tweener.addTween(this, {myValue: 1.0, time:开发者_C百科 2.0, onUpdate: traceValue, onUpdateParams: [myValue]});

private function traceValue(value:Number):void
    {
    trace(value);
    }


Primitive values are always passed by value in ActionScript, never by reference. Tweener is updating your value, but what gets passed to traceValue is always the original value. So in your code above it'll always trace out 0. The solution is to pass in a reference to the target object instead, and read the value each time. If you pass in the field name this can be done dynamically for the most flexibility. Eg:

public var myValue:Number = 0.0;

Tweener.addTween(this, {myValue: 1.0, time: 2.0, onUpdate: traceValue, onUpdateParams: [this, 'myValue']});

private function traceValue(target:Object, field:String):void
{
    trace(target[field]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜