When I create function that allow flash to detect object's velocity, a problem happen. I can't put delay before 'return' executed. It's cause result of function is null or 0. There's the script:
function SSvelocity(Target:Object,target_property:String,delay_ms:int=1000):Number { if ((target_property!="x")&&(target_property!="y")&&(target_property!="z")&&(target_property!="rotation")) { trace("ShortenScript: err(SSvelocity[1]): SSvelocity("+Target+","+target_property+","+delay_ms+")"); trace(" SSvelocity(the_object,target_property,delay_millisecond)"); trace(" position should filled with \"x\" or \"y\" or \"z\" or \"rotation\""); trace(" and don\'t forget about quotes(\")"); DisplayError = true; return null; } var detecta:Timer = new Timer(1000); var detectb:Timer = new Timer(1000); var resulta:Number; var resultb:Number; detecta.delay = delay_ms; detectb.delay = delay_ms; detecta.start(); detecta.addEventListener(TimerEvent.TIMER, handlera); detectb.addEventListener(TimerEvent.TIMER, handlerb); function handlera(event:TimerEvent) { detecta.stop(); if (target_property == "x") { resulta = Target.x; } else if (target_property=="y") { resulta = Target.y; } else if (target_property=="z") { resulta = Target.z; } else if (target_property=="rotation") { resulta = Target.rotation; } detectb.start(); } function handlerb(event:TimerEvent) { detectb.stop(); if (target_property == "x") { resultb = Target.x; } else if (target_property=="y") { resultb = Target.y; } else if (target_property=="z") { resultb = Target.z; } else if (target_property=="rotation") { resultb = Target.rotation; } } // I want put delay before return, because it's resulting NaN and often 0 return (resultb-resulta); }