I'm trying to display a text when a key is pressed at regular interval like 500, half a second. At the start, if I press a button like Up, the screen would display Up every half a second, the other half of a second there is no text on the screen, which is what I intended to do. But when I pressed other key, the interval mess up and also the text on the screen. I couldn't find what is wrong. This is the code I'm working with:
Actionscript Code:
this.createTextField("trace_txt",1,0,0,200,200);
trace_txt.multiline = true;
trace_txt.wordWrap = true;
var txtFormat:TextFormat = new TextFormat();
txtFormat.color = 0xFFFFFF;
txtFormat.bold = true;
trace_txt.setNewTextFormat(txtFormat);
var traceOn:Boolean;
function blink(arg)
{
if(!traceOn)
{
trace_txt.text = arg;
traceOn = true;
}
else
{
trace_txt.text = "";
traceOn = false;
}
}
var keyListener:Object = new Object();
keyListener.onKeyDown = function()
{
if(Key.getCode() == Key.DOWN)
{
setInterval(blink,500,"Down");
}
if(Key.getCode() == Key.UP)
{
setInterval(blink,500,"Up");
}
if(Key.getCode() == Key.LEFT)
{
setInterval(blink,500,"Left");
}
if(Key.getCode() == Key.RIGHT)
{
setInterval(blink,500,"Right");
}
}
Key.addListener(keyListener);
EDIT: I have tried using the SWF in Device Central and my phone. Both had the same result and the text interval is messed up when another button is pressed.