Sunday, February 22, 2009

How to set focus on a Flex app (and how to reset it after losing it)

If you are running a Flex app and click on another app, you'll lose focus from the Flex app. In most programs in order to regain focus you just reclick the app and off you go. However Flash does not regain focus automatically unless the user clicks on some element that has an onClick event listener set up for it. This can be a problem especially if you have an app that is supposed to run using keyboard controls only (like a slideshow).

In order to regain focus, make sure that your main component on the stage -- like the canvas that holds your app -- has a click listener set up like this:

click="enableKeyListener(event)"

and then you can have a function that is called like this:

public function enableKeyListener(evt:Event):void{
application.addEventListener(KeyboardEvent.KEY_DOWN,keyUpListener);
world.setFocus();
}

You'll note that the enableKeyListener function is called by the application on creationComplete and explicity calls setFocus() on an element that exists on the stage. And it needs to do this again if you want to regain focus. AFAIK there is no setFocus() method in the stage object so you need to choose an element that is on the stage instead.

Saturday, February 21, 2009

Turn off labels on a Flex chart

If you don't want the labels along the side and bottom of a chart in Flex to show, set the "showLabels" property of the axis renderer to false like this:

<mx:horizontalAxisRenderer>

<mx:AxisRenderer showLabels="false"/>

</mx:horizontalAxisRenderer>

<mx:verticalAxisRenderer>

<mx:AxisRenderer showLabels="false"/>

</mx:verticalAxisRenderer>

Wednesday, February 18, 2009

Creating full screen Flex apps

I'm not sure why Adobe doesn't just add this as an option to FlexBuilder but in order to allow your Flex app to go fullscreen you need to follow these steps:

1. Go here to download html templates for fullscreen support: http://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html
2. Delete all of the files in the html-template folder in your Flex project and place the contents of either the "full-screen-support-with-history" or "full-screen-support" folders from the zip file
3. Add this to the application tag in your Flex project: preinitialize="systemManager.stage.scaleMode = 'showAll'"
4. Call this when you want the app to go fullscreen: systemManager.stage.displayState = StageDisplayState.FULL_SCREEN;

Tuesday, February 17, 2009

Embedding an swf into Flex will remove all of the timeline code

It appears that if you try to load an swf file into Flex using the SWFLoader you can access functions and variables inside the swf from Flex by using this syntax: mySWFLoader.content.myvariable.

However if you use the embed directive in the SWFLoader, all timeline code is lost, meaning that you can't access functions, use gotoAndStop(), etc...

Sunday, February 1, 2009

RSL error 1 of 1 / error #2048 and Vista

A user reported a problem using a Facebook Flex app that uses Runtime Shared Libraries. On Vista/IE they tried to load the app and got this error : RSL error 1 of 1 / Error #2048

In Googling the error, most everyone said that the server needs a cross domain file -- but that is in place and I'm not able to replicate the issue in WinXP(Firefox and IE) or Mac(Firefox).

One forum (http://www.adobeforums.com/webx/.59b6ed13) indicated that a MIME type was needed for the .swz file so I put this in the .htaccess file: AddType application/x-swz .swz

But that didn't fix it either.

Finally I was looking at the date stamp for the framework_3.0.0.477.swf and framework_3.0.0.477.swz files and found that the ones on the server were older than the ones in the bin-debug directory of Flex (the server ones were 4 months while the latest ones were 2 months old). Anyway, I pushed the newer ones to the server and the app loaded perfectly.

Odd that this would only appear with Vista/IE. I was not able to test it with Vista/Firefox...