Author Topic: Flash problem  (Read 5275 times)

0 Members and 1 Guest are viewing this topic.

Offline ebidese

  • Holding
  • Posts: 2
    • View Profile
Flash problem
« on: October 17, 2008, 07:50:19 AM »
Hello

I have a problem.

I need to run a code G with the function:

fscommand ( "Code", ' ... ')

but it should be performed when a key on the keyboard is pressed.

How can I do?

 ;D

Offline zealous

  • Active Member
  • Posts: 492
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Flash problem
« Reply #1 on: October 17, 2008, 08:39:28 PM »
This is how you look for keys.

HIT:
If you call on the code again it will keep creating Listener objects so if you do not want multiple key listeners make sure to remove it before calling it again.
To remove a "Key Listener just do:

Code: [Select]
Key.removeListener(key_Listener_Function);
Also you can remove the function as well:

Code: [Select]
///Remove one if there is one so they dont multiply////
delete key_Listener_Function;

Then just call on it again later if you want to turn it back on.

Listen for Enter key:

Code: [Select]
///Create an object////;
key_Listener_Function = Object();

///On key down...you can change this to keyup/down ect...///;
key_Listener_Function.onKeyDown = function() {


///Which key was pressed///;
trace(Key.getAscii());

if (Key.isDown(Key.ENTER)) {


///What you are looking for///;
trace("enter key pressed");

///Send to Mach////
fscommand("Code", 'X10 Y5.6 Z 5.6');

}
};

///add listener to wait for the key press//;
Key.addListener(key_Listener_Function);

Test it out below:

<a href="http://alphagraphicdesigns.com/demo/KeyWatchMach.swf" target="_blank" class="new_win">http://alphagraphicdesigns.com/demo/KeyWatchMach.swf</a>
« Last Edit: October 17, 2008, 08:41:50 PM by zealous »

Offline zealous

  • Active Member
  • Posts: 492
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Flash problem
« Reply #2 on: October 21, 2008, 04:29:21 PM »
Notified when a key is pressed. To use onKeyDown, you must create a listener object.
You can then define a function for onKeyDown and use addListener() to register the listener with the Key object, as shown in the following example:


Code: [Select]
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {

    trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));

};
keyListener.onKeyUp = function() {

    trace("UP -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));

};
Key.addListener(keyListener);