Flash: Print is broken

Monkey Forums/Monkey Bug Reports/Flash: Print is broken

mr_twister(Posted 2013) [#1]
I have a flash game that's running fine with v66.
I switched then to v69 and my game crashed. v70f and v70g crashed as well.

After I checked the source I realized that now Print uses javascript to print to a textbox console. And the game was crashing in the points where I added some debug prints.

If you try to run the page (with the embedded swf) directly from your file system you -apparently- don't have the permissions to make the Javascript call and as consecuence Flash freezes in the attempt. The same happens if you try to open the SWF file alone.

This is especially troublesome if you intend to send the Swf file to a friend or colleage. Not everyone will set a webserver just to open a flash game. And I'm not sure it's good to force the existance of such a JS function in every web page we embed the game. In some scenarios we don't even have source-level control of the page where our game will be embedded into (think Kongregate).

Solution however is quite simple. You only need to wrap the ExternalInterface call (in the native lang.as file) with a try-catch block like this:
function print( str:String ):int{
	try {
		if( ExternalInterface.available ) ExternalInterface.call( "monkey_print",str );
	}catch (e: Error){
	}
	return 0;
}


And that makes it work in every possible case.
Mark, hope you can add this to the next version of Monkey :)


marksibly(Posted 2013) [#2]
Thanks!