Why my flash is not getting the JSON data from a s

2019-09-09 21:37发布

问题:

I am creating a flash project where I load data from server. When I run that from flash software using Ctrl+Enter or create exe then that works but when I run swf normally or using a browser then it is not working.

I tried to add this code but not working

Security.loadPolicyFile("policy.xml");
or
Security.allowDomain("192.168.10.8");
Security.allowDomain("www.example.com");

My policy.xml is

<cross-domain-policy> 
    <allow-access-from domain="*" /> 
    <allow-access-from domain="www.example.com" /> 
    <allow-access-from domain="192.168.10.8" /> 
</cross-domain-policy>

Please advice me.

回答1:

I had a similar problem. Flash will initially try to get the flash policy from a different port (843). See this: http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html



回答2:

Why not try use URLlaoder? and set up a web with service call.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html



回答3:

I suggest to try LoaderContext class. Here is example code:

Security.allowDomain("*");
Security.allowInsecureDomain("*");

var loader:URLLoader = new URLLoader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onDataLoaded);
loader.load(new URLRequest("http://www.example.com/json_file_path.json"), new LoaderContext(true));