0, 100.0, 100.0, 0, 0];
var originals = new Array();
var deltas = new Array();
for(i in 0...properties.length)
{
originals.push(Reflect.field(mc, properties[i]));
deltas.push(targetvalues[i]-Reflect.field(mc, properties[i]));
}
var start = Date.now().getTime();
var step = 0.0;
var duration = time * 1000;
var tollerance = 0.1;
mc.onEnterFrame = function()
{
step = Date.now().getTime() - start;
if (step < duration)
{
for(i in 0...properties.length)
{
// cubic function to obtain an ease-out effect
var x = step/duration - 1;
var v = deltas[i]*(x*x*x+1)+originals[i];
// adjust the value when in proximity of its target value;
// avoids strange adjustments at the end of the transition
if(v < targetvalues[i] + tollerance & & v > targetvalues[i] - tollerance)
v = targetvalues[i];
Reflect.setField(mc, properties[i], v);
}
} else {
mc.onEnterFrame = null;
}
};
}
}
To compile the preceding example, use the following command at the prompt/console:
> haxe -swf sample.swf -swf-version 8 -main Main --flash-strict -swfheader
640:480:60:000000
The value of the switch - swf - version can be changed in 6 or 7.
Pages:
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652