如何停止在spark文本区域中一次触发两个事件(as3+flex4)

发布于 2024-12-09 12:09:15 字数 467 浏览 0 评论 0原文

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() 函数将被调用两次。我怎样才能阻止这两个事件不应该一起触发呢?请帮忙

textChanged and valueCommit both event listener are attached with a spark textarea as follows:

addEventListener("textChanged", 
    function(event:Event):void {                                    
        colorize();                 
},false,0,true);

addEventListener("valueCommit",
    function(event:Event):void {                    
        colorize();                 
},false,0,true);

if I type any thing in textarea, then this colorize() function is called twice. How can I stop this one that both event should not be triggered together. Pls help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜血染红嫁衣 2024-12-16 12:09:15

如果你想监听打字,为什么要有两个监听器?如果您确实需要两个侦听器,则需要使用 setTimeoutcolorize 进行排队,而不是直接调用它:

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);

If you want to listen for typing, why do you have two listeners? If you really need two listeners, you need to queue colorize with a setTimeout instead of calling it directly:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文