Shared Model To Modules

thexeb's Avatar

thexeb

19 Nov, 2012 05:49 PM

I have a model instance in my Shell module , this model implements an interface IAppModel. My application is loading module swfs at runtime and i need to share my same model from shell, but i want to use IAppModel in sub modules to reduce file size or dont know duplication .
i am using
injector.mapSingleton(IAppModel);
in module Context. This application works good at online server , sub module reads AppModel everything fine , but when developing sub module individually, the module fails to load its visual assets and i got these error messages in debuger , Note these errors were not there when i was not using IAppModel injection.
[Fault] exception, information=TypeError: Error <a href="/discussions/problems/1009" title="Discussion #1009">#1009</a>: Cannot access a property or method of a null object reference. this is because there is no AppModel to be injected , plz tell me how i can overcome this so that i can develop sub module individually , or there is any other method to share model

  1. Support Staff 1 Posted by Ondina D.F. on 19 Nov, 2012 10:54 PM

    Ondina D.F.'s Avatar

    Hello,
    Mapping to an interface should be done like this:

    injector.mapSingletonOf(IAppModel, AppModel);

    Then you inject it like this:

    [Inject] public var appModel: IAppModel;

    Let me know if that solved your problem.

    Ondina

  2. 2 Posted by thexeb on 20 Nov, 2012 06:59 AM

    thexeb's Avatar

    same as before , module fails to initialize , with same Null refernce error , :(
    is there any other method to share model? i want to develop sub modules unaffected as standalone

  3. Support Staff 3 Posted by Ondina D.F. on 20 Nov, 2012 09:54 AM

    Ondina D.F.'s Avatar

    It’s hard to say what’s going on in your code, without seeing it.Can you provide more details/code? :)

    Some common problems:

    • module is loaded before the mapping occurs (timing issues)
    • wrong mapping (as in your first post)
    • application domain not defined or wrong definition
    • module is not added to the stage (i.e. the swfloader or loader if used in pure as3 projects)
    • wrong context definition for submodule
    • a mapping in submodule overwrites the mapping from shell
    • metadata gets stripped out (see -keep-as3-metadata+=Inject -keep-as3-metadata+=PostConstruct for flex projects)
    • creating a new instance of the class (appModel=new AppModel())

    You can also:
    - Use interfaces for module communication: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c...

    • Use a shared event dispatcher
  4. 4 Posted by thexeb on 20 Nov, 2012 02:01 PM

    thexeb's Avatar

    Here is attached project
    Now i am facing Context problem at initializing , IAppModel is instantiating successfully , i wonder if it will receive the Shell's AppModel singleton at runtime?

  5. Support Staff 5 Posted by Ondina D.F. on 20 Nov, 2012 02:51 PM

    Ondina D.F.'s Avatar

    I deleted the attachment, thus I’ll mark this discussion as public again.

    The problem was caused by the order of the mappings. You had this:

    mediatorMap.mapView(EffectsView, EffectsMediator);
    injector.mapSingletonOf(IAppModel,AppModel);

    AppModel has been mapped after EffectsMediator has been already created, therefore the injector didn’t have a rule for injection.

    Change it to this:

    injector.mapSingletonOf(IAppModel,AppModel);//1 MODEL FIRST
    mediatorMap.mapView(EffectsView, EffectsMediator);//2 MEDIATOR SECOND

    It works!!

  6. 6 Posted by thexeb on 20 Nov, 2012 03:26 PM

    thexeb's Avatar

    thanks so much ondina , as u could see i am an intermediate developer, i appreciate ur help a lot ,and looking to learn more about these kind of basics

  7. thexeb closed this discussion on 20 Nov, 2012 03:26 PM.

  8. thexeb re-opened this discussion on 20 Nov, 2012 03:26 PM

  9. Support Staff 7 Posted by Ondina D.F. on 20 Nov, 2012 03:35 PM

    Ondina D.F.'s Avatar

    My pleasure :) Don’t worry, advanced users/devs can make such a mistake too (i.e. order of the mappings).

    Cheers,
    Ondina

  10. Ondina D.F. closed this discussion on 20 Nov, 2012 03:35 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