3 Replies Latest reply on Jul 19, 2006 10:58 AM by arizona

    Setting an array to results from remoteObject


      Using the debugger in flex builder 2 I see that the myRemoteObject returns good data. I also see that alert.result returns an array full of data. My listener gets called and I set a breakpoint in the procedure (reportReceived) and can see the alert.result array. The reports.source is null even after I set it equal to the alert.result. Again alert.result has good data.

      What am I doing wrong?

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      import mx.controls.Alert;
      import mx.collections.*;
      import mx.rpc.events.*;
      import mx.events.*;
      import mx.utils.*;

      private var reports:ArrayCollection = null;

      private function setup():void {

      private function reportReceived(event:ResultEvent):void {
      reports = new ArrayCollection();
      reports.source = event.result as Array;
      private function reportInspector():void {
      var temp:Array = new Array();
      temp[0] = reports.length;

      fault="Alert.show(event.fault.faultString, 'Error');">
      <mx:method name="getReportsAll"
      <!-- <mx:method name="addReports" result="reportSaved(event)"/>
      <mx:method name="deleteReports" result="reportDeleted(event)"/> -->
      </mx:RemoteObject> Text
        • 1. Re: Setting an array to results from remoteObject
          inlineblue Level 1
          This leads me to suspect that event.result is not an array. The "as" operator will return null if it can't perform the cast. Are you sure that the debugger shows the type of event.result as being Array?
          • 2. Re: Setting an array to results from remoteObject
            arizona Level 1
            Hi inlineblue,

            Thank you for responding. I am new to flex and am very disappointed getting stuck on such a basic issue. I am trying to immerse myself in it so that I can become a master but when a simple assignment stops my work for a day it is very frustrating.

            Actually the alert.result is an ArrayCollection. So I thought that you had something there. I tried

            var myArray1 = new ArrayCollection();
            myArray1 = alert.result;
            Did not work. // no error but the collection was empty.

            I tried
            var myArray2 = new Array();
            myArray2 = alert.result.source; //since source is of array type.

            Again no compiler errors but myArray2 is empty after assignment.

            When I put a break point in and inspect the source of the alert.result it is full of data. I do not know what to do.

            Could it be possible that some package is not available to my instance of flex or that it is corrupt?


            • 3. Re: Setting an array to results from remoteObject
              arizona Level 1
              I created a new project. I copied all the files over to the new project and everything worked.

              I do not know what was corrupted but something was.