iOS implementation (not tested)
AS3 implementation (not tested)