How to hide debug Adobe Player popup window in Flex? - actionscript-3

When I run a Flex application in the debug flash player I get an exception pop up as soon as something unexpected happened. I would like to catch any exception that can happen anywhere in the Flex code and if it happens don't allow Adobe Debug Flash Player open his pop up window with this exception or error.
I tried:
[PostConstruct]
public function init():void
{
FlexGlobals.topLevelApplication.systemManager.stage.loaderInfo.
uncaughtErrorEvents.
addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,uncaughtErrorHandler);
}
private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
{
event.preventDefault();
event.stopImmediatePropagation();
}
but it don't work, general runtime error dialog will still pop up. I tried to prevent this, call event.preventDefault() inside my global error handler, but it don't work to me too. I'm using Flex 4.

If you add this line to your mm.cfg file: SuppressDebuggerExceptionDialogs=1 the exception dialogs will not appear any longer. The exception will still be in your flash logs.
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fc9.html

Related

Soundeffect not playing in background

I have an application that allows the user to take photos and save to isolated storage for upload to a server.
I am trying to play a shutter sound when the user clicks the software capture button provided. All documentation I can find indicates that soundeffect.play is asynchronous so the sound should keep playing in the background while logic continues, however in my case the sound either only partially plays or does not have time to play unless I put a breakpoint just after play() or add a Thread.Sleep(x) just after the call to play().
private void BtnCaptureClick(object Sender, RoutedEventArgs E)
{
if (_PhotoCamera != null)
{
PlayShutter();
_FileName = Guid.NewGuid().ToString(); //A breakpoint here will allow sound to play
_PhotoCamera.CaptureImage();
}
}
private void PlayShutter()
{
var Info = App.GetResourceStream(new Uri("Assets/camera.wav", UriKind.Relative));
try
{
_Effect = SoundEffect.FromStream((Info.Stream));
FrameworkDispatcher.Update();
using (_Effect)
{
if (_Effect.Play())
{
//Thread.Sleep(1000); //uncommenting this will allow sound to play if duration < 1000
}
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
I have tried using a soundeffectinstance explicitly, however behaviour does not change.
I have tried explicitly calling Play() asynchronously, no change in behaviour.
I have tried calling the following code asynchronously, no change in behaviour.
I have tried calling FrameworkDispatcher.Update frequently, no change in behaviour.
I have tried setting the .wav file in the project to “Resource” but this causes a nullreferenceexception when I call _Effect = SoundEffect.FromStream((Info.Stream)); because Info is null.(even with an absolute path)
This behaviour is present using both the emulator and an actual device via usb connection to pc to debug.
Can anybody help me resolve this frustrating issue please?
Answering my own issue now, it was the using block causing this behaviour, as the instance was being disposed. No idea why I was using that!

Flash Cs6 AS3 - trap ESC key to prevent exiting fullscrenn

I am building a kiosk game for a trade show and want to prevent users from exiting fullscreen with ESC.
I am using Flash CS6 IDE.
I can trap the ESC key with a onKeyDown event, but I can't prevent the ESC key from exiting fullscreen on the Windows executable.
I saw a post with a solution for AIR and Flex and saw your note about stage.nativeWindow as the thing to use in Flash IDE, but I am getting a "Access of possibly undefined property nativeWindow through a reference with static type flash.display:Stage." error.
Here is the code I am using:
function init():void
{
stage.nativeWindow.addEventListener(KeyboardEvent.KEY_DOWN, escapeTrap);
stage.nativeWindow.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
function escapeTrap(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.ESCAPE)
{
event.preventDefault();
}
}
Thanks!

Flash CS5.5 AS3 bug - button works everywhere except via HTML page

I have encountered a strange bug. I have buttons advancing one frame forward and back.
It works in the SWF on its own, it works in both the .app and .exe projector files, but it does not work accessing the SWF via the HTML generated page.
Does anyone have an inkling what's going on?
The code on the two buttons is:
import flash.events.MouseEvent;
stage.displayState = StageDisplayState.FULL_SCREEN;
function next1Click(event:MouseEvent): void {
gotoAndStop(this.currentFrame + 1);
}
function back1Click(event:MouseEvent): void {
gotoAndStop(this.currentFrame - 1);
}
//EVENT LISTENER AND VARIABLE DECLARATION
balancingNext.addEventListener(MouseEvent.CLICK, next1Click);
balancingBack.addEventListener(MouseEvent.CLICK, back1Click);
Thanks in advance for any help!
It's not a bug, but the intended bevahior. For this to work, allowFullScreen must be true, and you can't activate it without a user event, otherwise the program will throw an exception (and crash, since you don't catch it).
The ActionScript that initiates full-screen mode can be called only in
response to a mouse click or keypress. If it is called in other
situations, it will be ignored (in ActionScript 2.0) or throw an
exception (in ActionScript 3.0).
See Adobe's documentation.

AS3 - Pausing on loss of focus

I'm working on a Flash mobile game. If the app loses focus (a call comes in for example) I need the game timer to stop until focus is restored. Here is my current code but I'm getting a "Argument count mismatch error" onDeactivate(). Expected 0, got 1.
Here is the related code, I think:
addEventListener(Event.ACTIVATE, onActivate);
addEventListener(Event.DEACTIVATE,onDeactivate);
public function onActivate():void {
addEventListener(Event.ENTER_FRAME, showTime);
}
public function onDeactivate():void {
removeEventListener(Event.ENTER_FRAME, showTime);
}
I'm getting the error when testing in flash and I close the window. What am I missing? Thanks for any help you can offer.
onActivate and onDeactivate are event listeners. This means they will be called with event argument. Give them one like this: onDeactivate(event:Event):void.

Facebook Login Handler doesn't get fired in Flex4 Facebook API

I have literally spent HOURS trying to solve this mystery... but simply can't seem to get hold of it.
I am using the same code lines (literally!) as the example here (official adobe tutorial) and I get different result.
protected function login():void
{
Facebook.login(loginHandler,{perms:"user_birthday,read_stream,publish_stream"});
}
protected function loginHandler(success:Object,fail:Object):void
{
trace ("login handler called");
if(success){
currentState="state_home";
Facebook.api("/me",getMeHandler);
//userImg.source=Facebook.getImageUrl(success.uid,"small");
Facebook.api("/me/statuses",getStatusHandler);
}
}
Everything works fine, i.e. everything till it is time to fire the loggedin event. I get asked to log in and all permissions are asked correctly. After I log myself in to facebook, the loggedin event doesn't fire. Is there any way of solving this problem??
And I am really desparate... :(
Have you tried debugging the JavaScript of the containing HTML page? I've found that the JavaScript can encounter errors in the communication back to your Flash movie, and it fails silently in the background.
Open the debugger and have a look for any errors - sometimes its down to conflicting embed object Ids in the HTML that throws it.