Flex Error #1009: Cannot access a property or method of a null object reference (update)

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


			public var buttonLabel:String;

	<mx:Button id="button" label="{ buttonLabel }"/>


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.

6 responses to “Flex Error #1009: Cannot access a property or method of a null object reference (update)”

  1. Fred says :

    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);

    • Hillel says :

      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.

      • Fred says :

        protected function handleFocusIn( event:FocusEvent ):void
        if(event.relatedObject != null)
        if (event.relatedObject && contains( event.relatedObject ))
        if(focusManager != null)
        if (focusManager.getFocus() == _inlineButton)


        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.

      • Hillel says :

        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.

  2. http://yahoo.com says :

    “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

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: