Sometimes Flash button press events can fire more than once so most people put code in button release events, after all how can you release a mouse button more than once? Well, normally in Flash you can't, but because of some of the things SWF Studio allows you might see a release event triggered more than once.

myButton.onRelease = function()
{
   ssCore.Shell.execute({path:'startdir://test.exe'});
}

In the simple example above, it's possible to click on myButton and have two copies of test.exe started. It usually happens when the application you're launching opens quickly. What happens is Flash loses focus for a split second when the new application launches and then regains focus while the mouse is still above myButton which triggers another onRelease event. It's a timing thing.

What we need to do is make sure the onRelease event completes before the call to the command that takes the focus away (in this case ssCore.Shell.execute) is executed. The solution is strange, but simple...

myButton.onRelease = function()
{
   id = setInterval(
      function()
      {
         clearInterval(id);
         ssCore.Shell.execute({path:'startdir://test.exe'});
      }
      , 100
   );
}

By calling the code that opens the application from inside setInterval we delay the opening of the appliction by 100ms (1/10th of second). This is more than long enough for the onRelease handler to finish and it completely eliminates the problem.