Window not selected after changing frame from using a button - actionscript-3

When I change scene with the use of a button in my game it seems to deselect the window. Then it does not respond to keyboard input without clicking the window again afterwards.
Is there a way to stop this with some sort of command or a way to bypass this with a different method.

When you click an object that object gains focus. During your buttons MouseEvent.CLICK event listener, you need to call the setFocus() function on the object you need the key strokes on.

Related

Why do I have to click the movie for my character to respond?

My movie has 3 frames, first one is the welcome screen with the play button, and after I press it and jumped to frame2 I have to click the movie for my character/player to respond and move by arrows. Same happens if I go back to frame2 from my game-over screen placed on frame3.
I use gotoAndPlay(); to navigate frames, naturally.
if it's something having to do with my code from frame2 i will post what it is required. I'd like to know why is that happening and how to fix it. THANKS!
Clicking your character gives it focus.
Only* what has focus receives keyboard events.
If you register the listener for the keyboard event on your character object, you have to click it first, before it receives those events.
However, the KeyboardEvents bubble up the display list and eventually reach the top most container which is the stage. This gives you two options:
Handle the focus yourself by assigning the object that should have focus to the stage.focus property. This is basically doing what the clicking does in your current situation.http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#focus
register your listeners at the stage
The user simply needs to click anywhere on the flash stage to add keyboard focus. Normally, a good way of achieving this is by using a start button, or something similar, for that first bit of mouse/keyboard focus.

Action Script 3 keyboard event set focus

I set focus to a text field in the init method, however keyboard enter event only works when I click the text field first.
What is the problem?
It's because, in AS3, by default, stage got the focus. So if you are adding a keyboard event listener to anything other than stage you have to set focus to that object.
Example,
If txt is your text field, you are adding a keyboard event listener to txt then you must do get focus for that like
stage.focus = txt;
That line brought focus to the text field but remember if you click on anything other than that, that object got focus. Needless to say, txt lost focus.
Tip: Try using adding keyboard event listener to stage, if you do so then it dispatches the event when a key is clicked or released regardless of the what object has focus.
stage.addEventListener(KeyBoardEvent.KEY_DOWN, onKeyDown);

Actionscript 3 - Synchronous Click Event

I am trying to build a custom modal dialog in flash. The way I chose to go about it is create a movie clip class with the UI for the dialog with a function to add buttons to it. I then size the ui after all the buttons are added and display it on the screen.
It works up to this point. Now I want whatever called this dialog to wait until a button is picked before the user can do anything else. Something along the lines of:
var dialog:MyDialog = new MyDialog();
dialog.addButton(new MyButton("Foo"));
dialog.addButton(new MyButton("Bar"));
var result:String = dialog.show(); // we will wait here
In the dialog.show I wish to show the movie clip and then wait for the user to click and of the buttons on the dialog before returning. The MouseEvent.CLICK event is asynchronous though so I don't know how to wait for it.
An alternative is creating a whole custom complete event for the dialog that is added to the screen that is calling the dialog which I can continue the logic in and have a boolean that disables other input, but that is a pretty big hassle and I've never done anything like it.
What your describing is a misconception of what synchronous and asynchronous is.
When the dialog comes up, you still want the user to be able to hit the dialog button. If the procedure was synchronous then the entire program would freeze as the routines for the mouse clicking actions would never arrive. Remember, flash is single threaded.
The thread that has the popup is sharing the same thread as the underlying app.
The easiest thing is just to have an event on the buttons that dispatch some close event that you can listen for in your application. No custom event classes are needed.
dispatchEvent(new Event("close"))
as an example.
If your worried about the user interacting with parts outside of the application, then you can simply draw a rectangle behind the popup with mouseEnabled true, or check out using Flex's model dialog classes.

Page flip effect on button press in html5

I'm looking at this:
http://www.netmagazine.com/tutorials/create-page-flip-effect-html5-canvas
However, I have one problem with that - I need to be able to click on the pages, even the edges, without triggering the page turn. I want the pages to turn when a button outside of the canvas is pressed. Is this possible using the base they provided, or do I need to go an entirely different direction?
Yes that can be done.
From what i can see, you need a click event that doesnt trigger the page drag. You need to assign a flag for this.
Let Drag = mouse drag/mouse move, down = mouse down, release = mouse release events respectively.
Initialize your flag variable as false. When a drag event is encountered it becomes true. Otherwise it remains false. As long as it is false when the mouse release event occurs it can be treated as a click. Thats the basic principle behind using mousedown and mouseup as a click event.
You will have to use e.srcElement or e.target to give you the element your cursor is currently positioned over inorder to trigger click functions relative to that element.
If you want a more detailed explanation on the page flip technique then check this out. Helped me lot.

How can I press a swing JButton using mouse events?

I Have a JButton (or any Component, really) that I would like to trick into thinking that it has been clicked on and therefore firing its action performed event. I don't want to call the action performed or doClick directly because I am trying to make a solution that generalizes beyond buttons, and I am constrained to posting events.
I would have thought that posting a MousePressed event to the system event queue would have done it, but no. ( with appropriate location, click count etc.)
Then I thought a mouse entered followed by a mouse move, a mouse pressed, a mouse released, and a mouse clicked, but no.
None of this causes the JButton to fire its action performed like it does when I actually click on it.
Has anyone caused a JButton to spit out its action performed event by driving it with mouse events? Moved a JSlider with mouse events? Expanded a tree node?
Thanks for any help.
Have you tried the fireActionPerformed method? I can't off the top of my head now remember if all components have it but if i remember right, all buttons and menu items should deifnately have it. Just a thought