Home > Flex Gotchas, Flex Mobile > SkinnableTextBase focusManager runtime error popup

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%"/>

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
            MouseEvent.MOUSE_UP, touchMouseUpHandler, false, 0, true);
            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"
			import mx.core.IFlexDisplayObject;
			public function get defaultButton():IFlexDisplayObject
				return null;
			public function set defaultButton(value:IFlexDisplayObject):void
	<s:TextInput width="100%"/>
  1. nunivek
    August 10, 2011 at 6:02 AM

    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!

  2. stickboy
    August 14, 2011 at 2:54 PM

    Thank you!! First article listed from my search “SkinnableTextBase ‘null object reference’ ” and it is exaclty what I needed! ; ) Gracias!

  3. saa
    September 27, 2011 at 3:55 AM

    good job

  1. September 1, 2011 at 6:52 AM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: