Load External Image in Flex Mobile App - actionscript-3

I am trying to load images from my website on my Flex Mobile Application. When I run the code using my localhost, everything works perfectly. However, when I try to load the images from my live website, I get the error:
IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2036: Load Never Completed. URL: http://sortsports.com/images/players/nfl/sketch/8850x300.jpg" errorID=2036]
I am using a Loader to load the image and a LoaderContext setting checkPolicyFile to false.
var lc:LoaderContext = new LoaderContext();
lc.checkPolicyFile = false; // bypass security sandbox / policy file - does this effect quality when scaling? - See more at: http://www.onegiantmedia.com/as3--load-a-remote-image-from-any-url--domain-with-no-stupid-security-sandbox-errors#sthash.ZRnTf99k.dpuf
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, playerImageLoadCompleteHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
trace('loading: ' + remoteFileUrl);
loader.load(new URLRequest(remoteFileUrl), lc); // add a loader context to not check the policy file
private function playerImageLoadCompleteHandler(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
playerImage.source = loaderInfo.content;
}
private function loaderIOErrorHandler(ev:Event):void{
trace("Image not found and ioError: " + ev);
playerImage.source = 'k';
}
I also have a crossdomain policy in the root of the url:
<?xml version="1.0"?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
I load the crossdomain like this:
Security.loadPolicyFile(Globals.currentDomain + "/crossdomain.xml");
And I try to allowDomain
//Security.allowDomain('http://sortsports.com/');
But I get an error
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
So I put it in the try catch:
try {Security.allowDomain("*");}catch (e) { trace("e.message: " + e.message); };
Again, the code works great on localhost. I don't think using a proxy is a possibility as this is a mobile app.

Related

Adobe Air Writing a File throwing SecurityError: fileWriteResource

I am trying to write into the file and everything was working fine upto the time i used File.desktopDirectory but after updating it with File.applicationDirectory lots of places i am getting security issue.
So overcome this issue i tried this code
File file = File.applicationDirectory.resolvePath("urlsList.properties");
var writeStream:FileStream = new FileStream();
var pathToFile:String = file.nativePath;
var destination:File = new File (pathToFile);
writeStream.open(destination, FileMode.WRITE);
file.moveTo (destination, true);
writeStream.close();
Now its throwing error at file.moveTo (destination, true);
SecurityError: fileWriteResource at flash.filesystem::File/moveTo()
at Demo/addNewUrl()[C:\Users\subodhc\Adobe Flash Builder
4.5\Demo\src\Demo.mxml:319] at Demo/writeFile()[C:\Users\subodhc\Adobe Flash Builder
4.5\Demo\src\Demo.mxml:283] at Demo/__deleteServerConfig023_click()[C:\Users\subodhc\Adobe Flash
Builder 4.5\Demo\src\Demo.mxml:575]

Error #2035 URL not found - file path configuration

I try to open a swf from another swf. They are on the same folder. Here is the code block I am trying to get the file.
var newRequest:URLRequest;
var path:String = "mahmut"+".swf";
newRequest = new URLRequest(path);
newLoader = new Loader;
newLoader.load(newRequest);
newLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeFn);
newLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, camaluriFn);
function camaluriFn(e:IOErrorEvent)
{
trace("Error: " + String(e));
}
and trace throws Error #2035: URL Not Found. URL: app:/mahmut.swf
So how can I give right path and it can open display successfully?
Doesn't matter where those files are, what matters is from where they are loaded. In your case all local paths are from the app root no matter what. If you swf are in folder "myswfs" then the right path is not just "mahmut"+".swf" but "myswf/smahmut.swf".

Flash cannot setup XMLSocket

I just started a project in flash, but it can't startup XMLSocket.
My code:
import Network.CommunicationBootstrap;
var network:CommunicationBootstrap = new CommunicationBootstrap();
network.start("127.0.0.1", 30000);
Package Network classs CommunicationBootstrap:
package Network {
import flash.net.XMLSocket;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
public class CommunicationBootstrap {
private var socket:XMLSocket = new XMLSocket();
public function CommunicationBootstrap() {
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
public function start(ip:String, port:int):void {
this.socket.connect(ip, port);
trace("Testing this out!");
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
}
}
What my errors are:
ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1"]
securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: file:///C|/Users/iufrs/Documents/AS3/1/Torn.swf cannot load data from 127.0.0.1:30000."]
(gotten by trace and the 2 events)
This is (as the message hints) due to the sandbox your swf is running in.
from the docs
Local file describes any file that is referenced by using the file:
protocol
Which is what you are doing here.
Further:
The local-with-filesystem sandbox—For security purposes, Flash Player
places all local SWF files and assets in the local-with-file-system
sandbox, by default. From this sandbox, SWF files can read local files
(by using the URLLoader class, for example), but they cannot
communicate with the network in any way. This assures the user that
local data cannot be leaked out to the network or otherwise
inappropriately shared
This is what is causing you to see the error.
If you intend your swf to be hosted by a web server, then you should make sure the swf can be loaded from your webserver running on 127.0.0.1, and you should load it over http, e.g. as http://127.0.0.1/YourSwf.swf
If you want to run your sef from the filesystem, you need to compile it to run in the 'local-with-networking' sandbox, the link explains how.
.

as3 URLLoader always failing with IOError

I'm having problems with URLRequest in a flex application, it fails with whatever url I try:
var r:URLRequest = new URLRequest("http://stackoverflow.com");
var l:URLLoader = new URLLoader();
l.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void {
trace(e);
});
l.load(r);
This is the error I get:
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Error de secuencia. URL: http://stackoverflow.com"]
Obviously the url is not down as I'm using it right now to post this. I've also tried others such as google.com which work ok in my browser, and I get the same error. Any one knows what could be the problem?
Thank you

URLLoader in actionscript 3 not using the same web session on some machines?

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://domain.net/registerVideo.php");
var vars:URLVariables = new URLVariables();
vars.action = "insert";
vars.record = publishMode;
vars.name = streamName;
request.data = vars;
request.method = URLRequestMethod.POST;
loader.load(request);
The above client side code works for my machine(using the same web session),
but not working for some other machines.
Is this a known bug??
My guess is that you are testing this from the domain.net machine but loading from somewhere else. If it is not working from another machine, you may have a security sandbox violation. Try to add a crossdomain.xml file on your server with something like this to see if that fixes your issue.
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
I wouldn't advise keeping this for production if it fixes your issue. For more info, see this link.