0

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);

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.

Inside the Adobe Flash works fine. Outside doesn't work.

I have a raspberry pi with a service in nodeJS running. The door is open in the router.

My 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 = "http://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);
});
stlkr
  • 15
  • 6
  • Try to download a flash player debug version [here](https://www.adobe.com/support/flashplayer/downloads.html) to see if you get an error, otherwise I think that you should embed the font used in your text field, take a look here to see how to [embed fonts for a dynamic text field](https://support.google.com/richmedia/answer/2661568?hl=en). – akmozo Dec 19 '14 at 19:53
  • This is the error with flash player in debug mode Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: file: ... – stlkr Dec 20 '14 at 11:02
  • How are you running the swf on the Pi? Off a website? a local html page? An AIR application? – BadFeelingAboutThis Dec 20 '14 at 16:32
  • my Pi is only for the server. And in my desk, I develop my flash animation and I get the values from the Pi. – stlkr Dec 20 '14 at 16:36
  • how is it run from your desk then? AIR App? HtmlPage? just a swf file? – BadFeelingAboutThis Dec 20 '14 at 16:44
  • Yes...I use a swf file to test...when I use in Adobe flash, this works fine, but when I run outside (swf file or Html page, doesn't work). – stlkr Dec 20 '14 at 16:56
  • Just serve the html page from your Pi, or export as AIR app – BadFeelingAboutThis Dec 20 '14 at 17:18

2 Answers2

0

Most likely you are receiving a security error. Here are some steps you can take:

  1. Make sure to add the appropriate listeners to your loaders so you can properly handle errors.

    loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandlerFunction);
    loader.addEventListener(IOErrorEvent.NETWORK_ERROR, ioErrorHandlerFunction);
    loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandlerFunction);
    
  2. Make sure you are publishing with the correct security sandbox setting.

    Go to your publish settings file -> publish settings.

    You'll see a drop down labelled Local playback security. Ensure this is set to access network only and not the default access local only.

If you handle your errors, you'll at least know what the problem is. If this doesn't solve your problem, add a global error handler and share what is being thrown (if anything).

You can do that with the following on your main timeline or document class:

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);

function uncaughtErrorHandler(event:UncaughtErrorEvent):void {
    if (event.error is Error) {
        var error:Error = event.error as Error;
        trace(error);
    }
    else if (event.error is ErrorEvent){
        var errorEvent:ErrorEvent = event.error as ErrorEvent;
        trace(errorEvent);
    }
}

EDIT

From reading your updates, it looks like you could easily resolve this by dishing out your swf from the Pi Node JS Server in the browser. (Publish with html then copy to the server then access it in your web browser).

BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • This is the error with flash player in debug mode Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: file: ... In my publish settings, I choose access network only and I have same problem – stlkr Dec 20 '14 at 13:23
  • More info: My server is in nodeJS, running in a raspberry pi, and all configurations look fine. I search a little and I found the as3httpclientlib, but I have a problem with import. Any help? – stlkr Dec 20 '14 at 13:29
  • Your issue then will be one of cross domain rules. Though it still a very good idea to add error listeners to your loader. – BadFeelingAboutThis Dec 20 '14 at 16:29
0

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) :

enter image description here So in this case, to allow an swf file in a.com to load data from b.com, we have to add a crossdomain.xml file in the root of b.com, so we can access to it using b.com/crossdomain.com. 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.com requests but not its sub-domains -->
    <allow-access-from domain="a.com"/>
    <!-- if used alone, allow all a.com sub-domains and a.com requests -->
    <allow-access-from domain="*.a.com"/>
    <!-- if used alone, allow only b.a.com sub-domain requests -->
    <allow-access-from domain="b.a.com"/>
</cross-domain-policy>

I hope all this can help you to resolve your problem.

akmozo
  • 9,829
  • 3
  • 28
  • 44
  • My server is a single nodeJS file...how I introduce the xml file for cross domain? – stlkr Dec 20 '14 at 16:16
  • @stlkr How do you request your data ? – akmozo Dec 20 '14 at 16:18
  • my server is running in my raspberry pi in nodeJS. I run the file like this: node --harmony server.js and I get data from this mini-server in as3 like in my first question. – stlkr Dec 20 '14 at 16:26
  • I updated my first post with the nodeJS server; my protocol is http http://blabbabla:3001/message and return my json – stlkr Dec 20 '14 at 16:32