我在 Flash 中有一个项目,我使用带有一些数据的网络服务器.我阅读了该信息(json):
I have a project in Flash and I use a webserver with some data. I read that information (json) with:
var url:String = "URL REQUEST"; var request:URLRequest = new URLRequest(url); var loader:URLLoader = new URLLoader(); loader.load(request);我在 TextField 中使用该信息.这工作正常并正确显示我的数据.但是,当我发布我的作品或打开文件时,.swf 不显示数据.
and I use that information in a TextField. This works fine and show my data properly. But, when I publish my work or open the file .swf doesn't show the data.
在 Adobe Flash 内部工作正常.外面不行.
Inside the Adobe Flash works fine. Outside doesn't work.
我有一个在 nodeJS 中运行服务的树莓派.路由器的门是开着的.
I have a raspberry pi with a service in nodeJS running. The door is open in the router.
我的 nodeJS
var express = require('express'); var bodyParser = require('body-parser'); var app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:true})); const port = process.env.PORT || 3001; const SERVER_ROOT = "localhost:" + port; var messages = {}; messages["a1"] = blablabla; -- messages["n"] = blablabla; function buildMessage(newID, text, user){ const now = new Date(); return { }; }; app.route("/message") .get(function(req, res) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.json(messages); }); app.param('messageID', function(req, res, next, messageID){ req.messageID = messageID; return next(); }) app.listen(port, function() { console.log("Listening on " + port); }); 推荐答案这是一个典型的安全错误,当 swf 尝试加载其他域中的内容而不是它自己的域并且没有执行此操作的授权时会触发该错误.因此,为了避免这种类型的安全错误,您必须在要加载数据的服务器的根目录下创建一个 crossdomain.xml 文件.要更深入地了解事物,请查看此架构(从 Adobe 跨域策略文件) :
This is a classic security error which is fired when an swf try to load content in another domain other than its own and didn't has authorization to do that. So to avoid this type of security error, you have to create a crossdomain.xml file at the root of the server from where you want to load data. To more understand things, take a look on this schema ( taken, and edited, from Adobe Cross Domain Policy File) :
所以在这种情况下,为了允许 a 中的 swf 文件从 b 加载数据,我们必须添加一个 crossdomain.xml 文件在 b 的根目录中,因此我们可以使用 b/crossdomain 访问它.有关此文件的内容和更多详细信息,您可以查看上面的跨域规范链接.它可以是这样的:
So in this case, to allow an swf file in a to load data from b, we have to add a crossdomain.xml file in the root of b, so we can access to it using b/crossdomain. For the content of this file and more details about it, you can see the link above of the crossdomain specification. It can be like this :
<?xml version="1.0"?> <cross-domain-policy> <!-- if used alone, allow only all a requests but not its sub-domains --> <allow-access-from domain="a"/> <!-- if used alone, allow all a sub-domains and a requests --> <allow-access-from domain="*.a"/> <!-- if used alone, allow only b.a sub-domain requests --> <allow-access-from domain="b.a"/> </cross-domain-policy>我希望所有这些都可以帮助您解决问题.
I hope all this can help you to resolve your problem.
更多推荐
AS3 + HTTP GET 不起作用
发布评论