Archive for the ‘tips’ 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()

public class Child extends Parent
public function Child()

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.

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.

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.

    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()

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

        public function get holdCtrl():Boolean
            return _holdCtrl;

        override protected function selectItem(item:IListItemRenderer,
            //override values if necessary
            return super.selectItem(item, shiftKey,
                              _holdCtrl ? true: ctrlKey,

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:

            private var iCanEdit:uint = GLOBAL.g_iAllowTextInput;
    <mx:TextInput enabled="{iUserAccessId == iCanEdit}" />


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.

Midnight Commander under Cygwin/Vista

Saturday, August 2nd, 2008

For many years I’ve been using Far Manager which is really great commander for Windows.
It has many useful plugins like SCP/SFTP, Network Browser, reasonably good editor with Colorer, PocketPC connection etc.

On the downside FAR editor has a couple of problems which bothered me a lot:
– Internal editor which is quite powerful, sometimes starts using Windows line endings (CRLF) and because I am working in a mixed environment I had to run the dos2unix utility on the routine basis to convert all the files into the UNIX format.

– FAR has a mysterious feature of changing file permissions or file sharing by adding user “None” with special permissions which were preventing files from to be executed. I.e. you’ve download ZIP file using FAR’s FTP browser, unpack it, try to run EXE file, Windows says:

"You don't have permissions to run the file"

. So you have to Explorer->Security settings and kill this None user.

After my recent upgrade from XP to Vista these problems became even worse.
So, I tried to start using the Midnight Commander, which I’ve been using for ages in Unix environment.
But under Cygwin/Vista it behaves quite differently.

Problems I’ve met so far are:

– no mouse support under Vista.
I’ve even tried to use Cygwin’s SSH port with PuTTY and then run MC – no way to have mouse working in Cygwin window.

– I am unable to browse/open any .zip files.
MC says:

 ./ ./ cannot execute binary file

What the heck? Somehow it opens the TAR files, but only by F4(Edit) command. If you try to open TAR file it writes similar bullshit about running a binary file.

-And the last thing which drives me mad – I am unable to save some of the MC’s config files, such as .mc/bindings. Every time it accesses it, it sets up the sharing, adding this infamous user None with special permissions and this file becomes read-only for MC.

PS While writing this post, I have found that you can get a Midnight Commander’s subshell working under Cygwin – you have to explicitly enable the subshell support via parameter (even if it is a default):

#&gt; mc.exe -U

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.

Date & daylight savings

Wednesday, June 11th, 2008

Date class has a bug related to the daylight savings.

If you want to change the date using number of seconds it will cause a problem going over the dates when daylight savings change.


private var mydate:Date = new Date(2008, 3, 4, 0, 0, 0, 0);

mydate = new Date (mydate.getTime() + 1000 * 60 * 60 * 24)

mydate = new Date(mydate);

If it goes over the date when daylight savings is changed, instead of adding 24 hours it will add 23 or 25 hours (depending on the time of the year – summer or winter)

So, to do perform Date manipulation correctly you have to use date field, i.e.: +=1;

This method correctly handles the daylight savings and it will keep initial 00:00:00 time.


unselect in ComboBox

Monday, June 9th, 2008

If you need to unselect value in the ComboBox control, setting the

selectedIndex = -1

is not enough, you have to set

prompt = "something"

, otherwise it selects the first element. Despite

selectedIndex = -1

. Weird…