czwartek, 22 lipca 2010

Flash/Flex debugger and FireFox Flash plugin crash

Someone at Mozilla had this 'great' idea to introduce Flash plugin timeout settings. I'm not really sure what it was supposed to do but it does one thing for sure - crashes my Flash plugin whenever I spend more than 45 second on debugging a single breakpoint in Flex.

Although guys at Mozilla might not think twice about what they are going to implement next they've got a pretty good support.

Here's the solution to this problem: http://support.mozilla.com/pl/kb/The+Adobe+Flash+plugin+has+crashed

środa, 14 lipca 2010

Pass reference to "this" to child object generated by Repeater.

Let's assume that we've got a component named Item. This component has a public property named controller.

The idea is that we want to pass reference to this (usually a parent object of Repeater) to Repeater children.

You could use basic logic and try to do something like this:
<mx:Repeater dataProvider="{dP}">
    <layouts:Item controller="{this}" />
</mx:Repeater>
But unfortunately Flex is not a place where you should use logical solutions. In shown example scope of this is fubar. Thus the necessary workaround which is displayed below. Please note that XXX should be the name of the Class which is represented by this pointer.
[Bindable] private var _this:XXX; 
private function init():void
{
_this = this; 
}
<mx:Repeater dataProvider="{dP}">
    <layouts:Item controller="{_this}" />
</mx:Repeater>

wtorek, 29 czerwca 2010

Error #2038: File I/O Error

If you try to upload a file to the server by using FileReference.upload() method and get aforementioned I/O Error check if the file you're trying to send is larger than 0 bytes.

ActionScript can not upload zero-sized files and handles them by throwing I/O Error.

poniedziałek, 14 czerwca 2010

Flex: Important difference between TileList and Repeater

Let's assume we need to do some custom stuff after sending data, from data provider, to either TileList or Repeater items.

First step is to override commitProperties function in class that will represent item renderers in both cases.

All data passed to the item renderer by its parent object (TileList/Renderer) should be available during the execution of this function (and not only then) in the data variable. The difference is that Renderer does not put that data there automatically. God knows why.

To make it work exactly like TileList, or any other list for that matter, simply preceed all instructions in commitProperties by statement shown on following example:

override protected function commitProperties():void
{
   data = getRepeaterItem();
}

czwartek, 10 czerwca 2010

Flex: Focus issue while chaning cursor with CursorManager

Sometimes when CursorManager is used to swap normal cursor to a custom graphic it won't refresh until mouse pointer is moved to some other element of the application and then moved back.

It happens like that because component gains focus (kind of) on MouseEvent.ROLL_OVER event but making users roll out and over to see a new cursor is not an acceptable solution, unless of course you really don't like those guys, then be my guest and make them suffer.

There are two solutions for this problem:
  • call method UIComponent.setFocus()
    This will work if you don't need focus in any other part of the application, like for an example textfield or on a button
  • componentName.dispatchEvent(new MouseEvent(MouseEvent.ROLL_OVER,true));
    Second solution might not look as sharp as the first one but won't take your focus from other elements and will change cursor the same was as you'd move your mouse out and back from the component you're currently hovering over

środa, 9 czerwca 2010

Flex: component changing height when changing styles

Component <mx:Text> has unfortunate tendency to change its dimensions when its height/width was not specified and styles are being changed.

It's most visible when many components, with <mx:Text> inside them are placed in a container - <mx:Repeater> or even <mx:Vbox> which has a scroll. When those components have different styles assigned to over/normal/selected states they are being redrawn whenever user hovers his mouse over them.

Problem is that during style change process dimensions of <mx:Text> are being reset for a few miliseconds thus changing the dimensions of parent components which results in glitchy display or even resetting the position of scrollbars in parent components.

To fix those problems you have to override its styleName setter - you can use wrapping component for that and do something like this:
override public function set styleName(value:Object):void
{
   super.styleName = value;
   if (tContent && tContent.height >= 18) 
   {
      tContent.height = tContent.height;
   }
}
where
<mx:Text id="tContent" minHeight="18" />
Obviously now you'll want to change the styleName of the wrapping component, not <mx:Text> itself.

piątek, 28 maja 2010

Tip: Flex Builder 3 windows' content displayed incorrectly

If some sections of Flex Builder 3 seem to be empty or without some important content there you are probably an owner of Logitech hardware (mouse or keyboard) and have SetPoint software installed on your PC.

Fix: Close Flex Builder, turn off your SetPoint drivers, run Flex again. All content in Flex windows should be displayed correctly.

Note: You don't have to uninstall SetPoint, just exit it when you need to change something in Flex options.

Tip: Flex Builder 3 and Flash Player not found

When compiling new/imported Flex project you get the message that Flash Player is missing go to Project | Properties | Flex Compiler and deselect option Generate HTML. Click Apply and OK. Clean your project afterwards and build it again, go back to the same option and select it this time. Click Apply and OK for the last time.

If Flex Compiler options window is empty for you (no checkboxes, just a frame) please have a look at next post.

środa, 26 maja 2010

Tip: MouseEvents

If some functions get randomly invoked (or not) when rolling over or out some objects with listeners attached to them chances are you used:
MouseEvent.MOUSE_OVER
MouseEvent.MOUSE_OUT
instead of:
MouseEvent.ROLL_OVER
MouseEvent.ROLL_OUT