如果计时器已启动并正在运行,请不要使用 flex3 再次重置它

发布于 2024-09-17 05:02:52 字数 1069 浏览 2 评论 0原文

我有两个问题。

1 - 我有一个文本区域,在其中匹配一个字符串。如果匹配,则计时器将启动。但是这个条件可能会多次满足,所以我想给出一个条件,如果计时器已经在运行,则不执行任何操作,if(!timer.running)然后启动计时器。但它仍然每次都会重置计时器。

2 - 我有一个聊天窗口。对于每个用户活动,都会显示一个句子。对于每个添加的句子,我必须执行一些操作。因此,我在单个函数中给出了每个句子要执行的条件和操作,但问题是每次先前已执行的命令也会再次执行一次。 (例如上面的问题1。)所以一旦它匹配第一个字符串,它应该从文本区域的第二行开始搜索,我认为这可以解决问题。任何帮助将不胜感激。

public function updateMessage(updateMsg:String) : void
{
  userActivities.text+=updateMsg+"\n";

  if(userActivities.text.indexOf("user connected",0)!=-1)
  { 
    userTimer=new Timer(delay);

    if(!userTimer.running)
    { 
      basetmr=getTimer();
      userTimer.addEventListener(TimerEvent.TIMER,chkUserActivities);
      userTimer.start();
    }
    else
    {
      //trace("timerCount.."+userTimer.currentCount);
    }
  } 
  else if(userActivities.text.indexOf("user changed the image",0)!=-1 )
  {
    userActivities.text+="Click ReleaseDetails button to release your details to visitor";
  }
  else if(userActivities.text.indexOf("user quit the session",0)!=-1)
  {
    userTimer.stop();
  }
}  

I'm having 2 problems.

1 - I have a text area in which I am matching a string. If it matches then a timer will start. But that condition will likely be satisfied more than once, so I would like to give a condition that if timer is already running don't do anything, if(!timer.running) then start timer. But it still resets the timer every time.

2 - I have a chat window. For every user activity a sentence will be displayed to it. For each added sentence I have to perform some actions. So i have given conditions and actions to be performed for each sentence in a single function, but the problem is every time the previous already executed commands are also executed one more time. (for example above problem 1.)so once it matches the 1st string it should start search from 2nd line in the text area, i think this can do the trick. any help will be appreciated.

public function updateMessage(updateMsg:String) : void
{
  userActivities.text+=updateMsg+"\n";

  if(userActivities.text.indexOf("user connected",0)!=-1)
  { 
    userTimer=new Timer(delay);

    if(!userTimer.running)
    { 
      basetmr=getTimer();
      userTimer.addEventListener(TimerEvent.TIMER,chkUserActivities);
      userTimer.start();
    }
    else
    {
      //trace("timerCount.."+userTimer.currentCount);
    }
  } 
  else if(userActivities.text.indexOf("user changed the image",0)!=-1 )
  {
    userActivities.text+="Click ReleaseDetails button to release your details to visitor";
  }
  else if(userActivities.text.indexOf("user quit the session",0)!=-1)
  {
    userTimer.stop();
  }
}  

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

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

发布评论

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

评论(2

茶底世界 2024-09-24 05:02:52

你的代码是错误的。这里有一些评论:

// this line creaets a new timer        
userTimer=new Timer(delay);

// no code here to start the timer running

// userTimer.running will always be false and this condition will always be true
if(!userTimer.running)

我敢打赌,如果您将方法的第一行更改为如下所示:

if(userTimer){    
 userTimer=new Timer(delay);
}

它将起作用,因为您不会在任何方法调用时重新初始化计时器。

Your code is wrong. Here is some comments:

// this line creaets a new timer        
userTimer=new Timer(delay);

// no code here to start the timer running

// userTimer.running will always be false and this condition will always be true
if(!userTimer.running)

I bet if you change the first line of your method to something like this:

if(userTimer){    
 userTimer=new Timer(delay);
}

It would work because you will not be re-initializing the timer on ever method call.

遇到 2024-09-24 05:02:52

就目前情况而言,您正在创建一个新的计时器,然后检查它是否正在运行,所以我认为第一部分可以通过从 更改为

userTimer=new Timer(delay);

if(!userTimer.running)
{ 
  basetmr=getTimer(); //etc

类似的内容

if(!userTimer.running)
{ 
  userTimer=new Timer(delay);
  basetmr=getTimer(); //etc

来改进对于第二部分,我对 flex 不太熟悉,无法提供帮助,但不是检查 userActivities.text 您想要检查它的最新小节,例如最后一句话。

As it stands you are creating a new timer and then checking if its running, so I think part one would be improved by changing from

userTimer=new Timer(delay);

if(!userTimer.running)
{ 
  basetmr=getTimer(); //etc

To something like

if(!userTimer.running)
{ 
  userTimer=new Timer(delay);
  basetmr=getTimer(); //etc

For part 2 I'm not familiar enough with flex to be able to help, but instead of checking userActivities.text you want to check the latest subsection of it, such as just the last sentence.

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