I'm using this bit of javascript with json string to send data to fla开发者_如何转开发sh 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 ; ^ )
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.
Maybe it’s the /
that needs to be escaped in JSON strings.
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"}}'" />'
};
精彩评论