Flex Module – Error #1009

I ran into a problem recently with loading modules that contain instances of the List control.    The modules would load and display just fine, but as soon as you started to interact with them, you would get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.managers::DragManager$/get isDragging()
at mx.controls.listClasses::ListBase/mx.controls.listClasses:ListBase::dragScroll()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at ()
at flash.utils::SetIntervalTimer/flash.utils:SetIntervalTimer::onTimer()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()

Then something occurred to me that I recently heard at at the 360Max conference. Alex Harui gave a presentation at 360Max on modules.   His presentation talked about shared code between modules that share the same classes or assets.   If those modules share managers, then the developer must be careful.  Alex points out that a common mistake is to unwittingly bring in Managers (PopUpManger, DragManager) in a module and use from another module.  

So you must either factor out the code in another module or load it before you load the modules that use it.  Alex’s presentation describes one method and I found another method outlined on a Flexcoder’s post. Place the following code in the main application file within the script block:

import mx.managers.DragManager;
var dm:DragManager;

This will be sure that the DragManager (or PopUpManger) will be loaded before the modules that use it.   I recommend reviewing Alex’s presentation for a full discussion of why this occurs with modules.  Basically, the first DragManager loaded becomes the manager for all modules loaded after it.  If the first module had the DragManager, the second one can’t access it and throws the error.  

I am happy to report that this fixed the issue.  I also wanted to mention one more small caveat that I learned while using modules.  There is a bug when you use the width and height properties of the <Module> or <ModuleTemplate> tags.  You have to use percentWidth and percentHeight instead:

<view:ModuleTemplate percentWidth="100" percentHeight="100"
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:view="com.mister.view.*" >

The work around was described in this tech note from Adobe:

Modules – Module ignores percentages for width/height, always sizing to content. Workaround is to add percentWidth=”100″ percentHeight=”100″ example:

Modules – Module ignores percentages for width/height, always sizing to content. Workaround is to add percentWidth=”100″ percentHeight=”100″ example:

<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#ff00ff" percentWidth="100" percentHeight="100">

29 Comments

  1. Cool, had the exact same problem with isDragging(), but thanks to you the problem is now solved faster than expected.
    By the way, I had the problems with the percentage too…:-)

    Br Casper

  2. Thank for that Module detail, using percentage.
    For me, have module 100% is basic.
    Spend time trying to find why don’t work, thanks now is working.

    Paul

  3. Wow.. I was struggling hard in order to get it resolved. I also found , this happens only in debug version. For some reason without applying the fix as above my code works perfectly ok in FireFox but does not work in IE ( because of debug version)..
    Any way its better to apply the logical fix..

    thanks dude!

  4. Modules – Module ignores percentages for width/height, always sizing to content. Workaround is to add percentWidth=”100″ percentHeight=”100″ example:

    — doesn’t WORK!

  5. You are right, it is finally works. But I’m using Flex3 Beta and it has so many bugs – when I tried it firs time it just didn’t do anything, now it is ok.

    Thank you for article!

    May be you know – I have big issue with Flex3 plugin for Eclipse, it won’t highlight errors in MXML,AS files – you can type whatever you want, save and it just didn’t build – with no explanation…. tryed with my project at different PC – same problem…

  6. Thanks! This started looking pretty gnarly but your solution nailed it.

    In my case the modules were each using PopUpManager which would work for the first module loaded but not for any subsequent ones. I was getting the same null reference error but pointing to DragManager(!!) (which I wasn’t even using.)

    I used your ‘pre-declare’ method with both DragManager and PopUpManager in the main app and the problem went away.

    The problem was present in both Flex 2 and Flex 3 beta.

    Thanks again.

  7. Yeah, you have a shared code typology. Whichever module is loaded first grabs the reference to the Manager and the later modules can’t access it.

  8. I uses a SharedCode.as file that I compile into a SWF. This is loaded in the main application before I load any module. Inside that file I have the following Class files:

    import mx.modules.ModuleBase;
    import mx.managers.DragManager;
    import mx.core.BitmapAsset;
    import mx.controls.ToggleButtonBar;
    import mx.formatters.NumberBase;
    import mx.formatters.NumberFormatter;

    public class SharedCode extends ModuleBase
    {
    private var dragManager:DragManager;
    private var bitMapAsset:BitmapAsset;
    private var toggleBar:ToggleButtonBar;
    private var numBase:NumberBase;
    private var numberFormatter:NumberFormatter;
    }

  9. Im getting an error when attempting to load a second module into a ModuleLoader within my main application.

    Do i need to have a ModuleLoader for each module in my application?

    here is the stacktrace…

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at mx.managers::HistoryManager$/register()
    at mx.containers::Accordion/::addedHandler()
    at flash.display::DisplayObjectContainer/addChildAt()
    at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$addChildAt()
    at mx.core::Container/addChildAt()
    at mx.core::Container/addChild()
    at mx.core::Container/createComponentFromDescriptor()
    at mx.core::Container/createComponentsFromDescriptors()
    at mx.core::Container/mx.core:Container::createChildren()
    at mx.core::UIComponent/initialize()
    at mx.core::Container/initialize()
    at camdenModule/initialize()
    at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()
    at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()
    at mx.core::Container/addChildAt()
    at mx.core::Container/addChild()
    at mx.modules::ModuleLoader/::moduleReadyHandler()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at ::ModuleInfoProxy/::moduleEventHandler()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at ::ModuleInfo/readyHandler()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::FlexModuleFactory/::update()
    at mx.core::FlexModuleFactory/::docFrameHandler()

  10. I don’t think your error is related to the ModuleLoader. You can use the same ModuleLoader reference to load other modules. You are getting a null value error some place in your code. Try to locate the specific line number where the error code occurs and find out what is showing up as a null value.

  11. I had the same problem – and this fixed it straight away. I’ve done the same thing for pop-up managers and tooltip managers to be on the safe side

  12. Oh…God…Thanks..TT
    I have been distressed for two days…
    Now it just works well……
    Thank you very very much..^^

  13. If you load modules using ApplicationDomain.currentDomain, the DragManager, et al classes won’t trip over each other and should solve the problem.

    I.e.:

    moduleInfo.load(ApplicationDomain.currentDomain);

  14. Hi, I’m getting the error as I try to play a Movie Clip,
    [as]
    stop();
    play_btn.addEventListener(MouseEvent.CLICK, show_face1);
    function show_face1(event:MouseEvent):void {
    if (face_btn.visible == true) {
    face_btn.visible = false;
    } else {
    face_btn.visible = true;
    }
    }
    back_btn.addEventListener(MouseEvent.CLICK, tostart1);
    function tostart2(event:MouseEvent):void {
    prevScene()
    }
    face_btn.addEventListener(MouseEvent.CLICK, explode1);
    function explode1(event:MouseEvent):void {
    gotoAndStop(3)
    }[/as]
    Can you help me fix it please.
    Regards Malboro =]

  15. By The Way its the face_btn that i click on to play the Movie Clip, the error i get is

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Testing_fla::MainTimeline/frame4()

  16. Never Mind I fixed it 🙂
    I hadn’t noticed I had accidentally put some action script into the movie clip.
    I’ll come back if i have any other problems.
    Regards
    The Malboro

  17. Hello all! So, I’ve got an Error #1009 issue and would love a little guidance. On the first frame of my timeline, I have preloader animation that tracks the progress of the download. On the last frame of my timeline, I have a movie clip called INTRO_anim that loads after all of the content for my website. What I would like to be able to do is skip to the next frame of the timeline (which is where all the content is) once it’s ready and forget about playing the intro if I choose to do so. When I launch my swf and click on SKIP_btn, a bunch of 1009’s pop up along with some 1010’s. Here’s my code:

    stop();

    SKIP_btn.gotoAndStop(4);
    START_btn.gotoAndStop(2);

    SKIP_btn.buttonMode = true;
    START_btn.buttonMode = true;

    this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
    this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);

    function onProgress (event:ProgressEvent): void {
    var loaded:Number = event.target.bytesLoaded;
    var total:Number = event.target.bytesTotal;
    var pct:Number = loaded/total;
    LOADING_anim.gotoAndStop(Math.round(pct*100));
    loaded_txt.text = “Loading Site… ” + (Math.round(pct*100)) + “%”;
    if(framesLoaded >= 22) {
    SKIP_btn.gotoAndStop(1);
    SKIP_btn.addEventListener(MouseEvent.MOUSE_DOWN, SKIP_early_down);
    SKIP_btn.addEventListener(MouseEvent.MOUSE_OVER, SKIP_early_over);
    SKIP_btn.addEventListener(MouseEvent.MOUSE_OUT, SKIP_early_out);
    loaded_txt.text = “Loading Intro…” + + (Math.round(pct*100)) + “%”;
    function SKIP_early_down (event:MouseEvent): void {
    this.loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
    nextFrame();
    }
    function SKIP_early_over (event:MouseEvent): void {
    SKIP_btn.gotoAndStop(2);
    }
    function SKIP_early_out (event:MouseEvent): void {
    SKIP_btn.gotoAndStop(1);
    }
    }

    if(pct == 1) {
    loaded_txt.text = “”;
    }
    }
    function onComplete (event:Event): void {
    SKIP_btn.gotoAndStop(1);
    SKIP_btn.addEventListener(MouseEvent.MOUSE_DOWN, SKIP_down);
    SKIP_btn.addEventListener(MouseEvent.MOUSE_OVER, SKIP_over);
    SKIP_btn.addEventListener(MouseEvent.MOUSE_OUT, SKIP_out);

    function SKIP_down (event:MouseEvent): void {
    SKIP_btn.gotoAndStop(3);
    nextFrame();
    }
    function SKIP_over (event:MouseEvent): void {
    SKIP_btn.gotoAndStop(2)
    }
    function SKIP_out (event:MouseEvent): void {
    SKIP_btn.gotoAndStop(1)
    }
    }

    Any ideas? Thanks a lot for any help.

  18. prtn_btni.addEventListener(MouseEvent.CLICK, prtnwdgi);
    function prtnwdgi(event:MouseEvent):void
    {
    myUILoaderd.unload();
    myTimerd.stop();
    gotoAndStop(“Main”);
    }

    that is my code

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at crbp_fla::prtpg_10/frame1()
    at flash.display::MovieClip/gotoAndStop()
    at crbp_fla::prtpg_10/prtnwdgi()

    is the error

    I have similar code in other places and they work fine, if anyone has anyideas what the issue would be it would be a great help. Thank you for any help.

  19. I have encountered this error when I ran the following program. Please help me..
    TypeError: Error #1009: Cannot access a property or method of a null object reference in ActionScript3

    public class Pagination
    {
    //This is calling the ApplicationStatus.mxml component
    var obj:ApplicationStatus= new ApplicationStatus();

    public function update():void
    {
    obj.next_txt.text =””;
    }
    }

Comments are closed.