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.