0

I'm using this bit of javascript with json string to send data to flash project

        var flashvars = { 
        xmlFile: 'http://iyt.psu.edu/xml/abington/home.xml',
        preface: 'http://iyt.psu.edu/',
        preload: '{"url":"flash/project.swf","x":"375","y":"237","link":"home","tween":{"prop":"y","begin":"0","finish":"-200","duration":"1"}}'
    };

however the preload line causes problems in IE anyone have any idea what I"m might be doing wrong besides using IE ; ^ )

12
  • Why do you have a json string in a json object?
    – erjiang
    Mar 1, 2011 at 20:50
  • Well... you are using IE. But you already know that. ;)
    – BastiBen
    Mar 1, 2011 at 20:50
  • Is preload property supposed to be string or object? If object it should not be enclosed between quotes (single quotes around the { ... }.
    – amit_g
    Mar 1, 2011 at 20:50
  • Neither IE7 nor IE8 complain about that code when I try it. I suggest that the problem diagnosis may need reexamination.
    – Pointy
    Mar 1, 2011 at 20:52
  • @mcgrailm - clarify something please: does IE complain about the code you posted, or about the string value of "preload" when you pass it to some JSON decoder or something?
    – Pointy
    Mar 1, 2011 at 20:54

3 Answers 3

2

If there is a trailing comma and you are using FireFox or a Webkit based browser then everything will look fine. But in IE any trailing commas with no more object properties will cause a problem that may not be so obvious.

This will fail. see the extra comma at the end:

var flashvars = { 
        "xmlFile" : "http://iyt.psu.edu/xml/abington/home.xml",
        "preface" : "http://iyt.psu.edu/",
        "preload" : "{'url': 'flash/project.swf' , 'x': '375 ', 'y': '237', 'link': 'home', 'tween' : {'prop':'y','begin' : '0', 'finish' : '-200' , 'duration' : '1' }}",
}

Also properly formatted JSON that passes the http://www.jslint.com/ test never hurts.

var flashvars = { 
        "xmlFile" : "http://iyt.psu.edu/xml/abington/home.xml",
        "preface" : "http://iyt.psu.edu/",
        "preload" : "{'url': 'flash/project.swf' , 'x': '375 ', 'y': '237', 'link': 'home', 'tween' : {'prop':'y','begin' : '0', 'finish' : '-200' , 'duration' : '1' }}"
}

But the JSON you pasted in looks ok. Also, maybe an apostrophe was included from a Word document.

2
  • changing the quotes around fixes the problem of ie passing the stirng probperly but then my actionsript json decoder breaks var jsonData:Object = JSON.decode(jsontext) ;
    – mcgrailm
    Mar 1, 2011 at 22:35
  • this helped me out so +1 to you
    – mcgrailm
    Mar 4, 2011 at 21:18
0

Maybe it’s the / that needs to be escaped in JSON strings.

4
  • It doesn't have to be valid JSON; it's a JavaScript assignment statement. The contents of the "preload" variable looks like JSON to me, though strictly speaking JSON does require forward slash to be escaped (I don't know why).
    – Pointy
    Mar 1, 2011 at 20:53
  • @Darin Dimitrov: According to RFC 4627 it isn’t.
    – Gumbo
    Mar 1, 2011 at 20:54
  • great to know. Thanks for pointing this out. I wonder if this is the culprit here. Mar 1, 2011 at 20:56
  • Well according to the OP's latest comments, it's just a JavaScript error of some sort. (Maybe.)
    – Pointy
    Mar 1, 2011 at 21:00
0

actually you should encode the json string using server side or javascript tool and then AS3 will automatically decode it:

for example in JSP:

var flashvars = { 
        xmlFile: 'http://iyt.psu.edu/xml/abington/home.xml',
        preface: 'http://iyt.psu.edu/',
        preload: '<c:out value="{"url":"flash/project.swf","x":"375","y":"237","link":"home","tween":{"prop":"y","begin":"0","finish":"-200","duration":"1"}}'" />'
    };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.