textChanged和valueCommit两个事件监听器都附加了一个spark textarea,如下所示:
addEventListener("textChanged",
function(event:Event):void {
colorize();
},false,0,true);
addEventListener("valueCommit",
function(event:Event):void {
colorize();
},false,0,true);
如果我在textarea中键入任何内容,则会调用此colorize()函数两次。如何阻止这个事件不应该同时触发。请帮忙
答案 0 :(得分:1)
如果你想听打字,为什么你有两个听众?如果您确实需要两个侦听器,则需要使用colorize
对setTimeout
进行排队,而不是直接调用它:
import flash.utils.setTimeout;
private var colorizeQueued:Boolean = false;
private function queueColorize():void
{
if (colorizeQueued)
return;
colorizeQueued = true;
setTimeout(function():void
{
// Process for real and note update
colorize();
colorizeQueued = false;
}, 100);
}
addEventListener("textChanged",
function(event:Event):void {
queueColorize();
},false,0,true);
addEventListener("valueCommit",
function(event:Event):void {
queueColorize();
},false,0,true);