Tommy

Tommy


  • Name: [not set]
  • Favorite Languages: [not set]
  • Website: [not set]
  • Location: [not set]
  • About Me: [not set]

Recent Comments

  • Using Flex, PHP, and JSON to Modify a MySQL Database
    07/14/2009 - 04:25

    Hi,

    Well done on writing this great and extremely useful tutorial - I would've had no idea where to start without it. I've got one really irratating problem that I can't figure out.

    I'm doing a similar sort of thing to what your doing but just the first half - I only need to retrieve information from the database. The problem is that I just can't get the datagrid to update.

    The Flex code is:

    import mx.effects.Tween;
                    import mx.core.Application;
                    import mx.events.ScrollEvent;
                    import mx.events.ToolTipEvent;
                    import mx.rpc.events.ResultEvent;
       import mx.collections.ArrayCollection;
       import com.adobe.serialization.json.JSON;

                    [Bindable]
                    protected var inGame:Boolean = false;
                    private var dataArray:ArrayCollection;
                    private var rawArray:Array;
                    private var rawData: String;
                   
                    [Bindable]
                    public var toolTipData:*;
       
       
       private function initDataGrid():void
       {
         dataArray = new ArrayCollection();
         getData.send();
       }
       
       private function getPHPData(event:ResultEvent):void
       {
         //var rawArray:Array;
         //var rawData:String
         rawData = String(event.result);
         rawArray = JSON.decode(rawData) as Array;
         dataArray = new ArrayCollection(rawArray);
         trace("boo");
         trace(rawData); // All the data
         trace(rawArray);
         trace(dataArray);
       }

    With a datagrid:

    <mx:DataGrid id="dgData" x="10" y="10" width="495" height="50" dataProvider="{dataArray}" creationComplete="{initDataGrid()}" click="trace(rawArray);">
          <mx:columns>
                    <mx:DataGridColumn headerText="Garden name" dataField="garden_name"/>
            </mx:columns>
            </mx:DataGrid>

    The HTTPService and php file is correct because I have done a trace (trace()) on rawData. This results in [{"garden_name":"my garden2"}] which is got from the MYSQL database.

    Doing a trace on rawArray results in [object Object].
    Doing a trace on dataArray results in [object Object].

    Can anyone suggest what is happening?

    Thanks,

    Tom