Flex breaking AS3 focus functionality in SWC - actionscript-3

I've got a flashbuilder air/flex app that used SWC's for all of it's graphic/window content that I've inherited and have run into a problem that i do not know how to solve.
The SWC has multiple text inputs which the user can tab through. However, when that SWC is loaded in flash builder pressing tab only causes the focused text field to lose focus and nothing appears to gain the focus next.
I've manually captured the tab keypress via a keyDown event listener inseide the SWC's AS3, however even setting stage.focus or setSelection() has no effect when running inside the flashbuilder app.
Is there something i can do to tell air/flex/flashbuilder to allow the focus events of the SWC?

I've closed this question as i ended up having to write my own input tab/focus manager from the ground up as a workaround.

Related

Spark Button trapping keydown (spaceBar) event

Update: Apparently this is part of the accessibility scheme of Flex Spark Components
Button control Press the Spacebar to activate the Button control. To cancel activating a button, press the Tab key to move the focus off
the Button control before releasing the Spacebar.
I guess it can be turned off through compiler directives: Accessibility best practices
Question: Is there any reason a Spark Button would trap key events, in particular a "spacebar" key event?
Background: I've inherited and am maintaining a large legacy project done in Flex 4.6. I am seeing a weird behavior with a Spark Button. Essentially, once the button has been clicked on (i.e. given focus) a keyEvent (spaceBar) will trigger the click event handler attached to the button.
Weird, right?
The button is defined in MXML (below) within an MX:Module. The module has key event listeners attached to the stage but the event handlers for those do nothing with the button:
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, echoKeyDownHandler);
this.stage.addEventListener(KeyboardEvent.KEY_UP, echoKeyUpHandler);
If I put a trace statement in the button's event handler to check the event type when this weird behavior occurs, the type is reported as a click. I don't see anything in the docs for the Spark Button about capturing key events like this.
<s:Button id="toggleBtn"
label="Editor"
click="toggleBtn_clickHandler(event)"
x="943" y="8"/>
This is quite normal with Flex. You should also be able to navigate through the interactive elements by using the <tab> key. <space> usually acts like a click. You could try to avoid this by either
a) set the focus to another object after pressing the button
or
b) by checking the keyboardPressed property.
Both is a bit hacky imho. I am not sure if it is possible to turn of keyboard navigation completely in Flex.
[edit 1] I am just thinking if it wouldn't help to simply overwrite the default keyboard handler like this:
override protected function keyDownHandler(evt:KeyboardEvent):void {}
this is inherited by UIComponent. and you would need to create an own component extending s:Button. A little drawback...
[edit 2] I wasn't able to stop thinking about that, even I stopped using Flex 2-3 years ago. So I googled a bit and found this stack overflow post:
How to disable default browser navigation with Space in Flex

Losing focus on TLF Text

I have embedded my SWF file to an HTML. I am using a TLF text in my AS3 application for the chatbox, but the problem is that the application loses its focus on TLF text while I switch to other pages, and switch back on my application. Please note that I do not face this problem while I run the SWF file using flash player on my desktop.
I have tried to use following code to re-focus on the TLF text but it does not work on my case.
addEventListener(Event.ACTIVATE, infocus);
function infocus(e:Event):void {
myTLF.textFlow.interactionManager = new EditManager();
myTLF.textFlow.interactionManager.selectRange(myTLF.text.length, myTLF.text.length);
myTLF.textFlow.interactionManager.setFocus();
}
My question is how we can resolve this? because it really bothers people since they have to click on the chatbox every times that they switch to other pages.
There are few ways to do so. You can manually put focus on your desired objects either by:
listening to MouseEvent.ROLL_OVER on your stage make a handler that will return the focus to your text field
if you want to make it to return focus on switch back to the page, you'll need to write a JS script that will tell SWF via ExternalInterface to put focus on your text field.

Adobe Air - Starling/Feathers - Text Input without OS level hooks (aka StageText)?

Long story short, I seem to always be running into unpredictable StageText functionality in Adobe AIR applications. I want to avoid triggering the OS native input fields and emulate that functionality in a Feathers/Actionscript component directly.
I've incorporated an on-screen keyboard purely in Feathers and implemented a Button subclass that acts like a basic text input. When the user clicks the button, the on-screen keyboard is displayed and hardware keyboard KEYUP's are intercepted and used to dynamically update the button label attribute.
That all works well enough, but of course I have no flashing cursor or text selectability in my current rudimentary widget. I can continue along my current path and manually implement the rest of what I need, but wanted to ask if anyone has seen or implemented a 'native acting' non-native text input widget in the Feathers/Starling/Actionscript tech stack? (Google seems to say no, but I'm hoping that's wrong. Surely I'm not the only one that thinks AIR's StageText is... troublesome... at best)
I changed my rudimentary widget from a Button subclass to a TextInput with editor factory returning a custom flash.text.TextField that has it's SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATING being nixed via preventDefault().
I now have most of what I wanted from my basic text input functionality in that I now have a text widget I can click in and select text and have all the simple cursor functionality I was missing. This still prevents the flaky native-softkeyboard interaction so I think this might suffice.

Flash buttons flicker continuously when compiled

I am looking for some help with Flash (CS5 version). I have a situation where if try to put a button on the stage with visible differences in the up/over/down/hit states, when I compile the document into a .swf, the button will continuously flicker through each state in order very quickly. Also, if I break the AS3 code in the Main class file, hidden parts of a slider bar component will flicker between visible and not. I'm talking Japanese-style, seizure-inducing flicker here. I've searched my code for recursive function calls and tried deleting and re-adding components and buttons, but to no avail. Any ideas on what could be up?
Well, it seems to me you aren't using stop() to stop the button at the frame you want.
If it isn't this, then there is some error with your ActionScript, which will show up in the output panel, so check that.
When you say 'button' is it an instance of the Button Class and have you set the instance type to Button?
i.e.
Select the button in your library panel, right click and choose 'Properties'. Then set the Type to Button.
Next, select the instance of the button on the stage, open the Properties panel and just underneath where you type the instance name you should see a drop down menu containing MovieClip, Button and Graphic. Set it to Button.

Flex Textfield doesnot gain focus when cursor is in text field of iframe

I have a web page which has a SWF file embeded. I have an issue with the focus.
Steps to reproduce:
1)Click on a HTML Text Field which is inside a Iframe
2)Click on a Flex Field.
3)Begin to type some text.
Expected Result is the entered text should go in the Flex TextInput field but the actual Result is it goes into HTML text field.
This is the bug which was filed but closed without any resolution. The workaround suggested there doesnt work. ( bugs.adobe.com/jira/browse/SDK-12377 )
This is happening only in IE 6.0 and IE 7.0. Below is the live example.
http://drumbeatinsight.com/examples/htmlcomponent/iframe/HTMLFrameInApplication.html
Any Suggestions or workaround to solve this problem are requested.
Your browser is maintaining focus instead of giving it back to the flash player. I ran into this issue when trying to 'embed' html content inside my flex app ... accomplished by floating html iframe above the flash player.
I have to hide and restore the iframe if I want to interact with flex because the iframe needs to be on top of the flash player, but all that is easy. I would find, even if I hid the iframe, flash player was never getting keyboard focus back. You need to tell the browser to give keyboard focus back to the flash player.
Now there is no really good way to determine if you need to instruct the browser to give keyboard focus back, I end up executing this javascript on every mouse down, rather inefficient, but it was the only way to gaurentee whenever my user clicked on flash player content, that the browser gave keyboard focus back.
Execute a javascript method that looks up the embeded content by name and call focus().
Basically - document.getElementById('flexEmbedID').focus();
Use the external interface to call that on stage.mouseDown(). Lots of overhead as it executes a lot, but it will fix your problem.