json和flash

By sike On 2007年5月15日 星期二 At 15:13
flash 并没有提供对 json 直接支持,不过我们可以通过这个类来实现:JSON.as。然后就可以在 php 中生成类似这样的文件 data.php:

flashVar=[{"url":"中文支持.flv","name":"中文支持"},
{"url":"http://hello.com/1.flv","name":"say hi 1"},
{"url":"http://hello.com/2.flv","name":"say hi 2"},
{"url":"http://hello.com/3.flv","name":"say hi 3"}]

在 flash 中:

import json;
MyVars = new LoadVars ();
MyVars.load ("data.php");
MyVars.onLoad = function (success:Boolean) {
if (success) {
mslist = JSON.parse(this.flashVar);
for(i=0;i<mslist.length;i++){
trace("url:" + mslist[i].url);
trace("name:" + mslist[i].name);
}
}
}
//output
/*
url:中文支持.flv
name:中文支持
url:http://hello.com/1.flv
name:say hi 1
url:http://hello.com/2.flv
name:say hi 2
url:http://hello.com/3.flv
name:say hi 3
*/
这样比单纯用 xml 爽多了。
更多介绍

标签: ,

for this post

Anonymous 匿名 Says:

你好,json.as下载不下来,能给我一个下载的地址吗?
谢谢

Blogger sorrycc Says:

忘记写邮箱了,
我的邮箱是 sorrycc@gmail.com

Leave a Reply