Posted by Tony Monast in SWF Studio V3 on Apr 21 2008, 11:46 am

Hi,

First of all, I want to tell that I tried this file, block.spx, and it works very well.

Now, I create an Adobe Flex project, so I converted the code. Here my mxml file :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="onInitialize();" themeColor="#960000" layout="absolute">
   
     <mx:Script>
        <![CDATA[
      import mx.controls.Alert;
      
      private function onKey(return_obj, callback_obj, error_obj):void
      {
         Alert.show("test");
         if (return_obj.success) 
         {
          
            ssDebug.trace(return_obj.result);
            
              if (return_obj.result == "1,1,83,0,0,1") 
            {
                  ssDebug.trace("Ctrl+S");
              }
            else if (return_obj.result == "1,1,78,0,0,1") 
            {
                  ssDebug.trace("Ctrl+N");
              } 
            else if (return_obj.result == "1,1,90,0,0,1") 
            {
               ssDebug.trace("Ctrl+Z");
              } 
            else if (return_obj.result == "1,1,90,0,0,1") 
            {
                  ssDebug.trace("Ctrl+Y");
              } 
            else if (return_obj.result == "1,1,9,0,0,0") 
            {
                  ssDebug.trace("Tab");
              }
            
          } 
         else 
         {
             ssDebug.trace("ERROR - " + callback_obj.callback + " : " + error_obj.description);
          }
      }; 
      
      private function onInitialize():void
        {            
           ssCore.init();
         ssDefaults.synchronousCommands = true;
               
         ssCore.Keyboard.block({key:ssKey.VK_S, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_N, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_O, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_Y, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_Z, alt:"0", shift:"0", ctrl:"1"});
         
         ssCore.Keyboard.block({key:ssKey.VK_S, alt:"0", shift:"0", ctrl:"0"});
         ssCore.Keyboard.setNotify({event:"onKey"}, {callback:onKey});
         /*
         var returnObject:Object = ssCore.Keyboard.setNotify({event:"onKey"}, {callback:onKey});
         Alert.show(String(returnObject.success) + ' ' + String(returnObject.Error.description));
         */
        }
      
   ]]>
    </mx:Script>
    
    
    <mx:TextArea width="400" height="400" />
</mx:Application>



I compiled this code with Flex Builder 2 to create my SWF file. Then, I build the exe with SWF Studio 3.5 (trial version - Build 314). When I test the application, the S key is block like I defined in my code, but the callback function is never triggered.

When I change my code to :


var returnObject:Object = ssCore.Keyboard.setNotify({event:"onKey"}, {callback:onKey});
         Alert.show(String(returnObject.success) + ' ' + String(returnObject.Error.description));


I get the following error : SWF Studio commands are only available when running in a SWF Studio-Built EXE/SCR., but it's already an EXE file.

In conclusion, it's appear that I'm able to block keyboard keys, but the application is not able to execute the callback function from ssCore.Keyboard.setNotify.

My SWF file is in SWF9 format, I guess it's have something to do with my problem.

There is a way to make it work on Flex ?
Thanks for your help


Posted by mbd in SWF Studio V3 on Apr 21 2008, 01:55 pm

You need to make the callback function public. If it's private the API can't call it. If you enable the option to include the Flash debug player ( Output tab) you would probably see a Flash Player runtime error dialog. If you don't, then the API might be catching it instead and you should see a message in the SWF Studio Trace tab (if you've enabled debugging from the Output tab and have SWF Studio open).


Posted by Tony Monast in SWF Studio V3 on Apr 21 2008, 03:01 pm

Hi mbd and thanks for your answer,

Here is my last code :


 <mx:Script>
        <![CDATA[
      import mx.controls.Alert;
      
      public function onKey(return_obj, callback_obj, error_obj):void
      {
         //ssDebug.trace("The onKey callback function called");
         DoSomething();
      }; 
      
      private function DoSomething():void
      {
         //ssDebug.trace("Do something called");
         myTextArea.text = "I did something!";
         Alert.show("My alert box");
      }; 
      
      private function onInitialize():void
        {            
           ssCore.init();
         ssDefaults.synchronousCommands = true;
               
         ssCore.Keyboard.block({key:ssKey.VK_S, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_N, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_O, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_Y, alt:"0", shift:"0", ctrl:"1"});
         ssCore.Keyboard.block({key:ssKey.VK_Z, alt:"0", shift:"0", ctrl:"1"});
         
         ssCore.Keyboard.block({key:ssKey.VK_S, alt:"0", shift:"0", ctrl:"0"});
         ssCore.Keyboard.setNotify({event:"onKey"}, {callback:onKey});
         //ssDebug.trace("The onInitialize called");
        }
      
   ]]>
    </mx:Script>
    
    
    <mx:TextArea id="myTextArea" width="400" height="400" />


In the Output tab of SWF Studio, I checked Use the Flash debug player, Build and Test the application. A box appeared :

Where is the debugger or host application running

If I click OK for Localhost, I get the following error : A connection to the Debugger or Profiler could not be established by Adobe Flash Player 9.

So, I just click Cancel and my application start normally. Every functions works (callback function, doSomething and the Alertbox). No problem. I can put the callback function private or public, it's work for both.

But if in the Output tab of SWF Studio, I unchecked Use the Flash debug player, build and test, the callback function is not called : no alert box, no action...

I have the Flash Player 9 installed and updated. I'm not sure what happend. Do you have an idea? Maybe I'm doing something wrong but I can't see it.


Posted by mbd in SWF Studio V3 on Apr 21 2008, 04:00 pm


QUOTE:
Where is the debugger or host application running
The Flash debug player (previous to 9r115) will ask you to locate the debugger if it doesn't find it locally right away. It gives you time to start the debugger and/or point to the remote location, if appropriate.

You can just hit Cancel, as you've done, to just get notified of runtime errors.

In order to actually use the debugger, you would need to use the debug version of your project. In Flex Builder 2 you would need to include the "-debug.swf" version of the output file. In Flex Builder 3 the output file is the debug version by default.

QUOTE:
Every functions works (callback function, doSomething and the Alertbox). No problem. I can put the callback function private or public, it's work for both.
Yeah, I didn't clue in until I created the project that you were specifying the callback as a function reference. When you do that private/public won't matter. If you were to specify the function name as a string and provide a scope, then you would HAVE to make the function public in order for the API to find the callback.

I've attached an example project with your code that works. If it doesn't work for you then we'll get more specific about would could be different between our two setups.

Note about the example:
The SPX contains the entire Flex project. Just double-click the SPX and the files will be extracted to a folder named onKeyTest. Open Flex Builder and choose File > Import. Select Existing Projects into Workspace. Then point to the onKeyTest folder.

The project contains a libs folder that contains the coreAS3Definitions.swc so you shouldn't have to change any paths for this to work on your system, although let me know if you do have problems with paths and I'll refine how I post these.

attachments: onKeyTest.spx  


Posted by Tony Monast in SWF Studio V3 on Apr 21 2008, 04:37 pm

- I extracted the file
- I double-clicked on SPF file
- I clicked on Build, then Test
- I wrote inside the textarea

No function call. No alert box, no DoSomething.

If I start again and check Use the Flash debug player, all is working fine. It's look like it's not working perfectly in my Flash player.

Finally, I tried it on two others computers, and it's work. Apparently, I have a problem with my Flash player on my own computer. I uninstalled it, and reinstalled it, but I still have this problem. I'm gonna look further tomorrow, with a fresh head...

I feel sorry. Next time, I'm gonna test on others computers before asking. I always try to make everything I can alone before asking help... but this time, I guess it was not enough. At least, you didn't lost all your time because I learned few stuff from your help, like using the debug and trace with SWF Studio.

I really appreciate your help and I'm gonna buy SWF Studio for sure.
Have a nice end of day.

Thanks for all and sorry again...


Posted by mbd in SWF Studio V3 on Apr 22 2008, 09:30 am

It should work on just about any computer, so no harm in asking about it.

The Flash Player installed on your system shouldn't make a difference since SWF Studio V3 applications should be using the Flash Player that gets bundled with them. Do you have a beta version of the Flash Player? What version do you have installed?


Posted by Tony Monast in SWF Studio V3 on Apr 22 2008, 10:56 am

Hi,

I have the Adobe Flash Player installed for Internet Explorer 6 and Firefox, both with the version 9.0.124.0 founded on the adobe website.

Like I said, if I Build the exe with the Use Flash debug player and then click Cancel when it ask me for the Debugger location, it work as expected on my computer. On the right click, I have the following menu :

- Settings
- Print
- Show redraw regions
- Debugger
- About Adobe Flash Player 9

If I Build the exe normally, with the standard player, the menu is :

- Settings
- Print
- About Adobe Flash Player 9

So If I get it well, the problem is coming from my standard Flash Player. I try to track the source of the problem but I'm hitting a wall right now.