1 Reply Latest reply on Sep 3, 2009 8:09 AM by zakabalt

    The same Java service in more than one Flex component

    zakabalt Level 1

      Hello, I'm using Java to do the services for one application, and I want to use the same service in more than one component. I know how can I use in one component but I don't know if I have to declarate again in the other or how can I do. Here a part of the code to show clearly.


      . . . . . .


      var info:IServiceInfo;
                      //Ask service ref
                      info = Environment.getInstance().
                          serviceLocator.getterService("com.ent.prueba.Conexion");//the package and the class name
                      info.addEventListener(ServiceInfoEvent.READY, onInfoResult);
                      info.addEventListener(ServiceInfoEvent.ERROR, onInfoFault);
                  //The service exist
                  private function onInfoResult(event:Event):void{
                      info.removeEventListener(ServiceInfoEvent.READY, onInfoResult);
                      info.removeEventListener(ServiceInfoEvent.ERROR, onInfoFault);
                      var ser:Service = info.getService();
                      ser.addEventListener(ResultEvent.RESULT, onCtxInfo);
                      ser.addEventListener(FaultEvent.FAULT, onInfoFault);
                  //The service doesn't exist
                  private function onInfoFault(event:Event):void{
                      info.removeEventListener(ServiceInfoEvent.READY, onInfoResult);
                      info.removeEventListener(ServiceInfoEvent.ERROR, onInfoFault);
                      Environment.getInstance().showInfoUser("Error with the service");
                  private function onCtxInfo(event:ResultEvent):void{
                      lbl.text = event.result as String;
                  private function onCtxInfoError(event:FaultEvent):void{
                      lbl.text = "Fallo : " + event.message;
      . . . . . . .


      This code works, but I want to use ser.xxxx in other component.


      private function treeLoaded():void
              private function treeLoadedResult(event:ResultEvent):void
                  xmlTree = XML(ser.getFolder.lastResult.toString());
                 var lista:XMLList= xmlTree.Cuenta;
                 for(var i:Number=0;i<lista.length(); i++)
                         var tmpTree:XMLList = xmlTree.Cuenta[i].node;
                        newTree.dataProvider = tmpTree;
                       newTree.labelField = "@label";


      I hope that someone knows how can I do that. how can I can to 'ser' in the second component.




      PD: all the methods that i want to use in ser.xxxx are in the same class 'Conexion'