Posted by: edsyrett | 19 December 2008

PopupButton.closeOnActivity


As I mentioned in a previous post, I’m working on a dashboard application, and I wanted a control bar at the top of the main application window with a PopupButton on it that drops down a list of the available windows to show in the dashboard.  You might think that this is pretty easy, and you’d almost be right….

I derived a class, PopupCheckboxList,  from PopupButton, which sets a List as its popup.  I created an item renderer, CheckboxListItemRenderer, that contains a checkbox and a label in a HBox.  I added overrides for dataProvider and labelField in PopupCheckboxList so that it could pass on these values to the list.  And I thought that I was finished.  However, there was still a problem.  When I clicked on the button, the list dropped down, but as soon as I clicked anywhere on the list, it closed again.  Whilst I could still click on an individual checkbox to set or clear it, I had to click on the button to reopen the list every time.

I found this code in PopupButton.as…

private function popUpItemClickHandler(event:Event):void { if (_closeOnActivity) close(); }

So I looked for some way to set _closeOnActivity to false. I found this…

/** * @private * Specifies popUp would close on click/enter activity. * In popUps like Menu/List/TileList etc, one need not change * this as they should close on activity. However for multiple * selection, and other popUp, this can be set to false, to * prevent the popUp from closing on activity. * * @default true */ private function get closeOnActivity():Boolean { // We are not exposing this property for now, until the need arises. return _closeOnActivity; } /** * @private */ private function set closeOnActivity(value:Boolean):void { _closeOnActivity = value; }

OK, this was a bit of a surprise…

“for multiple selection..this can be set to false”

No it can’t!…It’s private….

We are not exposing this property for now, until the need arises.

But you just said it can be set to false….make up your mind…

So I had to resort to good old Monkey Patching. The end result is
here. You can click on the down arrow on the button to drop the list, and then click as many times as you like to check or uncheck items. Then click anywhere on the button to close the list (and hopefully do something with your selection)

I had a quick Google for “closeOnActivity” and found
this. So this is a known bug, and until Adobe see fit to fix it, you and I have to keep going with Monkey Patching.

Advertisements

Responses

  1. Very useful post! I was looking for a similar control.

  2. Thanks for this post! It really helps me a lot on my project.
    Just one question, how am I going to set the vertical spaces between the checkboxes?
    Sorry for this question, I am new in using this Flex and I really don’t have any idea how to do it. Thank you in advance. 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: