SkinnableTextBase focusManager runtime error popup
When you show a popup in Flex in a mobile environment, defined as the style “interactionMode” being set to InteractionMode.TOUCH in this context, that is based on a component that does not implement the mx.managers.IFocusManagerContainer interface, you will receive a runtime error when the user taps the control that is to receive focus.
Lets pretend you have a custom component that is based on <s:Group/>
:
<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" width="400" height="300"> <s:TextInput width="100%"/> </s:Group>
If you were to create or add this component as a popup using the PopupManager in a mobile application, you would get a runtime error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at spark.components.supportClasses::SkinnableTextBase/touchMouseDownHandler()[E:\dev\hero_private\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableTextBase.as:2140]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
at mx.managers::SystemManager/mouseEventHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\SystemManager.as:2924]
var myPopup:MyPopup = new MyPopup(); PopUpManager.addPopUp(myPopup, this, true);
The problem code is in spark.components.supportClasses::SkinnableTextBase.
private function touchMouseDownHandler(event:MouseEvent):void { isMouseDown = true; mouseDownTarget = event.target as InteractiveObject; // If we already have focus, make sure to open soft keyboard // on mouse up if (focusManager.getFocus() == this) //<---- focusManager is null. delaySetFocus = true; // Wait for a mouseUp somewhere systemManager.getSandboxRoot().addEventListener( MouseEvent.MOUSE_UP, touchMouseUpHandler, false, 0, true); systemManager.getSandboxRoot().addEventListener( SandboxMouseEvent.MOUSE_UP_SOMEWHERE, touchMouseUpHandler, false, 0, true); }
The focus manager only gets set when the popup that is added or created by the PopupManager implements the mx.managers.IFocusManagerContainer interface. A sample workaround for the Group component is listed below:
<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" width="400" height="300" implements="mx.managers.IFocusManagerContainer"> <fx:Script> <![CDATA[ import mx.core.IFlexDisplayObject; public function get defaultButton():IFlexDisplayObject { //TODO: return null; } public function set defaultButton(value:IFlexDisplayObject):void { //TODO: } ]]> </fx:Script> <s:TextInput width="100%"/> </s:Group>
Thank you so much!! I faced this issue and I spent hours looking for a solution, then I found your post and it works perfectly!
Thank you!! First article listed from my search “SkinnableTextBase ‘null object reference’ ” and it is exaclty what I needed! ; ) Gracias!
good job