sendToURL not working in flashplayer 14 - actionscript-3

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.

Related

Flash update 12 broke my video recorder

When flash pushed the 12.0.0.70 version to Chrome it broke my video recorder.
According to the patch notes here, one thing was changed that might have broken my flash-based recorder
[3689061] [Video] Resolves an issue injected in Flash Player
11.9.900.170 that caused the video buffer to no longer be filled if the buffer was emptied while playing an RTMP stream
My recorder breaks when it's time to stop the stream and save the video to the Adobe Media Server.
I tried debugging it with the 12.0.0.70 flash debugger, but it doesn't crash when I'm using the debugger. Only when using the non-debugger Chrome version does it crash.
I can't debug it and get any useful information out of my swf, apart from making a bunch of external calls to console.log to see where it fails.
If someone also ran into a similar issue with flash-based, media-server-connected webcam recorders, and can guess at what might fix my problem, I'd be grateful.
I'm building this swf with Flex 4.6.0
Here's the function that stops the video recorder.
public function doStop():void{
if(status=="paused"){
doResume();
}
rectColor.color=0x000000;
rectColor.alpha=1;
var timer:Timer=new Timer(1 * 10);
timer.addEventListener(TimerEvent.TIMER,function(e:TimerEvent):void{
timer.stop();
timer.reset();
myns.close();
myTimer.stop();
if(!thumbBeginning){
if(status=="recording"){
takeScreenShot();
}
}else{
if(status=="recording"){
recordingTime = formatTime(realTime);
recordingLength = myTimer.currentCount;
if(!redoFlag){
ExternalInterface.call("CTRecorder.stopOk");
myTime.text = formatTime(0);
VD1.attachCamera(myCam);
setState("ready");
status = "stopped, ready"
playbackTimer.reset();
msg(recordingTime);
recording=false;
pauseTime=0;
}else{
pauseTime=0;
myTime.text = formatTime(0);
VD1.attachCamera(myCam);
playbackTimer.reset();
msg(recordingTime);
recording=false;
}
}
if(shutterGroup.visible){
toggleShutter();
}
myTimer.stop();
myTimer.reset();
if(redoFlag){
doRecord();
redoFlag=false;
trace("redoFlag turned off");
}
}
rectColor.alpha=.5;
});
timer.start();
}
This isn't really an answer, but it's too long for a comment.
"I can't debug it" - it only breaks in the release version? Is the release version the pepper plugin (i.e. Chrome's version of Flash), and the debug is the NPAPI plugin (i.e. Adobe's version)?
A likely candidate for where it's breaking is the ExternalInterface.call("CTRecorder.stopOk"); call. Are you testing this locally, or remotely? If locally, then you might be running into this bug: https://code.google.com/p/chromium/issues/detail?id=137734 where the Flash <-> JS communication is broken because of Trusted locations being ignored in PPAPI flash. In any case, try installing the release NPAPI version of Flash and see does it still crash (you can verify which one is running by visiting chrome://plugins/)
To help debugging the release version, you need a logging system - instead of making trace() calls, you call a custom log() function, that, as well as trace()ing, also stores the message somewhere, like in an Array. Then, in your SWF, when you hit a certain key, show a TextField on the screen, and populate it with your log() messages. That way, you'll be able to see trace() statements in release mode.
Also, don't forget to listen to any relative error events and thrown exceptions - ExternalInterface.call() will throw an Error and SecurityError for example. You can also set the marshallExceptions property, which will pass ActionScript exceptions to the browser and JavaScript exceptions to the player: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#marshallExceptions
Finally, add a listener for the UncaughtErrorEvent.UNCAUGHT_ERROR event on your main class, which will catch any uncaught thrown errors (funnily enough), which will at least mean that your app doesn't collapse:
mainClass.loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, this._onUncaughtErrorEvent );
private function _onUncaughtErrorEvent( e:UncaughtErrorEvent ):void
{
var message:String = null;
var stackTrace:String = null;
// get the message
if ( e.error is Error )
{
message = ( e.error as Error ).message;
try { stackTrace = ( e.error as Error ).getStackTrace(); }
catch ( error:Error ) { stackTrace = "No stack trace"; }
}
else if ( e.error is ErrorEvent )
message = ( e.error as ErrorEvent ).text;
else
message = e.error.toString();
// show an alert
trace( "An uncaught exception has occurred: " + e.errorID + ": " + e.type + ": " + message + ", stack:\n" + stackTrace );
e.preventDefault();
}

StackTrace in release flash player

I have problem with getting stacktrace of errors.
When i use error.getStackTrace() in debug player it works fine.
ReferenceError: Error #1056: Не удается создать свойство asdad в starling.display.Stage. at app.views::MachineHeader/onSoundButtonTriggered()
[/var/lib/jenkins/jobs/.../src/app/views/MachineHeader.as:111] at starling.events::EventDispatcher/invokeEvent()
[/var/lib/jenkins/jobs/.../workspace/src/starling/events/EventDispatcher.as:141] at starling.events::EventDispatcher/dispatchEvent()
[/var/lib/jenkins/jobs/.../workspace/src/starling/events/EventDispatcher.as:112] at starling.events::EventDispatcher/dispatchEventWith()
[/var/lib/jenkins/jobs/.../workspace/src/starling/events/EventDispatcher.as:190] at org.feathers.controls::Button/button_touchHandler()
[/var/lib/jenkins/jobs/.../workspace/src/org/feathers/controls/Button.as:3052] at starling.events::EventDispatcher/invokeEvent()
[/var/lib/jenkins/jobs/.../workspace/src/starling/events/EventDispatcher.as:141] at starling.events::TouchEvent/dispatch()
[/var/lib/jenkins/jobs/.../workspace/src/starling/events/TouchEvent.as:174] at starling.events::Touch/dispatchEvent()
[/var/lib/jenkins/jobs/.../workspace/src/starling/events/Touch.as:231]
But on release player stackTrace looks like:
ReferenceError: Error #1056
Code:
this.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onGlobalErrorsHandler);
private function onGlobalErrorsHandler(e:UncaughtErrorEvent):void {
if (_errorList[e.errorID]) {
e.preventDefault();
return;
}
trace(e.error.getStackTrace());
var data:Object = {};
data["login"] = AMFService.instance.login;
data["error_type"] = String(e.error.errorID);
data["stacktrace"] = e.error.getStackTrace();
AMFService.instance.sendError("statistics.error_send", data);
_errorList[e.errorID] = e.error;
e.preventDefault();
}
Debug player: Linux 11.2
Release player: PepperFlash 11.9
What i'm doing wrong? How can i get stacktrace on release player?
Than you.
To enable stacktraces in release player(11.5+), you have to compile your swf with swf-version=18
http://www.adobe.com/devnet/articles/flashplayer-air-feature-list.html
According to Adobe's API Reference for Error.getStackTrace() ...
"For Flash Player 11.4 and earlier and AIR 3.4 and earlier, stack
traces are only available when code is running in the debugger version
of Flash Player or the AIR Debug Launcher (ADL). In non-debugger
versions of those runtimes, calling this method returns null."
Sorry, but there's just no way around it. :(

How to get error message on a HTML5 Application Cache Error event?

During the caching of my offline webapp I receive a totally valid error which is displayed in the browser console like this:
Application Cache Error event: Manifest changed during update, scheduling retry
I can add a Listener to be informed that an error has occured.
window.applicationCache.addEventListener('error', function(e){
//handle error here
}, false);
How can I get the error detail, in this case "Manifest changed during update, scheduling retry"?
You must use window.onerror. The callback can have three parameters:
Error message (string)
Url where error was raised (string)
Line number where error was raised (number)
check this for more information:
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror
Still a valid issue today. In my example, my error log does not return anything. I am using IE11.
<html xmlns="http://www.w3.org/1999/xhtml" manifest="icozum.appcache">
onChecking events fires but then onError with cache status = 0 which is nocached.
window.applicationCache.onchecking = function (e) {
var doc = document.getElementById("cachestatus");
if (doc != null) {
doc.innerHTML += "Checking the cache.\n";
}
}
Then onError
window.applicationCache.onerror = function (e) {
var doc = document.getElementById("cachestatus");
if (doc != null) {
doc.innerHTML += "Cache error occurred." + applicationCache.status.toString() + "\n";
console.log(e);
console.log("test");
}
}
The output on the screen is
Checking the cache.
Cache error occurred.0
There is no detail info about the error in onError event handler. I got the real error by pressing the F12. Here is the screen shot. Is there any way to capture this much detail in onError event handler.
And finally I figured out the problem. The error is not due to missing file. The app cache file does exist, however in windows , visual studio (2013)/IIS does not recognize the extension .appcache. The following section needs to be added to the web.config file.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".appcache" mimeType="text/cache-manifest"/>
</staticContent>
</system.webServer>

Catching "Server not found" exception

In a standalone XUL app, I'd like to catch the server not found exception. I've tried by checking state in onStateChange event of the nsIWebProgressListener, but this doesn't seem to work. My onStateChange event implementation is as shown below. I'm making the assumption that if STATE_START or STATE_STOP is not returning a valid value, then there's something wrong with page loading, and displays the error message to the user.
onStateChange: function(aProgress, aRequest, aFlag, aStatus) {
const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START;
const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP;
if(aFlag & STATE_START) {
document.getElementById("progressBar").hidden = false;
}
if(aFlag & STATE_STOP) {
setTimeout(function() { document.getElementById("progressBar").hidden = true; }, 2000);
}
if(aFlag & (!STATE_START | !STATE_STOP)) {
alert("Your connection seems to be down. Please confirm with your system admin.");
}
return 0;
},
Can someone kindly advice me on what I'm doing wrong? Thanks in advance.
The onStateChange parameter indicating whether there was a connection error is aStatus. For example you could use Components.isSuccessCode:
if ((aFlag & STATE_STOP) && !Components.isSuccessCode(aStatus))
{
alert("Your connection seems to be down. Please confirm with your system admin.");
}
You could also compare aStatus with Components.results.NS_ERROR_UNKNOWN_HOST which corresponds to the "Server not found" error. If the connection is down there could be a number of other errors however, e.g. NS_ERROR_CONNECTION_REFUSED (connection failed), NS_ERROR_UNKNOWN_PROXY_HOST (proxy not found), NS_ERROR_OFFLINE (attempt to connect while in offline state). You can find the complete list of network error codes in nsNetError.h.

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.