We are using the Cairngorm framework in our Flex 2.0 app. and
have now met a problem related to the resulthandling. If I trace
the result in the onResult handler in the Command class, the traces
once the first time i call the service, two times the second, three
times the third and so on. It might be related to the code which
adds the event handler, but I'm not sure.
Have any of you met the same problem, or maby see some errors
in the code below?
Event class:
public class GetCategoriesEvent extends CairngormEvent
{
public function GetCategoriesEvent() {
super( GetCategoriesEvent.EVENT_GET_CATEGORIES );
}
public static var EVENT_GET_CATEGORIES:String =
"getCategories";
}
Command class:
public class GetCategoriesCommand implements Command,
Responder {
private var model : ModelLocator =
ModelLocator.getInstance();
public function execute( event : CairngormEvent ) : void {
var delegate : GetCategoriesDelegate = new
GetCategoriesDelegate ( this );
var getCategoriesEvent : GetCategoriesEvent =
GetCategoriesEvent( event );
delegate.getCategories();
}
public function onResult( event : * = null ) : void {
Application.application.trace("onResult: " + event.result);
}
public function onFault( event : * = null ) : void {
Application.application.trace("onFault: " + event.result);
}
}
Delegate class:
public class GetCategoriesDelegate
{
private var responder : Responder;
private var service : Object;
public function GetCategoriesDelegate ( responder :
Responder )
{
this.service = ServiceLocator.getInstance().getHTTPService(
"getCategories" ) as HTTPService;
this.responder = responder;
}
public function getCategories(): void {
service.addEventListener(ResultEvent.RESULT,
getCategories_onResult);
service.addEventListener(FaultEvent.FAULT,
getCategories_onFault);
service.send();
}
private function getCategories_onResult( event:ResultEvent
): void {
responder.onResult(event);
}
private function getCategories_onFault( event:FaultEvent ):
void {
responder.onFault();
}
}
Service:
<mx:HTTPService id="getCategories" url="
http://localhost:9081/sparing/fondtilbud/action?action=list_verdipapir_kategorier" showBusyCursor="true"
useProxy="false" />