Using a preloader.fla seems to be screwing up my injection

mbilokonsky's Avatar

mbilokonsky

04 Mar, 2011 03:41 PM

So I'm working on a flash-based project. The main application lives in one .fla, and I have a separate preloader.fla which loads in the main application, casts it as its document class and then adds it to stage after a form is filled out.

When I publish the main application on its own, everything works great. However, when I publish it via the preloader it seems like my injection isn't working. In my StartupCommand it appears that eventDispatcher is null in execute(), and in my mediators the views are null in onRegister().

I even tried putting a [PostConstruct] tag above my StartupCommand.execute, but no dice.

I thought maybe it was a race conditions issue of some sort, so I tried setting my MainContext in my preloader instead of my main application, but that didn't help.

What am I doing wrong?

Here's a stack trace, I can post any code that you may need to make sense of it:

[object MainContext] Context Initialized! [object MainContext] Context Startup Firing [object MainContext] Models Mapped! [object MainContext] Services Mapped! [object MainContext] Views mapped! [object MainContext] Commands mapped! [object StartupCommand] EventDispatcher: null TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.prettysmartstudios.ism.pat.controller::StartupCommand/execute()[E:\workspaces\clients\ISeeMe-PAT\com\prettysmartstudios\ism\pat\controller\StartupCommand.as:20]
at org.robotlegs.base::CommandMap/execute()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/CommandMap.as:175]
at org.robotlegs.base::CommandMap/routeEventToCommand()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/CommandMap.as:225]
at Function/<anonymous>()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/CommandMap.as:100]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at org.robotlegs.base::ContextBase/dispatchEvent()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/ContextBase.as:70]
at com.prettysmartstudios.ism.pat.controller::MainContext/startup()[E:\workspaces\clients\ISeeMe-PAT\com\prettysmartstudios\ism\pat\controller\MainContext.as:50]
at org.robotlegs.mvcs::Context/onAddedToStage()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/mvcs/Context.as:271]
at flash.display::DisplayObjectContainer/addChild()
at PreloaderDC/startBook()[E:\workspaces\clients\ISeeMe-PAT\PreloaderDC.as:82]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.prettysmartstudios.ism.pat.views.components::PreloaderForm/beginBtnClickHandler()[E:\workspaces\clients\ISeeMe-PAT\com\prettysmartstudios\ism\pat\views\components\PreloaderForm.as:85]

[object BookMediator] Initialized! Here's my view: null TypeError: Error #1009: Cannot access a property or method of a null object reference.

at org.robotlegs.base::EventMap/mapListener()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/EventMap.as:118]
at org.robotlegs.mvcs::Mediator/addContextListener()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/mvcs/Mediator.as:125]
at com.prettysmartstudios.ism.pat.views.pages::BookMediator/onRegister()[E:\workspaces\clients\ISeeMe-PAT\com\prettysmartstudios\ism\pat\views\pages\BookMediator.as:19]
at org.robotlegs.base::MediatorBase/preRegister()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorBase.as:76]
at org.robotlegs.base::MediatorMap/registerMediator()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorMap.as:174]
at org.robotlegs.base::MediatorMap/createMediator()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorMap.as:159]
at org.robotlegs.base::MediatorMap/onViewAdded()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorMap.as:274]
at flash.display::DisplayObjectContainer/addChild()
at ISeeMeDC/addedHandler()[E:\workspaces\clients\ISeeMe-PAT\ISeeMeDC.as:67]
at flash.display::DisplayObjectContainer/addChild()
at PreloaderDC/startBook()[E:\workspaces\clients\ISeeMe-PAT\PreloaderDC.as:82]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.prettysmartstudios.ism.pat.views.components::PreloaderForm/beginBtnClickHandler()[E:\workspaces\clients\ISeeMe-PAT\com\prettysmartstudios\ism\pat\views\components\PreloaderForm.as:85]

[object FooterMenuMediator] Here's my view: null TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.prettysmartstudios.ism.pat.views.userInterface.mediators::FooterMenuMediator/onRegister()[E:\workspaces\clients\ISeeMe-PAT\com\prettysmartstudios\ism\pat\views\userInterface\mediators\FooterMenuMediator.as:34]
at org.robotlegs.base::MediatorBase/preRegister()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorBase.as:76]
at org.robotlegs.base::MediatorMap/registerMediator()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorMap.as:174]
at org.robotlegs.base::MediatorMap/createMediator()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorMap.as:159]
at org.robotlegs.base::MediatorMap/onViewAdded()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/MediatorMap.as:274]
at flash.display::DisplayObjectContainer/addChild()
at ISeeMeDC/addedHandler()[E:\workspaces\clients\ISeeMe-PAT\ISeeMeDC.as:72]
at flash.display::DisplayObjectContainer/addChild()
at PreloaderDC/startBook()[E:\workspaces\clients\ISeeMe-PAT\PreloaderDC.as:82]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.prettysmartstudios.ism.pat.views.components::PreloaderForm/beginBtnClickHandler()[E:\workspaces\clients\ISeeMe-PAT\com\prettysmartstudios\ism\pat\views\components\PreloaderForm.as:85]
  1. Support Staff 1 Posted by Till Schneidere... on 04 Mar, 2011 03:49 PM

    Till Schneidereit's Avatar

    The only explanation that I can come up with is that, for some reason,
    your preloader compiles in some of the classes that get injected into
    in your main application.

    To test that theory, you can enable the "export to SWC" option in
    Flash Pro's publish settings. If that fixes the problem, you should
    investigate which classes the preloader compiles in and why it does
    so.

    If it doesn't fix the problem, I'm afraid I can't help without you
    posting some sort of reduced test-case exhibiting the problem.

  2. 2 Posted by mbilokonsky on 04 Mar, 2011 03:54 PM

    mbilokonsky's Avatar

    I'll be damned, that fixed it.

    OK, I think I see what gets compiled in - since I'm casting the main application as its own document class, I had to import that class into the preloader. I may not need to do that, I'll poke around.

    Thanks for your help! If it's not too much trouble, can you explain how you knew that? Why would having a class get compiled in break injection like that?

  3. 3 Posted by Stray on 04 Mar, 2011 03:54 PM

    Stray's Avatar

    Till is almost certainly on the right lines here.

    2 other thoughts I had:

    1) Any chance your swf is being published differently? It's as if the metadata is being stripped... is it definitely the same swf that behaves fine if you run it outside the preloader?

    2) Any chance you're not holding on to your context? Or that your context is being overwritten (and thus is available for garbage collection)? That normally causes silent 'something that should have happened didn't happen' errors, but it's worth checking.

  4. 4 Posted by Stray on 04 Mar, 2011 03:58 PM

    Stray's Avatar

    If the preloader didn't have the export swc stuff going on then it would have stripped the [Inject] tags from the classes it compiled. First definition of a class wins - and there's your solution :)

    Nice one Till!

  5. Support Staff 5 Posted by Till Schneidere... on 04 Mar, 2011 04:03 PM

    Till Schneidereit's Avatar

    Thanks Stray!

    Apart from causing mischief with your application, casting the main
    application to its real document class also defeats the purpose of
    your preloader: It's probably bigger than the application it is
    preloading because it should contain the entirety of that, plus
    whatever you're using to show loading progress.

    To work around that, either cast to an interface (which will then also
    be duplicated in the preloader and the main application, but being an
    interface, it won't bloat the preloader by more than a few bytes) or
    simply treat is as a Sprite if you don't need to interact with it in
    any application-specific way.

  6. 6 Posted by mbilokonsky on 04 Mar, 2011 04:04 PM

    mbilokonsky's Avatar

    Excellent, what great support! You fixed my problem and gave me some great pointers. Much appreciated! :)

  7. Stray closed this discussion on 10 Mar, 2011 03:24 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac