and one more null eventdispatcher inside Actor derived class

peter.bannier's Avatar

peter.bannier

10 May, 2011 03:12 PM

Hi,
I wan't figure out what's happening here ... here's what's inside my context:

var m:EpodxModule = new EpodxModule();
injector.injectInto(m);
injector.mapValue( EpodxModule,m);

then inside a model class:

public class ModulesModel extends Actor
{
    private var _m:EpodxModule;

    [Inject]
    public function  set m(value:EpodxModule):void
    {
        _m = value;

    }
    public function get m():EpodxModule
    {
        return _m;
    }
[...]
}

Injection occurs as expected ... my m property is injected with a brand new instance of EpodxModule Class.

BUT:

m property still has a null eventDispatcher that prevents it from dispatching events for example !!! I checked by tracing it inside [PostConstruct] init function and inside others ...

There must be something wrong inside my code but honestly I can't see ...

  1. Support Staff 1 Posted by Stray on 10 May, 2011 03:54 PM

    Stray's Avatar

    Hi there,
    could you post the code inside EpodxModule?

    Does it definitely extend Actor?

    I'm sure we can help you figure it out.

    You're definitely not trying to access that eventDispatcher in the constructor? (I know you said it's in a PostConstruct function but it's worth checking).

    BTW - m is a terrible name for a variable!

    Stray

  2. 2 Posted by peter.bannier on 11 May, 2011 07:38 AM

    peter.bannier's Avatar

    Hi!
    Sure m isn't a good choice !! :)
    After a few hours trying to find out what's wrong, I was a bit uninspired for my variables names ...
    Anyway this is the EpodxModule Class:

    public class EpodxModule extends Actor

    {
        public var moduleName:String;
        public var moduleURL:String;
        public var view:Group;
        public var moduleInfo:IModuleInfo;
        public var module:IVisualElement;
        public var licenseObject:Object;
    
        public function EpodxModule()
        {
            super();
            /*moduleName = _name;
            moduleURL = _url;*/
        }
    
        [PostConstruct]
        public function init():void
        {
              trace('PostConstruct '+_eventDispatcher);
        }
    
        override public function set eventDispatcher(value:IEventDispatcher):void
        {
            _eventDispatcher = value;
            Alert.show("SET EVENT DISPATCHER");
        }
    
        override public function get eventDispatcher():IEventDispatcher
        {
            return _eventDispatcher;
        }
    

    }

    that's a pretty simple case isn't it ? I still can't see what's wrong ...
    Thanks

  3. Support Staff 3 Posted by Stray on 11 May, 2011 08:09 AM

    Stray's Avatar

    Hi Peter,

    when you overrode the set eventDispatcher you lost the [Inject] tag that was in the original Actor class.

    It should be:

    [Inject]
    override public function set eventDispatcher(value:IEventDispatcher):void
    {
        _eventDispatcher = value;
        Alert.show("SET EVENT DISPATCHER");
    }
    

    Ref: Line 67 of
    https://github.com/robotlegs/robotlegs-framework/blob/master/src/or...

    If you reinstate that then you'll probably find things work as they should - do let us know! If not then I'll help you do some deeper digging, but injection is really pretty simple:

    injection point + injection rule => process through injector = happy code.

    So there's a surprisingly small number of things that can go wrong.

    Hopefully this fixes it!

    Stray

  4. Support Staff 4 Posted by Stray on 11 May, 2011 08:10 AM

    Stray's Avatar

    A completely different note - is there a reason why you're using mapValue and instantiating the instance for yourself, rather than using mapSingleton ?

    Stray

  5. 5 Posted by peter.bannier on 11 May, 2011 08:51 AM

    peter.bannier's Avatar

    Hi,
    thanks for the quick reply !
    That was it ! now I understand pretty well what was my mistake ...
    Now I can go happy coding ... big thanks!

    I was using mapValue instead of mapSingleton as I want to have the opportunity to have multiples instances if I want to ... that's the right way isn't it ?

    I had a relative conceptual question :

    If I want a Class to act as a manager just like my ModulesModel Class which is meant to handle multiples modules. This Class have a few modules as properties. Here, with injection, I have to instantiate those modules first inside my Context and then map them. Would it be conceptualy better to handle their instantiation inside the ModulesModel himself ?

  6. Support Staff 6 Posted by Stray on 11 May, 2011 08:56 AM

    Stray's Avatar

    Hi Peter,

    I'm glad I asked then because the answer is that mapClass won't give you multiple instances (except over time, you can switch out instances).

    Essentially mapClass is identical tomapSingletonOf( ) except that you're controlling the creation of the concrete instance.

    Can I just clarify - when you talk about 'Modules' - do you mean like Robotlegs Modules (using the modular utils) - or just Flex Modules, or perhaps something totally different?

    Stray

  7. 7 Posted by peter.bannier on 11 May, 2011 09:03 AM

    peter.bannier's Avatar

    Hi,

    I was talking about something different ... it could have been anything ... just an example to picture the problem ...

    thanks for your explanations and your support!

  8. Support Staff 8 Posted by Stray on 11 May, 2011 09:08 AM

    Stray's Avatar

    Ah - ok - no problem. Basically if you want to have multiple instances within a single context your best option is always to create a container for them.

    I'll close this now - shout again if you need any more help,

    Stray

  9. Stray closed this discussion on 11 May, 2011 09:08 AM.

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