我想只执行一次特定事件

时间:2015-04-13 04:54:14

标签: livecode

我有一个按钮,它执行特定的任务。我想在第二次鼠标点击期间只执行一次特定任务我不想执行特定任务。现在,在完成任务之后,我只是禁用按钮,这是上述问题的任何替代方法。我使用以下代码

global e
on mouseUp 
   replace "\$" with "{\XXdollarXX}" in field "MytextField" 
   put the text of field "MytextField" into ss 
   put "" into yy 
   put 0 into tmp 
   repeat with i = 1 to the number of chars in ss 
      if char i of ss contains "$" then 
         add 1 to tmp 
         if tmp = 1 then 
            put CR & char i of ss after yy 
         else 
            put char i of ss && CR after yy 
            put 0 into tmp 
         end if 
      else 
         put char i of ss after yy 
      end if 
   end repeat 
   put yy into the field "MytextField"
   disable me
end mouseUp

2 个答案:

答案 0 :(得分:2)

我认为您的问题是脚本的持续时间。如果脚本需要大量时间来运行,则用户可能会再次单击,认为没有任何反应。通常,这将执行两次脚本。您可以使用wait with messages和本地声明的变量来阻止这种情况。

local lBusy
on mouseUp
     // first provide a way to force-unlock the script
     if the shiftKey is down then put false into lBusy
     if lBusy is true then
          // warn that the script is running
          beep
          answer error "Please wait for the script to finish."
     else
          // lock the script
          put true into lBusy
          repeat with x = 1 to 100000
               // just do something that takes a lot of time
               add 1 to mySampleVar
               put "The current value is" && mySampleVar // msg box
               // make the loop non-blocking
               wait 0 millisecs with messages
          end repeat
          // unlock the script
          put false into lBusy
     end if
end mouseUp

脚本启动时,lBusy设置为true。在脚本结束时,lBusy再次设置为false。只要lBusytrue,如果您点击按钮,脚本将无法运行。

答案 1 :(得分:0)

如果您的按钮都使用" mouseUp"消息,对它们进行分组并将该处理程序放在组脚本中。然后,您可以区分目标按钮并运行与每个按钮相关的相应代码。但由于所有操作都在一个处理程序中,因此您可以从该组中的任何兄弟中锁定任何此类消息。

相关问题