Saturday, November 6, 2010

DropDownList Memory Leak - Flex 4.1

There's a memory leak in the DropDownList in Flex 4.1 (build 4.1.0.16076). If you set the dataProvider you'll find you can't subsequently clear it from memory and it won't get garbage collected (and nor will the container etc. that houses it).

Adding the functions below provided us with a workaround (in MXML set "preinitialize" to the onPreInit function):

import flash.events.Event;

private function onPreInit():void
{
      addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}

protected function onRemovedFromStage(event:Event):void
{
      removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
      this.dataProvider = null;
}

Saturday, September 25, 2010

MXDataGridItemRenderer Focus

Author's note - since writing this post I subsequently discovered the "editor" property which does exactly what my "focusChild" property does below. I've left the post intact anyway to help highlight the point and maybe also in the faint hope that somebody from the documentation team at Adobe sees this and does something wild like mentioning this property in their examples...

Once you have switched your existing Flex 3 projects over to trying to use the spark components in Flex 4 you will come across a problem with the new setup for DataGrid ItemRenderers. You will realise that things are now structured differently and you will need to use the MXDataGridItemRenderer class to get your item renderers working again.

You smile a wry smile and bite the bullet, but then something else happens. You realise that things have got all “out of focus”... And by that I mean that tab and mouse focusing doesn't work like they did in Flex 3, and the behaviour is not what you (or your users) would be expecting.

The good thing is the solution is ultimately pretty simple. The code below shows a sub-class of MXDataGridItenRenderer which you can use to get the old focus behaviour back to the way it was. What happens is MXDataGridItemRenderer itself receives the focus, but can't really do anything with it, so you yourself get the job of passing it on to your TexInput, DropDownList, whatever. The way we did it was to add a property called focusChild to our sub-class, as the itemRenderer could conceivably contain any number of custom controls, and this helps to stipulate which one gets the focus when the user mouse-clicks or tabs into the renderer for the given column on the DataGrid.

Our team on the job generally subclass this class, and use the creationComplete event to set the focusChild property to the custom control. The accessors on Data and ListData are there for convenience so that these can be accessed by a subclass (in Flex 3 this complied with the interfaces for IDataRenderer and IListItemRenderer). We also generally override the set data method for setting custom properties on a custom control.



<s:MXDataGridItemRenderer
fx="http://ns.adobe.com/mxml/2009"
mx="library://ns.adobe.com/flex/mx"
s="library://ns.adobe.com/flex/spark"
focusin="gotFocus(event)"
focusenabled="true"
implements="mx.managers.IFocusManagerComponent">
<fx:script>
<!--[CDATA[

import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import flash.events.Event;
import mx.managers.IFocusManagerComponent;

protected var _listData:DataGridListData;
protected var focusChild:IFocusManagerComponent;

private function gotFocus(event:Event):void
{
if (focusChild)
{
focusChild.setFocus();
}
}
override public function set data(value:Object):void
{
super.data = value;
}
public override function get data():Object
{
return super.data;
}
override public function get listData():BaseListData
{
return _listData;
}
override public function set listData(value:BaseListData):void
{
_listData = DataGridListData(value);
}
]]-->

</fx:script>
</s:MXDataGridItemRenderer>


Tuesday, March 9, 2010

Air 2 Native Process Command Window Pop-up

Further to an earlier post, I just wanted to note that Adobe have now said they will stop the command window appearing by default on native processes run on Windows when they do the full release of Air 2 (see my post from January 2010 on Air 2 Beta Native Process).

Chris Thilgen from Adobe apparently pushed for this (see his comments on the adobe forum), so if you ever read this Chris, thanks for that.

Saturday, March 6, 2010

Don't try this at home

All people in this video will remain anonymous - its not me by the way - its the future president of FIFA.

Thursday, January 28, 2010

Subversion subfolder access fun

After such a fantastic morning trying to set up subfolder access on various subversion repositories - its nice to share this little gem with anybody that might be interested.

I wanted a user to have read access to a whole project folder, but to restrict write access to just one folder inside the project. According to the docs I read this should work:

[Project1:/]
newuser = r

[Project1:/trunk/graphics]
newuser = rw

But it didn't. After a whole wasted morning, I found - much to my chagrin - that I had to grant rw rights at the root to the new user, and then deny rights where they weren't applicable, to be able to grant write rights (apache with subversion 1.6.6) to a subfolder (read rights worked ok funnily enough).

[/]
newuser = rw

[Project1:/]
newuser = r

[Project1:/trunk/graphics]
newuser = rw

[Project2:/]
newuser =

I suppose there is some kind of logic there, somewhere...

If you're reading this because you're having the same problem -I really do hope I've helped you.

Monday, January 25, 2010

AIR 2 Beta native process and the PHP CLI

With the release of the Adobe Air 2 beta comes a rake of cool new features. The most promising amongst them for future development is the ability to call and communicate with native processes on the machine on which Air is running. This obviously opens up all sorts of possibilities for extending the capacity of AIR without the need for the required API to be a part of AIR itself.

The application I'm building has so far has been slowly growing as a bunch of Flex applications, working with MYSQL via AMFPHP. But as more things are moved into AIR I wanted to get rid of the need for the webserver, in the case of the application working standalone on a local machine with a local installation of a MYSQL database.

Using the new native process API in AIR, and the CLI version of PHP, I've managed to come up with a way of communicating with AMFPHP directly through STDIN and STDOUT without the need for a webserver. The code is in its infancy, but I thought this would be a good time to share the idea and get some comments and input from those of you out there who are working in the same environment.

Rather than trying to post the code here on the blog - I've opened a Google Code project so that anybody who's interested can download the code and develop the idea if they want to. The project is at http://code.google.com/p/aircmdamfphp/ - you can download from subversion or there's a zip that you can download for convenience.

My main concern so far is security. For this to work on in a live application scenario on a user's machine the first consideration would be to have the PHP code compiled and have some way of securing the PHP installation against possible attacks. Any comments and/or suggestions on this or any other areas of concern regarding security on this particular idea would be appreciated. I suppose the other concern might be somebody hooking something in between the parent and child process...

There is a truly annoying caveat with AIR on Windows at the moment. If you install and run an AIR application using the 2 beta you get a command line pop-up window appearing each time you run php.exe (or it seems any other command line executable). I was hoping Adobe would come up with a fix for this before a production version is released, but looking at the Adobe Forums, Chris Thilgen is telling us that it won't be... (apparently its a "feature request" to not show the command window!) http://forums.adobe.com/thread/558533?tstart=0.

Maybe next time eh?