4 Replies Latest reply on Jun 14, 2011 5:19 AM by Arul pugazh

    Object Proxies into ArrayCollections

    Arul pugazh

      1 . Retrieve data from MySQL table using PHP and echo it in XML .
      - This part is working fine and prints the data in XML form

      2 .I receive that XML and assign it as ArrayCollection . Then pass that ArrayCollection into a Component .
      - For this i have done :


      My code :


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" minWidth="955" minHeight="600"
                  import mx.collections.ArrayCollection;
                  import mx.controls.Alert;
                  import mx.events.FlexEvent;
                  import mx.rpc.events.ResultEvent;
                  public var _myData:ArrayCollection;


                  protected function service_resultHandler(event:ResultEvent):void
                      _myData=new ArrayCollection();


                  protected function maps1_creationCompleteHandler(event:FlexEvent):void


              <mx:HTTPService id="service" url="map.php" result="service_resultHandler(event)" />
          <comp:Maps creationComplete="maps1_creationCompleteHandler(event)"/>




      The Error i got :
      Type Coercion failed :Cannot convert ObjectProxies into ArrayCollection

      I have previously done this type of conversion and got no errors . This is bugging me very much guys........


      Any suggestions welcome....

        • 1. Re: Object Proxies into ArrayCollections
          CleanCoder Level 2

          In your "service_resultHandler", you initialize "_myData" as a new ArrayCollection, then you immediately assign it the value of the "event.result.map.location". Instead of doing that try casting the event.result.map.location as an ArrayCollection? ("_myData = event.result.map.location as ArrayCollection")

          1 person found this helpful
          • 2. Re: Object Proxies into ArrayCollections
            Arul pugazh Level 1

            @CodeCleaner , Yes , i tried that also .


            But it says :


            TypeError: Error #1009: Cannot access a property or method of a null object reference.


            i.e., _myData is null ........


            Another note :


            I previously accessed a  local xml file using the same method and it worked like dream .


            I will post the map.php file i'm using :


            PHP code :




            $result=mysql_query("select id,name,address,latitude,longitude from location_table");


            echo "<?xml version=\"1.0\" ?><map>";


            while($row = mysql_fetch_assoc($result))
                echo "<location><id>" . $row["id"] . "</id>" ;
                echo "<name>" . $row["name"] . "</name>" ;
                echo "<address>" . $row["address"] . "</address>" ;
                echo "<latitude>" . $row["latitude"] . "</latitude>" ;
                echo "<longitude>" . $row["longitude"] . "</longitude></location>" ;
            echo "</map>";


            Output :


            <?xml version="1.0" ?><map><location><id>4001</id><name>Some Location</name><address>1001 W MacArthur Blvd , Santa Ana ,CA</address><latitude>33.70008360</latitude><longitude>-117.88000488</longitude></locati on><location><id>4002</id><name>Some House</name><address>7464 kipling street , Detroit ,MI</address><latitude>42.36729290</latitude><longitude>-83.08875600</longitude></locatio n></map>


            It exactly prints out what i wanted ......


            So i can't figure out where is wrong ..........

            • 3. Re: Object Proxies into ArrayCollections
              CleanCoder Level 2

              Try setting the "resultFormat" property to "xml" maybe?

              1 person found this helpful
              • 4. Re: Object Proxies into ArrayCollections
                Arul pugazh Level 1

                I have done the most silliest thing in the world .......


                I haven't set any Application Server for my project .


                I set that as PHP and it worked like dream......


                @CleanCoder , thank you very much for the suggestions and more importantly , your time .