5 Replies Latest reply on Feb 22, 2007 7:59 AM by 187_2007

    ArrayCollection Not working

    187_2007 Level 1
      My Init Function calls my RemoteObject which passes a string. I am returning an array from the RemoteObject. Once return comes back to Flex from my RemoteObject, my result function is called (myresult). This simply calls a class sends my result array into the class and then I send the result to my ArrayCollection. Outside my FOR loop I run:

      trace(ObjectUtil.toString(myArrayofStructs));

      This WILL print out the array that is in my Array collection. I then have a TEST function which is a ran when I click on a button. As you can see it is the same code above:

      trace(ObjectUtil.toString(myArrayofStructs));

      But this time there is nothing in the ArrayCollection. It's like it's loosing scope or something. I'm not sure what the issue is. I've been working on this for 2 days now... Any idea?




      <mx:Script>
      <![CDATA[
      import Classes.SiteSpecs.SiteSpecs;
      import mx.utils.ArrayUtil;
      import mx.rpc.events.ResultEvent;
      import mx.utils.ObjectUtil;
      import mx.collections.ArrayCollection;
      import Classes.SiteSpecs.*;

      [Bindable]
      public var myArrayofStructs:ArrayCollection = new ArrayCollection();


      public function init(nodeSent:String):void{
      callGetData.returnSiteSpecInfo(nodeSent);

      }

      public function myresult(event:ResultEvent):void{
      var result_Array:Array = event.result as Array;

      for(var i:int =0; i<result_Array.length; i++) {
      var buildSiteSpecs:SiteSpecs = new SiteSpecs();
      buildSiteSpecs.init(result_Array );
      myArrayofStructs.addItem(buildSiteSpecs);
      }
      trace(ObjectUtil.toString(myArrayofStructs));
      }


      private function test():void{
      trace(ObjectUtil.toString(myArrayofStructs));
      }
      ]]>
      </mx:Script>
        • 1. Re: ArrayCollection Not working
          michael_ramirez44 Level 1
          You wrote this:
          buildSiteSpecs.init( result_Array );

          Did you mean this:
          buildSiteSpecs.init( result_Array );

          If you didn't then what is the reason for the loop?
          • 2. Re: ArrayCollection Not working
            187_2007 Level 1
            Well, The loop is so that I can run my Array into a class, it's sorta like a template. If something is missing in the array it will set it to a default via a constructor.. But I can exclude it all together and have this...

            public function myresult(event:ResultEvent):void{
            var result_Array:Array = event.result as Array;
            myArrayofStructs.source = result_Array;
            trace(ObjectUtil.toString(myArrayofStructs));
            }

            And I still get the same result as I stated above.
            • 3. ArrayCollection Not working
              187_2007 Level 1
              The TRACE above yields this result:

              (mx.collections::ArrayCollection)#0
              filterFunction = (null)
              length = 1
              list = (mx.collections::ArrayList)#1
              length = 1
              source = (Array)#2
              [0] (Object)#3
              AD_SERVER_USED = "proprietary technology"
              AJAX = 0
              FORMAT_HTML = 1
              FORMAT_LINK = 0
              FORMAT_TEXT = 0
              FORMAT_ZIP = 1
              FOURTHPARTY = 0
              INTERIAM = " /eyewonder/interim.html"
              LINK_TO_SPECS = " http://solutions.yahoo.com/adspecs/richmedia/rm_formats.html"
              NOTES = "If you wish to collect personal information within advertisements, those ad units will need to: 1) Clearly identify your organization. 2) Provide a direct link to your privacy policy, adjacent to the submit button. 3) Clearly identify the purpose for collecting the information."
              PARENT_COMPANY = 0
              PARENT_SITE_SETTINGS_TO_ALL = 0
              PROGRESSIVE_DOWNLOAD_STREAMING = "streaming"
              SERVE_IFRAME = 0
              SITE_ID = 1
              ZIP = 1
              uid = "B51F4915-8E64-8CDB-32E4-EA1364114BEE"
              sort = (null)
              source = (Array)#2



              The TRACE in the TEST Function yields this:


              (mx.collections::ArrayCollection)#0
              filterFunction = (null)
              length = 0
              list = (mx.collections::ArrayList)#1
              length = 0
              source = (Array)#2
              uid = "5F2345C7-A3E7-16B2-93D4-EA1354BF9C5B"
              sort = (null)
              source = (Array)#2



              Why are thy different?
              • 4. Re: ArrayCollection Not working
                michael_ramirez44 Level 1
                Instead of:

                var result_Array:Array = event.result as Array;

                Declare Array outside your result event.

                public var result_Array:Array;

                • 5. Re: ArrayCollection Not working
                  187_2007 Level 1
                  Okay, let me try that.... Thanks