A couple of years ago I wrote a post discussing the Flex error #1009 (cannot access a property or method of a null object reference). If you’ve done any serious amount of Flex coding I’m sure you’ve run into this error a number of times.
While there are a few possible causes, the post discussed how a lack of understanding of the Flex component creation lifecycle could be a possible culprit. While everything in the post is still technically accurate (for Flex 3) I find that I often just use bindings if I need to set a property of a child component.
So… here’s the fourth way to solve the problem (at least for simpler use cases).
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ [Bindable] public var buttonLabel:String; ]]> </mx:Script> <mx:Button id="button" label="{ buttonLabel }"/> </mx:Canvas>
I realize this is pretty obvious to most Flex programmers, I just wanted to clarify for people who are new to Flex and are finding the old post.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::UIComponent/drawFocus()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9416]
at com.hillelcoren.components.autoComplete.classes::FlowBox/handleFocusIn()[C:\dev_workspace\YmcoLibrary\src\com\hillelcoren\components\autoComplete\classes\FlowBox.mxml:63]
I’m using the AutoComplete everywhere and with no problems. I have a popup form that uses the AutoComplete and always throws this error. I literally have the exact same code elsewhere with no issues (not a popup);
I think you’ll need to extend the component (or use the source) and modify the handleFocusIn function in AutoComplete.mxml to check if focusManager is null.
protected function handleFocusIn( event:FocusEvent ):void
{
if(event.relatedObject != null)
{
if (event.relatedObject && contains( event.relatedObject ))
{
return;
}
}
if(focusManager != null)
{
if (focusManager.getFocus() == _inlineButton)
{
setFocus();
}
}
}
I don’t think this is enough. Why would focusManager be null? Another instance of this component just failed. Completely frustrating. This instance is not on a popup, and no code has changed. I am using the source as well, not the swc.
With this change are you still getting the null error? As for why the focusManager is null it could be because your popup doesn’t implement IFocusManagerContainer (http://tech.groups.yahoo.com/group/flexcoders/message/152278). When you say “another instance of this component just failed” could you please provide more specifics.
“Flex Error #1009: Cannot access a property or method of a
null object reference (update) Hillel Coren”
was a great posting, can’t help but wait to examine even more
of your postings. Time to waste a little time online lmao. Thanks for your effort -Winnie