Sunday, January 27, 2008

Random issues with Flex and Flash

1. Using setFocus or focusManager for your Flex login form to have the caret focus when the page loads:
You set your initialize method to set the focus of your TextInput. When you test in your browser it merely sets the border color of your element since your SWF doesn't yet have the focus yet.

Solution:
In your html-template directory, set the body's onload event to contain:
document.getElementById('${application}').focus()

2. Trying to print with Flex using FlexPrintJob:
So, trying to print something from the click of a button but what you're printed is created dynamically and is never actually displayed to the user? Maybe the pictures aren't loading?

Solution:
To print something that is essentially offscreen or in the background, do something like this:
<mx:canvas><somenamespace:print id="myObject" x="-20000" y="-20000" /></mx:canvas>

And the pictures that aren't loading? Well, they can't print until they're actually loaded so create a class to track when all those media objects are loaded.

3. Internet Explorer popup blocker is reloading the page and affecting the display/dimensions of symbols/movieclips inside of your SWF:
Well, in my case what was happening, we were using SWFObject and it was setting the dimensions to a size that was different then the document dimensions of the SWF itself.

Solution:
Update SWFObject to use the correct dimensions of the SWF, or re-export your SWF to use the dimensions that SWFObject is using.

4. Issues with scrolling in your Flex app on OSX:
Would be nice if I could use my scrollwheel for once. Pretty nice and crippling bug.

Solution:
OSX scrollwheel workaround for Flex 2

5. TextFormat doesn't always underline correctly in IE/Firefox/whatever
Underlining, for whatever reason can only be set using TextFormat. I found no elegant solution for this.

Solution:
Draw a line and place it under your text (ugh...).

6. Text you are getting from a webservice appears to be double spaced
When I was setting a textarea to the contents of a response from a webservice. It was peculiarly double spaced.

Solution:
It's those unix line endings. Replace all those \r\n with \n.

7. Dynamic event listener in Flex
I needed a login form to have different focus out events when someone selected a different item in a ComboBox

Solution:
private var loginKeyupProxy:Function;
private var loginKeyup:Function;
private function init():void {
loginKeyupProxy = function(event:FocusEvent):void { loginKeyup(); };
username.addEventListener(FocusEvent.FOCUS_OUT, loginKeyupProxy);
}

// somewhere else in your code:

loginKeyup = function() { /* do stuff */ };

No comments: