Flash cannot setup XMLSocket - actionscript-3

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.
.

Related

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".

sendToURL not working in flashplayer 14

This piece of code is working in flashplayer 11 but it's not working in flashplayer 14.
AS3 code :
private function savePDF(pdfBinary:ByteArray, urlString:String):void{
try{
//result comes back as binary, create a new URL request and pass it back to the server
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var sendRequest:URLRequest = new URLRequest(urlString);
sendRequest.requestHeaders.push(header);
sendRequest.method = URLRequestMethod.POST;
sendRequest.data = pdfBinary;
sendToURL(sendRequest);
} catch (e:Error) {
// handle error here
trace("Error in savePDF "+e.message);
trace("StackTrace : "+e.getStackTrace());
}
}
and these are the errors I got :
Error in savePDF Error #3769: Security sandbox violation: Only simple headers can be used with navigateToUrl() or sendToUrl().
StackTrace : SecurityError: Error #3769: Security sandbox violation: Only simple headers can be used with navigateToUrl() or sendToUrl().
at global/flash.net::sendToURL()
at Export2Publish/savePDF()[my_project_dir\src\Export2Publish.mxml:158]
at Export2Publish/GeneratePDF()[my_project_dir\src\Export2Publish.mxml:386]
at Export2Publish/getUrl()[my_project_dir\src\Export2Publish.mxml:138]
at Export2Publish/___Export2Publish_Application1_creationComplete()[my_project_dir\src\Export2Publish.mxml:3]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[my_framework_dir\src\mx\core\UIComponent.as:9051]
at mx.core::UIComponent/set initialized()[my_framework_dir\src\mx\core\UIComponent.as:1167]
at mx.managers::LayoutManager/doPhasedInstantiation()[my_framework_dir\src\mx\managers\LayoutManager.as:698]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[my_framework_dir\src\mx\core\UIComponent.as:8460]
at mx.core::UIComponent/callLaterDispatcher()[my_framework_dir\src\mx\core\UIComponent.as:8403]
Any fix for this issue ?
You can start by using a try and catch like this :
try {
sendToURL(request);
}
catch (e:Error) {
// handle error here
}
If the problem is not visible on dev environment, I recommand you to install a flash debug player which you can download here : Flash Player Downloads to see what kind of error your code will fire.
If your code is fine, in dev and prod environment, you should debug your server side script.

Load External Image in Flex Mobile App

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.

AIR Socket app keeps requesting policy file

I am building the AIR socket server example, as explained on this page.
The AIR app is running fine, it creates a socket on 127.0.0.1 on port 8080.
I am connecting to the server with a SWF running on localhost. This SWF is built using the client example on the same site. The SWF attempts to connect to 127.0.0.1 on port 8080 - so far so good, except that the AIR app now receives a POLICY-FILE-REQUEST:
Received:<policy-file-request/>
Since I've read everywhere that AIR does not require a policy file, why does the AIR app receive this request? And how do you reply with the proper file, from an AIR app?
Actionscript code in the SWF client:
public function XMLSocketExample() {
socket = new XMLSocket();
configureListeners(socket);
if (hostName && port) {
socket.connect(hostName, port);
}
}
public function send(data:Object):void {
socket.send(data);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.CLOSE, closeHandler);
dispatcher.addEventListener(Event.CONNECT, connectHandler);
dispatcher.addEventListener(DataEvent.DATA, dataHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}

Getting Error #2032: Stream Error. in Flash while sending url request to server

I am sending http request to server via URLLoader in Flash. My Code is:
var urlLoader:URLLoader=new URLLoader();
var urlRequest:URLRequest=new URLRequest();
var urlparam:URLVariables= new URLVariables();
urlparam.req=JSON.encode(workout);
urlRequest.method="POST";
urlRequest.data=urlparam;
urlRequest.url="http://mydomain.com/saveworkout.php";
urlLoader.addEventListener(Event.COMPLETE,loadCompleted);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,loadError);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
urlLoader.load(urlRequest);
}
private function loadError(event:IOErrorEvent):void{
trace("Stream Error="+event.text);
}
private function securityError(event:SecurityErrorEvent):void{
trace("Security Error="+event.text);
}
private function loadCompleted(event:Event):void{
var urlLoader:URLLoader=event.target as URLLoader;
trace(urlLoader.data);
}
This code works fine when I test it locally and send request to localhost, but giving me Error #2032: Stream Error. At remote server codeigniter framework is being used. I also the crossdomain.xml in the httpdocs directory, and also cross check the request url. Request url opens fine directly in the web browsers. Any idea?
Thanks & Regards,
Check headers in server response.
Maybe it's not of right MIME type or even corrupt.
Browser show it's ok, but in reality its broken. Use Firebug, or Tamperdata plugin for Firefox.