Hello Guest it is October 21, 2021, 11:43:12 PM

Author Topic: Flash problem  (Read 6208 times)

0 Members and 1 Guest are viewing this topic.

Flash problem
« on: October 17, 2008, 07:50:19 AM »

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?


Offline zealous

  •  491 491
  • 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.

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]
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///;

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//;

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

  •  491 491
  • 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()));