2 Replies Latest reply on Jul 22, 2010 1:42 AM by nitin_ramachandran

    How to pass object values between classes

    nitin_ramachandran

      Hi,

      Stating my problem below.

       

      My issue is surrounded between three action script classes.  These classes are mapped to remote java clesses.

      The first one is:

       

      package com.script.vo
      {
          [RemoteClass(alias="vo.RouteVO")]
          [Bindable]
          
          public class RouteVO
          {
              public function RouteVO()
              {
              }
             
              public var routeId:Number;
             
              public var fromStation:StationVO;
             
              public var toStation:StationVO;
             
              public var firstClass:int;
          }
      }

       

      Second is :

       

      package com.script.vo
      {
          [RemoteClass(alias="vo.SectorVO")]
          [Bindable]
          
          public class SectorVO
          {
              public function SectorVO()
              {
              }
             
              public var sectorId:Number;
             
              public var fromStation:StationVO;

       

              public var toStation:StationVO;
             
              public var firstClass:int;
          }
      }

       

       

       

      Third one is :
      package com.script.vo
      {
          [RemoteClass(alias="vo.SectorMapVO")]
          [Bindable]
         
          public class SectorMapVO
          {
              public function SectorMapVO()
              {
              }
             
              public var mapId:Number;
              public var route:RouteVO;
              public var sector:SectorVO;
              public var legSeq:Number;
          }
      }

       

      private function getVal():void{

      private var sectorMap:SectorMapVO = new SectorMapVO();

      private var selectedRoute:RouteVO = new RouteVO();

       

      //I get error in this line

      sectorMap.route = SectorMapVO(selectedRoute.routeId);

      }

       

      Isn't it possible for my 3rd class object of type RouteVO to get the value of the same type? Please help me with the right code since I am new to Flex.

      Thanks in advance.

        • 1. Re: How to pass object values between classes
          Sebastien V. Level 3
          private function getVal():void{
               private var sectorMap:SectorMapVO = new SectorMapVO();
               private var selectedRoute:RouteVO = new RouteVO();
          
               //I get error in this line
               sectorMap.route = SectorMapVO(selectedRoute.routeId);
          }
          

           

          The types you are using are not the good ones.

          selectedRoute is a RouteVO, so selectedRoute.routeId is a Number. So when calling SectorMapVO(selectedRoute.routeId), you are actually trying to convert a Number into a SectorMapVO.

          sectorMap is a SectorMapVO, so route is a RouteVO. Meaning the only type of object you can assign to it is RouteVO.

          So what your last line is doing, is trying to convert a Number into a SectorMapVO, then assigning it to a RouteVO. This is very wrong.

           

          I suppose what you are willing to do is to assign the selectedRoute to the sectorMap (but I might very well be wrong on that). Then you should do:

          sectorMap.route = selectedRoute;
          

           

          Then if you need to access the sector map's route id, you just access sectorMap.route.routeId (supposing it has been initialized).

           

          Hope this helps...

           

          Edit: You should also remove the "private" before the two variables declarations in the function, a variable only has a scope (private, protected, public or default) when it is an object variable, but not in a function.

          • 2. Re: How to pass object values between classes
            nitin_ramachandran Level 1

            Thank you very much. That indeed helped..! Problem is solved..!