my callback function is not firing.

payamp's Avatar

payamp

12 Oct, 2011 03:26 PM

Hello everyone, I am taking my first stab at using Robotlegs.

override public function onRegister():void
{
    Alert.show("onRegister called in LocationFinderPanelMediator");
    view.addEventListener( MCLocationFinderSearchRequestEvent.LOCATIION_SEARCH_EVENT, onLocationFinderRequest );
    addContextListener( MCLocationFinderEvent.MCLOCATION_LOADED_EVENT, locationsLoaded );       
}
protected function locationsLoaded(e:MCLocationFinderEvent):void
{
    Alert.show("locationsLoaded function called in LocationFinderPanelMediator");
    view.locations = e.locations;
}

protected function onLocationFinderRequest(event:MCLocationFinderSearchRequestEvent):void
{
     dispatch( event );
}

I don't know what I am doing wrong. My service (that extends Actor) dispatches the MCLocationFinderEvent. I have verified the event is not null and contains the proper payload parsed out in my service code, but My callback function (locationsLoaded) is never called. the Alert is firing so onRegister is being called.

Any ideas on what I might be doing wrong?

Thanks.

  1. Support Staff 1 Posted by Joel Hooks on 12 Oct, 2011 03:57 PM

    Joel Hooks's Avatar

    unrelated, but change view.addEventListener to addViewListener( - this will let the eventMap do its thing and remove the listeners automatically.

    So is the view still on the stage? Add an onRemove override and check to make sure the mediator isn't being destroyed somehow. Double check your configuration/mappings to ensure that you've mapped all your injections/mediators properly. Make sure that you've overridden the clone method of your custom events.

  2. Support Staff 2 Posted by Stray on 12 Oct, 2011 04:07 PM

    Stray's Avatar

    Also check for race conditions - is your event firing before the mediator is around to gather it?

    Stray

  3. 3 Posted by payamp on 12 Oct, 2011 04:28 PM

    payamp's Avatar

    Hi Stray and Joel,

    Thanks for the rapid fire response. I have done what Joel suggested.

    The request event and the response event are being fired from the same mediator.

    [correction: the request is fired from the mediator which is listening to the response so I don't think this is a race condition.]

    The mediator is definitely being created by the framework and the onRegister is being called. I am also doing an Alert just as I am dispatching the MCLocationFinderEvent from the Service (that extends Actor) and I am looking at the event object in the debugger and everything looks good in the object. Scratching my head... I will keep looking.

    Thanks,

  4. 4 Posted by payamp on 12 Oct, 2011 04:50 PM

    payamp's Avatar

    I don't know if this helps but in my context I create the service like this.

    var lfs:MCJSONLocationFinderService = new MCJSONLocationFinderService( BASE_URL );
    injector.mapValue( MCJSONLocationFinderService, lfs );
    commandMap.mapEvent( MCLocationFinderSearchRequestEvent.LOCATIION_SEARCH_EVENT, MCSearchForLocationsCommand, MCLocationFinderSearchRequestEvent );
    

    my service extends Actor which is invoked from a Command.

    all I do is use the dispatch( event ) and everything should be wired up right? Assuming the injector is what owns the service. Do I need to do anything else in the service other than extend Actor and use the dispatch(event) method?

  5. 5 Posted by payamp on 12 Oct, 2011 11:53 PM

    payamp's Avatar

    I got it working by using mapSingleton instead of mapValue

    The only parameter that I wanted was the BASE_URL so I hard coded that into the service code and used:

    injector.mapSingleton( MCJSONLocationFinderService );
    

    And everything is working. Why would mapValue not work?

    Thanks for your help.

  6. 6 Posted by Stray on 13 Oct, 2011 10:29 AM

    Stray's Avatar

    Hi Payamp,

    that doesn't make any sense - the only difference between mapSingleton and mapValue is where you create the variable.

    Did you by any chance rearrange the order of things as well?

    Stray

  7. 7 Posted by payamp on 13 Oct, 2011 01:46 PM

    payamp's Avatar

    I know, but I assure you that is what is happening. I have not changed the order, I simply comment out the mapValue lines and add the mapSingleton. I have pasted in the stacktrace of the error when I use mapValue and I simply use mapSingleton and like magic everything works. Somehow when I use mapValue the eventDispatcher that gets inherited from extending Actor is null.

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at org.robotlegs.mvcs::Actor/dispatch()[/Development/Projects/Robotlegs/robotlegs-framework/src/org/robotlegs/mvcs/Actor.as:97]
    at com.companyname.services::MCJSONLocationFinderService/handleResponse()[/Users/Pi/Documents/Adobe Flash Builder 4.5/Explorer/src/com/companyname/services/MCJSONLocationFinderService.as:89]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:993]
    at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
    at mx.rpc::Responder/result()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
    at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
    at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()
    
  8. Support Staff 8 Posted by Shaun Smith on 13 Oct, 2011 01:48 PM

    Shaun Smith's Avatar

    mapValue() does not inject into the mapped value, so, even though you were extending Actor, the dependencies (injection points) that Actor has were not being satisfied because you were constructing the instance yourself.

    You worked around this by using a singleton mapping - forcing the injector to construct the instance and thus resolve the dependencies.

    If you want to go back to using mapValue() you would need to follow it up with injectInto(). For example:

    var lfs:MCJSONLocationFinderService = new MCJSONLocationFinderService( BASE_URL );
    injector.mapValue( MCJSONLocationFinderService, lfs );
    injector.injectInto( lfs );
    commandMap.mapEvent( .. );
    
  9. 9 Posted by payamp on 13 Oct, 2011 01:59 PM

    payamp's Avatar

    Great! Thanks! I am sure this is going to help others as well.

  10. payamp closed this discussion on 13 Oct, 2011 02:00 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