Googolflex!!
  • Home
  • About
  • Contracting

Recent Posts

  • Sprint’s new “Simply ‘Almost’ Everything®” Plans
  • CSS Changes in Flex 4
  • Dotted Underline LinkButton (Flex)

About The Author : jwd

This is John Dusbabek's tech blog. John is a software engineer and Flex developer in Provo, UT, where he lives with his lovely wife and four sons.

Recent Comments

  • Nikos on Flex: Binding to an Interface
  • Iain Hosking on Apache mod_proxy_balancer: No Protocol handler was valid

Archive for Monkey Patching

Jul
21

Changing Default Minimum Height of ScrollThumb

Posted by: jwd | Comments (0)

The default minimum height of the scroll thumb is about 10 pixels, which my client felt was a little too small (their data sets usually run into the several-hundreds, which is enough to push it to the minimum at most resolutions). So I set about trying to fix the problem.

There was no style or property I could set on the VScrollBar to control this, so I went to the ScrollThumb. There was no global style I could set on the class to control this, and if I extended the ScrollThumb and manually set it, there was no way for me to easily tell my VScrollBar to use this version of the ScrollThumb.

Long story short, I had to change the framework code. I changed line 48, where explicitMinHeight was set, to something more agreeable for my client. I was pretty disappointed about this, because it has some unfortunate side effects (which I could probably correct if I had the time). Specifically, if there’s a scroll bar that can’t fit the newly resized ScrollThumb, it doesn’t show one at all. This seems most common in short TextAreas.

Categories : Actionscript, Architecture, Flex 2, Flex 3, Monkey Patching, Scalability
Comments (0)
Jul
21

Preventing User Dragging Panel Off Screen

Posted by: jwd | Comments (0)

My most recent monkey patch to the Flex framework code took place in the Panel class.  It is possible to drag a Panel completely off the screen, such that the user has no way of dragging it back should they release the mouse button.

Panel has a private handler private function systemManager_mouseMoveHandler (event:MouseEvent) : void that gets called before any mouse event handlers you might listen for should you extend Panel or try any other object oriented approach. There are also two private variables on the Panel class, regX and regY which store the location the mouse was pressed on the Panel’s title bar, and are set in the startDragging() method. (These numbers are useful for determining if the Panel is being dragged off screen as well as for determining where the top-left corner of the Panel is).

I decided to keep it simple and only prevent the user from dragging the Panel off the left or upper edges of the browser. (You can do the same for the bottom and right edges by performing similar calculations… but I didn’t.)

Here’s the code that does the checking (inside systemManager_mouseMoveHandler():

var sx : int = event.stageX;
var sy : int = event.stageY;

var nx : int = event.stageX - regX;
var ny : int = event.stageY - regY;

if (nx < 0 && ny < 0)
  move(0,0);

else if (nx < 0 && ny >= 0)
  move(0, sy-regY);

else if (nx >= 0 && ny < 0)
  move(sx-regX, 0);

else
  move(event.stageX - regX, event.stageY - regY);

Essentially the code detects if the top or left edge of the Panel is in the negative, and if so resets it to zero. There is a stopDragging() method that I originally tried to use in my code, but gave up, because I wanted the user to be able to continue dragging their mouse back onto the browser after they dragged it off.

Adding in the right and bottom will add several more permutations, so I’ve been thinking of more creative ways to handle this, but haven’t got it working the way I want yet. I’ll update this post when I do.

Categories : Actionscript, Architecture, Design, Flex 3
Comments (0)
Jul
12

Private Variables and Monkey Patching

Posted by: jwd | Comments (0)

I’ve been pretty busy the past two months finishing up a project for my client.  I may have mentioned it before, but their creative vision is pretty intense (especially considering this is an in-house app… in my limited experience I’ve never seen so many resources allocated toward getting the look and feel of an in-house app to be just right).

Anyway, I’ve had to monkey patch approximately 10 Flex framework classes (for various reasons) in order to realize their vision.  In each of these cases I’ve first tried to use inheritance or composition to achieve the desired functionality, mostly in terms of interaction.  And in each of these cases I was unable to do so, and had to resort to making changes directly in a framework class which I maintain in an mx.controls.etc, etc structure with the rest of my project.  I don’t think I need to point out the many evils that this exposes the project to, suffice it to say it’s not ideal.

I just wanted to make an observation as to why I was unable to use normal OOP techniques to achieve the desired functionality.  The most common reason I have been unable to extend classes to do what I need is because there are too many private variables being used in protected functions.  So if I need to tweak one line of a protected method, I can override it.  However, assuming I don’t want to call super.methodName(), there’s no way to recreate the lines that interact with the private variables.

This leaves me two alternatives: 1) monkey patch the file to make the variable protected, or 2) monkey patch the file and just make the change directly to the method.  I make that decision depending on whether I’m fixing a bug, or just adding functionality.  Either way, it’s still a pain in the butt; and will probably be a bigger pain down the road.

Categories : Actionscript, Architecture, Design, Flex 3, Frameworks, Scalability
Comments (0)
May
01

Flex Menu Monkey Patch: Allowing a Branch to be Selected

Posted by: jwd | Comments (3)

So the interaction designers decided that the branches of a menu needed to be selectable (picture a warped checkbox tree, only it’s a menu… and there aren’t any checkboxes). The default behavior of a Menu in Flex can be described as follows:

1. If you click on a leaf, the leaf is selected.
2. If you click on a branch, the sub menu opens up.
3. If you hover over a branch, the sub menu opens up.

I needed to change #2 to select the branch.

The first thing that I did was sublcass Menu (we’ll call it NewMenu), and overrode (with copies) two obvious methods on the Menu class:

override protected function mouseUpHandler(event : MouseEvent) : void
override protected function mouseDownHandler(event : MouseEvent) : void

In those two methods you’ll need to remove any expressions containing something similar to the following:

_dataDescriptor.isBranch(item)

This will allow the branches of your sub class to be treated as leaves. The problem is that Menu class contains this line:

private var subMenu:Menu;

which forces all sub menus to be of type Menu– the only NewMenu will be at the very top! We need all sub menus to be NewMenus. So this is where the monkey patching comes in. You have to change subMenu to a protected variable. Then in your NewMenu class, you can override the function:

mx_internal override function openSubMenu(row : IListItemRenderer) : void

And change the line:

menu = new Menu();

to

menu = new NewMenu();

And you’re done! The reason you need subMenu to be protected is because later on in the method you assign menu to subMenu, and you couldn’t do that from a subclass when it was private. Voila. Interaction designers satisfied.

Categories : Actionscript, Flex 2, Flex 3, Monkey Patching
Comments (3)

Search

Feedburner

Subscribe to

Get the latest updates delivered via email

Calendar

September 2010
M T W T F S S
« Jul    
 12345
6789101112
13141516171819
20212223242526
27282930  

Archives

  • July 2010 (1)
  • June 2010 (2)
  • May 2010 (1)
  • February 2010 (11)
  • January 2010 (3)
  • December 2009 (5)
  • November 2009 (1)
  • August 2009 (8)
  • July 2009 (8)
  • May 2009 (4)
  • April 2009 (1)
  • March 2009 (6)
  • January 2009 (1)
  • November 2008 (4)
  • October 2008 (5)
  • September 2008 (1)
  • August 2008 (5)
  • July 2008 (1)
  • June 2008 (2)
  • May 2008 (8)
  • April 2008 (5)
  • March 2008 (2)
  • February 2008 (3)
  • January 2008 (1)
  • December 2007 (6)
  • November 2007 (9)
  • October 2007 (1)
  • September 2007 (2)

Categories

Tag Cloud

adobe apache Architecture book review C++ centos client server architecture Custom Components database Design error message fedora flash catalyst flex Flex 3 Flex 4 fms iis 6 Interaction Design load balancing master-master master-slave mod_proxy_balancer Monkey Patching MySQL no protocol p2p peer to peer Perl PHP Red5 regex replication self registration selinux Shell Scripting shortcut manager skins socket policy file sockets states stored procedures stratus tools workflow

Coworkers

  • Casey Jackman
  • Sean Murphy

Family

  • Emily & CJ
  • Family Blog
  • Gary Dusbabek

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

RSS FlexExamples

  • Styling the text selection format on a Spark TextArea control in Flex 4
  • Setting the scale mode on a Spark Image control in Flex Hero
  • Setting the fill mode on a Spark Image control in Flex Hero
  • Setting a bitmap image fill on a Spark Form container in Flex Hero
  • Setting a bitmap image fill on a Spark FormHeading control in Flex Hero

Spam Blocked

847 spam comments
blocked by
Akismet

Sponsored Links

JUICE Chat

BYU Adobe Users Group


Copyright © 2010 All Rights Reserved
Flexx Theme by iThemes
Powered by WordPress