This is going to be a rather long post since I’ll try to share all information related to this issue. And I’m using Flash 8. Just hope you all can read my bad english:
Oki I stumbled on something that I can’t find the reason for other than a bug in Flash or somehow in the EventDispatcher class.
Allright lets take it from the top. I’m building a tween class. The goal with this class is that you shall be able to tween any numeric property of any object. Using one of the easing functions you get with Flash. To be exact thoose you find here: “mx.transitions.easing.*”. Each property should also be able to use it’s own easing function or a “global” one assigen when creating an instance of the class.
And as another feature you should also be able to syncronize other objects with the class’s target object.
So it works like this: You create a new instance of the class specifiying a target object, delay(how many frames it takes from calling the play method until the tween actually starts), duration, mode(If it should loop or play “ping-pong” etc), global easing function and maybe an object containg the properties you want to tween, their end values and their local easing function, if any.
Then you can also use the addProp() method to add properties to animate.
After that you can add any object as a listener. This class uses the eventDispatcher class to sentup errorhandling.
then when you start your tween the class calls a method on the target object:
setCurrentState(names:Array):Object;
“names” is an array of strings containing the names of the properties the class is to animate. In return it expects an object with corresponding numeric properties containing the property’s current value.
Then every frame it calculates the new state of each property as well as the change from the previous frame. Both in two sepparate objects: “current” and “changes”:
Like this:
for(var i:String in _properties)
{
ref = _properties*;
current* = ref.begin + (ref.change * mod[ref.tweenNum])
changes* = current* - _propMem*;
_propMem* = current*;
}
For optimising purposes each easing function is called once per frame with begin = 0 and change = 1 and saved in the array called “mod”.
And finally the class calls an method on the target object named “setAnimState” like this:
_target.setAnimState(current, changes, _time);
And they’re also added to the eventObject sent to dispatchEvent method:
dispatchEvent({target:this, type:"step", current:current, changes:changes, time:_time});
Now here’s where the “fun” part comes:
When I tested the class i animated the _x and _y properties of a movieclip. And noticed how the movieclip that used the event listener started to drift away. And so after some investigations I’ve found that when assigning to the movieclips _y property from the currentObject in setAnimState method it rounded with one decimal while in the eventListener for the “step” event it rounded with two decimals. So I got theese values:
First round:
current._y: 103.141683887137
setAnimState: 103.1
listener: 103.1
second round:
current._y: 112.369331995614
setAnimState: 112.3
listener: 112.35
The movieclips are actually the same object. It’s just that one is target and one is a listener. Funny thing if I assign ._y to the “listener” from setAnimState it works.
So it seems like it’s different if I send the object directly as a parameter rather than as a property of the eventObject used as parameter to dispatchEvent method.
/Mirandir