Flash AS3 : Error #1014 : When loading remotely but not locally - actionscript-3

Starting with a blank project, when I load a SWF which has a dependence on ISomeInterface defined in a swc which is compiled into my blank project
var lc:LoaderContext = new LoaderContext( true, ApplicationDomain.currentDomain );
var loader:Loader = new Loader();
loader.load( new URLRequest( "Some.swf"), lc );
Not too surpisingly all is good as the interface it requires is already in the application domain into which it has been loaded.
However, when I load the same file from a remote url
loader.load( new URLRequest( "http://127.0.0.1/Some.swf"), lc );
I get the evil
[Fault] exception, information=VerifyError: Error #1014: Class ISomeInterface could
not be found
What am I missing that makes these different?

My issue appears to have been 2 fold
1) When loading the asset locally, it will by default be loaded into the correct security domain. However, when loading from a web site, I need ensure that I set the security domain correctly
new LoaderContext( true, ApplicationDomain.currentDomain, SecurityDomain.currentDomain )
2) However, you can only use the SecurityDomain when the swf you are doing the loading from was actually itself loaded remotely :
Security.sandboxType == Security.REMOTE
So no mix mode of local and remote.
In the end it was a matter of simply loading the first SWF from a website, and adding the correct SecurityDomain.
In my searching, this was the best discorse I found on the topic of Security Domains and Applciation Domains http://www.senocular.com/flash/tutorials/contentdomains/

Since your testing locally you might want to check this out:
http://jansensan.net/flash-player-security-settings-to-develop-locally
Essentially go to the Flash Player security page:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html
Click Edit Location -> Add location
Add the project folder or your filesystem root.

Related

Loading and displaying externally hosted SWF into an Adobe Air application

I have a game written in AS3 on top of Adobe AIR. Now that I've found a publisher for the game, I need to load an external swf to display advertisements (cpmstar). Unfortunately it hasn't been straightforward, and I can't seem to get any advertisements to display on the stage. I'm wondering if I'm doing something wrong. Here's my code:
Security.allowDomain("server.cpmstar.com");
var cpmstarViewSWFUrl:String = "http://server.cpmstar.com/adviewas3.swf";
var cpmstarLoader:Loader = new Loader();
var allowSWF:LoaderContext = new LoaderContext( false, ApplicationDomain.currentDomain, null );
allowSWF.allowCodeImport = true;
var urlRequest:URLRequest = new URLRequest(cpmstarViewSWFUrl + "?contentspotid="+ < my ID > );
cpmstarLoader.load( urlRequest, allowSWF );
addChild( cpmstarLoader );
With the above, I see the url request successfully complete ( I can also see the 200 success response in Chrome ) , but I never see any content added to my stage. I've also tried, with no success, loading the distant URL with URLLoader and then reloading it through loadByte as described here: AIR Loading server hosted swf into same sandbox
If the code above looks okay, could the advertisers swf file be doing something that isn't allowing it to play nicely with this code? If so, what?
Thanks in advance.

Flash sandbox not enabling me getting JSON data from server - AS3

i'm setting up a local SWF file that has to display some JSON data retrieved from a remote web server in some dynamic text fields.
Code:
Security.allowDomain("api.yourserver.com");
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://api.yourserver.com/yourendpoint");
request.method = URLRequestMethod.GET;
request.contentType = "application/json";
loader.load(request);
loader.addEventListener(Event.COMPLETE, decodeJSON);
function decodeJSON(event:Event):void{
var loader:URLLoader = URLLoader(event.target);
var Info:Object = JSON.parse(loader.data);
cont.textfield1.text = Info.text.field1;
cont.textfield2.text = Info.text.field2;
cont.textfield3.text = Info.text.field3;
}
Control > Test - It works. When run standalone it doesn't. I get the 2028 error (sandbox violation).
What i tried:
The LoaderContext method explained here on StackOverflow but i get a 2124 error (Loaded file is an unknown type - seems like the Loader method can only be used with stuff like SWF or medias like JPG etc.);
Setting local playback as described always here on StackOverflow but it didn't help;
Setting up and exception in the Global Flash Player Trust directory as explained here but got the 2028 again;
Anyone who was able to overcome this and willing to explain how or at least pointing in the right direction?
Thanks in advance!
I think that your current published file has just assess to local files only and not network ones, that's why you got security #2028 error.
To avoid that, you can change the Local playback security for your published swf from the Publish Settings to Access network only :
If you still get security errors when testing locally ( like #2048 error ), take a look on my answer of this question to add your local swf file to the trusted locations ...
Hope that can help.

Flash player stuck at Frame 1 after calling a function

I'm working in a flash CS6 and I'm having a trouble: After calling a function, player freezes at frame 1. This not happend during Ctrl+ENTER preview, but when I play the .swf file published (using flash player or opening it on a web browser, doesn't matter) is when the problem begin.
This is the code:
import flash.display.MovieClip;
var code:int = 0
var temp:int = 0;
var _xmlURL:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=368335%20and%20u=%27c%27";
var _xmlData:XML;
function loadXML(xmlURL:String):void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(_xmlURL);
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadData);
}
function loadData(event:Event):void{
_xmlData = new XML(event.currentTarget.data);
var dataG:XMLList = _xmlData.results.channel.item.elements();
code = dataG[5].#code;
temp = dataG[5].#temp;
trace(code);
trace(temp);
}
loadXML(_xmlURL);
I'm not used to use as3, I don't know if I'm using it right.
As you can see, the code reads an external xml file using "URLLoader" and its method ".load".
Thanks for your help.
BTW, I've already tried to play the published ".swf" file in other PCs (xp, seven, 8), one of them with Windows recently installed (seven).
Most likely (because you're loading in resources from the internet, and it works when you test), this has to do with the security settings of your application.
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 acess local only.
This hangs up a lot of people when they first start using flash.
It's always good practice too, to listen not just for the COMPLETE event on your loaders, but also for error events such as:
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandlerFunction);
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, ioErrorHandlerFunction);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandlerFunction);
In your case, it's probably throwing a security error.

how to load swf immediately from local data

i want to save the swf data in local so i can recreate it again and again.though most web browser has cache mechanism ,once a resource is downloaded,the application can get the resource from the local. but the browser still need to check the remote server's file's time stamp to make sure the remote file was not updated.that's make the process delay.
i want to handle it by myself ,so i save the downloaded data in the application.the trouble is i didn't find a way to recreate a new instance of the loaded swf immediately.for example,if i download a jpeg file,i finally got a bitmapdata , so i keep the bitmapdata,if i need a copy,i simply use clone() . but swf is different,i dont know how to clone the swf instance.
my way is load swf as binary array,and load it by Loader.loadBytes,here's my code.
public static function loadSWFByte(data:ByteArray,callback:Function,domain:ApplicationDomain):void{
var loader:Loader = new Loader();
var f:Function = function(e:Event):void{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,f);
if(callback!=null){
callback(loader.content,loader.contentLoaderInfo);
}
}
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,f);
loader.loadBytes(data,new LoaderContext(false,domain));
}
if i need to create it,i always use callback,thus make coding complicated.Is there a way i can get the instance without using callback?
Loading SWF bytes or from URL is always async , but You can load it once and clone each time:
// when loader load is complete
var cl:Class = loader.content["constructor"];
var clone:* = new cl();

Is there reliable method of ensuring crossdomain policy files have been retrieved for all Facebook image servers?

I've recently started putting together a Facebook Connect AS3 app and retrieving objects and images through the Graph API.
Running anywhere but locally, I receive security errors of the form:
SecurityError: Error #2122: Security sandbox violation: Loader.content: xxxx cannot access http://photos-a.ak.fbcdn.net/xxxx.jpg
A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
If I add a line of the form:
Security.loadPolicyFile("ht_tp://photos-a.ak.fbcdn.net/crossdomain.xml");
-then I'm fine for that server, but it seems that there are any number of domains with the photos-[letter] format. I've added the one for each in the alphabet - which happily retrieves crossdomain files successfully - but it doesn't seem like a nice solution, and doesn't accommodate any new hosting setups Facebook may will implement in the future.
One thing I'd considered was retrieving the crossdomain policy file on a per image basis, capturing the domain from the image URL before making the image request. Unfortunately, at least via the Graph solution (and I haven't looked too closely at the others), their servers resolve the image url after the request is made, from something more generic like:
ht_tps://graph.facebook.com/[objectId]/picture?type=small&access_token=[accessToken]
Has anyone found a more dependable means of ensuring that images can be retrieved without security sandbox violations? Or do Facebook maintain a definitive list that developers need to keep an eye on?
Thanks!
Load the facebook crossdomains on the initial of your application as below;
Security.allowDomain("*");
Security.allowInsecureDomain("*");
Security.loadPolicyFile("http://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("https://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("https://profile.ak.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("http://profile.cc.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("https://profile.cc.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("http://fbcdn-profile-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("https://fbcdn-profile-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("http://fbcdn-sphotos-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("https://fbcdn-sphotos-a.akamaihd.net/crossdomain.xml");
and then whenever you want to load an image from facebook, set the checkPolicy flag to true using the Loader's LoaderContext as below;
var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;
context.checkPolicyFile = true;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadFacebookPhoto);
loader.load(new URLRequest(YOUR_FACEBOOK_PHOTO_URL),context);
private function onLoadFacebookPhoto(e:Event):void
{
addChild(Bitmap(LoaderInfo(e.target).content));
}
Ideally I would guess that you'd want Flash to get the policy file on its own, rather than triggering it with Security.loadPolicyFile. Have you tried simply setting the checkPolicyFile flag for your Loader's LoaderContext?
Alternately, I believe that when you use URLLoader instead of Loader, Flash will request a policy file automatically, so you could try that as well. The tricky thing is that if you use Loader, Flash will let you display what you've loaded even without a crossdomain policy, so it doesn't load one unless you tell it to. When you use URLLoader, the load itself is not allowed unless there's a policy file, so Flash gets it automatically.