Topic: Flashdevelop, Haxe and Tween

Hello!

Out of curiosity, I tried to develop a tiny widget using FlashDevelop and Haxe as Programming Language. For my first attempt I tried to load an image from the library and slowly present it using the tween-utility. But I failed. My code looks like the following:

var photo:MovieClip = Lib._root.attachMovie("Library.img000.jpg", "photo", 5);
photo._alpha = 0;
tween = new Tween( 0, 100, 3000, photo, "_alpha",Linear.easeIn);
tween.start();

I had expected that the image has alpha=0 at the beginning and slowly increasing to alpha=100, but as soon as tween.start() is called, alpha is set strait to 100 without delay.

I have very little Flash-experience, so it is very possible that I mistook something obvious. Can anyone give me a small hint?

Thanks,
Christian

2 (edited by gmcbay 2010-12-07 11:48:34)

Re: Flashdevelop, Haxe and Tween

Seems like you are using the feffects Tween haxelib based off the syntax you used.

I've never used this library before but AFAICT from a quick look at it, there is a bug in it that you're hitting... so congrats, the problem isn't in your code!


The feffects Tween class is never setting the offsetTime property if you don't manually call seek, and thus when it tries to calculate the time offset later it compares against a NaN value and thinks the tween is done during the first interval.

If you want to fix this at the source, open up Tween.hx (go to your code in FlashDevelop, highlight the "Tween" constructor call and press F4"), go to the start() method in that file and add this line to the end:

offsetTime = startTime;

Alternatively, if you don't want to change Tween's code, you can just add a call to seek in your own, eg:

var photo:MovieClip = Lib._root.attachMovie("Library.img000.jpg", "photo", 5);
photo._alpha = 0;
tween = new Tween( 0, 100, 3000, photo, "_alpha",Linear.easeIn);
tweek.seek(0);
tween.start();

Can't really explain how they have this bug in their library without having noticed it themselves previously, but like I said I've never used feffects before, so I'm not sure if it is actively maintained or what.

Re: Flashdevelop, Haxe and Tween

Thanks gmcbay, you are perfectly right! I added tween.seek(0) and now everything works as expected. Good to hear that it wasn't my fault wink