Request programming buttons that replace the keyboard

Hello and welcome
Simple inquiry about programming buttons. There is a swf flash game. I called it in the animate 2022 program and it works successfully and there is no problem but the only problem is that the game is controlled through keyboard buttons like (y - x - z - space) and other buttons and I wanted to put buttons on the game screen so that when I click on them As keyboard buttons. I mean, I want to make a button when pressed it does a real button function on the keyboard . where I can control the game by creating buttons that replace the buttons on the keyboard

Make a function that does whatever is needed when a button is pressed (eg: do_char_Up).
Then your click listener calls that function, your keyboard listener also calls that same function…

The idea is you make a central “up” function and then send both keyboard press or mouse click to that same function. The mouse can be sent directly to the function (using null)) without needing a MouseEvent listener but since your key presses will have key codes, that one cannot be null (so check the code and run the required central function).

Example:

stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyPress );
icon_up.addEventListener( MouseEvent.CLICK, do_char_Up );

//# cannot be null since you need event's keyCode  
function onKeyPress (evt:KeyboardEvent) :void
{
	//# if pressed is: arrow UP
	if( evt.keyCode == 38) { do_char_Up(); }
}

//# can be NULL to avoid restricting to a specific event type...
function do_char_Up (evt:Event = null) :void
{
	//# do whatever happens on UP press/click
}
2 Likes

how you do you integrate that SWF in AIR ?

do you have the sources and you compile it ?
or do you load the SWF dynamically ?

1 Like

Thank you very much for your beautiful reply. I did not fully understand the code and I hope that you do the entire code ready for the experiment and let it be three buttons and each of them when we click on it executes a command which is like real and actual pressure on one of the buttons of the keyboard. That is, when I press the number one button, the application feels as if I pressed a real button on the keyboard. Thank you

Thanks for your beautiful reply. My dear friend, this game was programmed by one of my friends with action script 3. But this game was running using the keyboard and left the field and currently uses another programming language. This game was flash. So I called her in the program using the calling code. But I cannot control the game because it works by using the keyboard, so I wanted to make buttons above the game when I click on it.

If you have the original .fla file is easy to do, if you don´t you can´t try pass it to .fla with a .swf decompiler, there is one that works very well https://www.swf-decompiler.com/tutorial/convertswftofla.htm

then you add the buttons and the AS3 on it.

Cheers

1 Like

thank you for your reply
You mean to convert file from swf to fla. But this is very difficult because when the conversion process is done and when the file is played it will never run successfully. Always make many mistakes. But I think you can add buttons that do the same thing as a keyboard

Yeah well… I will call bullshit here

you said

but then

if your friend actually programmed that SWF you should have no problem getting the sources from your friend

if you are reusing someone else SWF without their consent/authorisation/etc.
that’s not gonna fly here, it is not because Flash is dead that you can make a land grab on anything SWF and disregard the work of others.

closing the topic.

1 Like