Flash Media Server calls a page that returns JSON data

I am very new to Flash development.

I have an asp.net mvc site that has a controller action that returns JSON.

I have a Flash Media Server setup that needs to call this controller action every 15 minutes to get the current schedule. I can get FMS to call the site (and every 15 minutes not a problem) and I get the JSON right now as a string, but I need to parse it from string to objects in order to use the returned data.

Any pointers or ideas would be greatly appreciated.

+2


source to share


2 answers


Mike Chambers has an AS3 library on github ( https://github.com/mikechambers/as3corelib ). One of the libraries is for JSON serialization and parsing. Here's an example of it in a Flex MXML doc, but it will be the same in AS3 (you basically get JSON data and then call JSON.decode () to get an array.):

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

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" 
layout="absolute"
creationComplete="service.send()" viewSourceURL="srcview/index.html">

<mx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.rpc.events.ResultEvent;
        import com.adobe.serialization.json.JSON;

        private function onJSONLoad(event:ResultEvent):void
        {
            var rawData:String = String(event.result);
            var arr:Array = (JSON.decode(rawData) as Array);

            var dp:ArrayCollection = new ArrayCollection(arr);

            grid.dataProvider = dp;
        }
    ]]>
</mx:Script>

<mx:HTTPService
    id="service"
    resultFormat="text"
    url="http://weblogs.macromedia.com/mesh/mashedpotato.json"
    result="onJSONLoad(event)" />

<mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10">
    <mx:columns>
        <mx:DataGridColumn headerText="Service" dataField="src"/>
        <mx:DataGridColumn headerText="Title" dataField="title"/>
    </mx:columns>
</mx:DataGrid>

      



0


source


I am assuming you are using a webservice from FMS to get the data. In ActionScript 1, I think you should use eval () to get an object that you can query.



var callback = mWebService.NewGuid();
mWebService.onResult = function(resultString){
    var resultObject = eval(resultString);
    trace(resultObject.mProperty1);
}

      

0


source







All Articles