如果计时器已启动并正在运行,请不要使用 flex3 再次重置它
我有两个问题。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的代码是错误的。这里有一些评论:
我敢打赌,如果您将方法的第一行更改为如下所示:
它将起作用,因为您不会在任何方法调用时重新初始化计时器。
Your code is wrong. Here is some comments:
I bet if you change the first line of your method to something like this:
It would work because you will not be re-initializing the timer on ever method call.
就目前情况而言,您正在创建一个新的计时器,然后检查它是否正在运行,所以我认为第一部分可以通过从 更改为
类似的内容
来改进对于第二部分,我对 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
To something like
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.