Rewriting AS3 code that can't be directly converted