Archive for the ‘Flex’ Category

Binding to the members of the parent class

Tuesday, January 13th, 2009

This is not an obvious fact and this is not mentioned anywhere in the documentation: to bind to the member of the parent class both (child & parent classes) should be declared as [Bindable].

Here is the example:

public class Parent
{
public var m_sText:String;

public function Parent()
{
}
}

[Bindable]
public class Child extends Parent
{
public function Child()
{
super();
}
}
 

If you don’t specifically tell to compiler that class Parent is bindable, compiler will give you the infamous warning on the attempt to bind to any public member of the Parent class:

Data binding will not be able to detect assignments to "m_sText".

P.S. It is logical if you think about the meaning of the [Bindable] directive and and you know the fact that PropertyChange events is not fired for changes happened inside of the complex members.

Flex popup window disappears if x or y becomes negative number with fraction

Tuesday, December 9th, 2008

There is a strange glitch in the Flex SDK – if you center PopUp window by yourself, then you should check that x & y properties are always casted to integer values.

If x or y coordinate becomes negative number with fraction, the whole popup window disappears.  This is strange as positive numbers with fraction are valid. And what is most frustrative, DesignView sets them with fractional parts when you re-arrange elements. 

 

UPD: bug submitted

Looking closely at setters & getters

Monday, October 27th, 2008

AS3 has a mechanism for defining setters & getters for the member variables (pardon, properties).

private var _property:uint
public function set property(value:uint):void
{
    _property = value;
}
public function get property():uint
{
    return _property;
}

Recently, I’ve bumped into the the strange thing: if you change directly the value:

 _property = 17;

this won’t generate propertyChangeEvent and all you bound variables won’t be notified about the change. So, instead when you need to notify others about the change, you have to do this:

 property = 17;

This will cause the setter to be executed and propertyChangeEvent will be dispatched.

MacOS, Flex Builder, libs directory and nightmares

Thursday, October 16th, 2008

At some point of time I decided to be cool for once in my life and try to use this “libs” folder feature (See the overexcited Ted’s article here). Because I had to add a number of SWCs to the project I decided not to add them manually one by one as I usually do, but instead I created a sub-directory under libs (I should be listening to that ominous voices) and placed a bunch of SWCs there.  Then I just added a new “SWC Folder” location to the library path and I was enjoying the fact that as soon as I place anything in that directory, Flex Builder catches it up (after a refresh though).  But then storm cloud gathered. I.e. our Mac designer updated the code from the SVN.  The symptoms were:

 

a) Flex Builder hangs (freezes) at the startup while loading the project which referes to that libs/cool_dir directory.

b) In the log file we saw the following:
Caused by: org.eclipse.core.internal.resources.ResourceException: The resource tree is locked for modifications.

After 4 hours of the tambourine dancing around Mac we have figured out that the cause of the problem was my libs/cool_directory. As soon as you remove it, everything gets back to normal. And only Flex Builder for MacOs is prone to this problem.

Damn it!  The number of hours I’ve already spent in the last 2 years troubleshooting Mac’s problems is now probably equal to the unforgettable hours I’ve spent installing SCSI board drivers for WinNT3.51/4.0 on SMP servers.  Oh…. sweet unpretentious Windows…

 

NB On the way, I’ve been really pissed off  by MacOS again – if you download zip file in Safari, it automatically unpacks it. And if folder in the archive is org.eclipse.core smart Safari-MacOs-SteveJobs-whatever unpacks it into the org/eclipse/core.  This is so sweet, caring and mindful.
I’ve been told that there is a setting somewhere in Safari to stop doing this, but we’ve got a presumption of innocence, right? Why should arrogant, ill-mannered and unsophisticated bloke like me know, that there is an option somewhere in the MacOs which says “let’s be stupid, OK/Agree?”

Anyway, enough about this bloody MacOs.  Allons! Revenons à nos moutons! Qu’en fut-il?

Easy multiple items selection in DataGrid

Sunday, August 24th, 2008

Using Ctrl or Shift keys in multiple items selection is a common thing. Unfortunately, it is appeared that it is common only among the advanced users. So, I decided to simplify the interface: simulate Ctrl key, so user will use single mouse click to select/unselect items in the DataGrid.


package
{
    import mx.controls.DataGrid;
    import mx.controls.listClasses.IListItemRenderer;

    public class EasySelectionDataGrid extends DataGrid
    {
        //this flag simulates holding a Ctrl key
        private var _holdCtrl:Boolean = false;

        public function EasySelectionDataGrid()
        {
            super();
        }

        public function set holdCtrl(value:Boolean):void
        {
            _holdCtrl = value;
        }

        public function get holdCtrl():Boolean
        {
            return _holdCtrl;
        }

        override protected function selectItem(item:IListItemRenderer,
                              shiftKey:Boolean,
                              ctrlKey:Boolean,
                              transition:Boolean=true):Boolean
        {
            //override values if necessary
            return super.selectItem(item, shiftKey,
                              _holdCtrl ? true: ctrlKey,
                              transition);
        }
    }
}

Diff on mxml files in Flex 3 sucks big time

Thursday, August 21st, 2008

Internal diff tool in FB3 sucks big time. It worked in FB2, but someone decided that this thing is too good for this world and changed it. This ugly proportional font and this terrible performance are just unbearable!

Single diff on 1000 lines files takes around 50 seconds. Multiply it by 10-20 per day and this is a stolen time from you.

It is time to change this. Here is the place to vote for this bug:

http://bugs.adobe.com/jira/browse/FB-12492

Sweet Adobe, please have a mercy on us all and give us back the
simple, no-gimmick diff, which just works.

Cheers!

Data binding will not be able to detect assignments to “SOME_STATIC_VARIABLE”.

Monday, August 18th, 2008

If you want to bind in MXML to some static variable compiler will warn you that data changes to the value will be unnoticed with the following warning:

Data binding will not be able to detect assignments to "SOME_STATIC_VARIABLE".

I don’t like compiler errors and don’t like compiler warnings as well. So, to avoid this warning you can do the following:

Instead of:

    <mx:TextInput enabled="{iUserAccessId == GLOBAL.m_iAllowTextInput}" />;

you can do this:

    <mx:Script>
        <![CDATA[
             [Bindable]
            private var iCanEdit:uint = GLOBAL.g_iAllowTextInput;
        ]]>
    </mx:Script>
    <mx:TextInput enabled="{iUserAccessId == iCanEdit}" />

Voilà!

ComboBox selectedItem problem

Monday, August 18th, 2008

ComboBox is definitely one of the lousiest Flex components.
First, you can’t customise the itemRenderer for the main control (not the drop-down list).
Second, it has very uncertain behaviour with item selection.

Problem 1:
setting ComboBox.selectedItem = null does not do anything. Logically, it should be equivalent to setting selectedIndex=-1. But it does not work.
There is Flex bug registered and it is marked as Fixed in Flex 3 (Released), which is a bullshit. It is still there.

Problem 2:
The whole Flash/Flex framework is event-driven thing. But sometimes developers forget about it. Unfortunately, including the framework designers.
Somehow, someone thought that dataProvider property will be always set first, and selectedItem second. This is wrong. Here is an example how it could be in a real world:

A multi-state Panel has Combobox. The Panel is cached (after creation it is saved to be reused in later calls).

Here is the sequence of events:
1. Already cached Panel is opened up by PopUpManager
2. Panel is initialised with new data
3. selectedItem property is getting initialised first (by data binding)
4. Panel performs the state change
5. Panel in new state initialises ComboBox by setting the dataProvider (by databinding)

Because there are no new dataChange events coming after this point, selectedItem won’t be set.

Touché!

Here is the overridden class which addresses both problems.

package
{
    import mx.controls.ComboBox;

    public class RightComboBox extends ComboBox
    {
        public function RightComboBox ()
        {
            super();
        }

        override public function set selectedItem(value:Object):void
        {
            if (value == null)
            {
                super.selectedIndex = -1;
            }
            else
            {
                super.selectedItem = value;
            }
        }

        override public function set dataProvider(value:Object):void
        {
        var l_savedSelectedItem:Object = super.selectedItem;
            super.dataProvider = value;
            super.selectedItem = l_savedSelectedItem;
        }

    }
}

call validateNow() on parent for correct results

Saturday, August 2nd, 2008

It is never too late to learn. After a lot of time spent on fixing the mighty “Flex Printing Engine”(tm), I’ve learnt an important lesson: you have to call validateNow() on parent component as well to get child component properly measured and rendered.

Flex debugging session is stuck at the loading stage (IE only)

Saturday, August 2nd, 2008

I’ve found that when you start debugger from Flex using IE, in most of the cases the debugging session is stuck at the stage when Flash Player shows Loading/Initialising progress bar.
I can’t recall this happening in the Firefox. I still have got intermittent problem with debugging in both browsers but at the later stages, when I load and initialise dynamically SWFs and loading/screen update is stuck.

To overcome this I used to a trick: right-click to get into the Flash Player menu -> click “Play” to shove the debugging session. Sometimes it worked, sometimes it was crashing in the guts of the SystemManager. So I had to restart the whole thing all over again.

It is appeared that the culprit for this freezing is an Anti-Phishing filter.
As soon as added my sites to the Trusted domain and in the IE settings disabled the anti-phishing filter it immediately stopped doing this nasty thing.