3 Replies Latest reply on Oct 16, 2009 9:05 AM by Powder77

    Casting a ValueObject

    Powder77

      Hi Guys

       

      I am fairly new to flex and a little there is the code that is confussing me:

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" xmlns:subscription="services.subscription.*" xmlns:ganalytics="services.ganalytics.*" creationComplete="application_creationCompleteHandler(event)">

      <fx:Script>

      <![CDATA[

      import mx.events.FlexEvent;

      import mx.controls.Alert;

       

      import valueObjects.DashStatsVO;

       

      public var myDash:DashStatsVO = new DashStatsVO();

       

       

      protected function application_creationCompleteHandler(event:FlexEvent):void

      {

      getDashStatsResult.token = ganalytics.getDashStats();

      myDash = getDashStatsResult.lastResult as DashStatsVO;

      }

       

       

      ]]>

      </fx:Script>

      <fx:Declarations>

      <s:CallResponder id="getDashStatsResult"/>

      <ganalytics:Ganalytics id="ganalytics" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

       

       

      <!-- Place non-visual elements (e.g., services, value objects) here -->

      </fx:Declarations>

      </s:Application>

       

       

      When I do this getDashStatsResult.lastResult. I get the auto complete list of the objects properties which is what I'd expect, but if I try and do myDash. I don't see a list of the objects properties just the standard "hasOwnProperty" etc.

       

      All I want to do is save time typing I don't want to have to do getDashStatsResult.lastResult.property all the time but instead do myDash.property.

       

      Am sure I am making a silly mistake but any help would be much appreciated .

       

      Regards

      Chris

        • 1. Re: Casting a ValueObject
          David_F57 Level 5

          Not sure if I am reading this right but I assume by property you mean the fieldname of the retreived data so then to get a value it would be

           

          myDash[x].myproperty.

           

          i'm either right or so far off its not funny

           

           

          David.

          • 2. Re: Casting a ValueObject
            mewk Level 3

            You are assuming .lastResult is populated immediately. It is not; you need to give your service/responding objects time to call and then retrieve data from the server.

             

            try this:

            <script>
                 protected function application_creationCompleteHandler(event:FlexEvent):void {
                      getDashStatsResult.token = ganalytics.getDashStats();
                 }
                 protected function resultHandler(): void {
                      myDash = getDashStatsResult.lastResult as DashStatsVO;
                 }
            </script>
            
            <declarations>
                 <s:CallResponder id="getDashStatsResult" result="resultHandler()"/>
            </declaration>
            

            • 3. Re: Casting a ValueObject
              Powder77 Level 1

              Thanks everyone for all your help. I knew the result was not populated immediately, but I assumed that flash builder would still show the object properties. Typing it in the result handler works like a treat.