Search code examples
actionscript-3jsonflashvars

json in flashvars


I want to use josn in my flashvars and I'm having trouble

here is my json

var flashvars = { 
                xmlFile: '<?php echo $preface.$xmlpath; ?>',
                preface: '<?php echo $preface; ?>',
                "preload": {
                    "url": "flash/someflash.swf",
                    "x": "375",
                    "y": "237"
                }
                };

here is what I have been trying

    var jsondata:String  = this.loaderInfo.parameters.preload;
    if(jsondata){
        //var jsonData:Object = JSON.decode(jsondata.toString()) ;

     error_txt.text = jsondata.toString();
    }

error_txt returns "object Object" but I can't access any part of the json object


Solution

  • I believe what is happening here is that Javascript calls .toString() on your flashvars variable and passes the resulting string to flash. If my hunch is correct you will need to pass the JSON as a string such as this.

    var flashvars = "{xmlFile:'myFile.xml',
                      preface:'Preface',
                       {
                        'url': 'flash/someflash.swf',
                        'x': '375',
                        'y': '237'
                       }
                     }";