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 May, 2009

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)
May
01

Responding to FocusIn and focusOut Events

Posted by: jwd | Comments (0)

I recently had some problems responding to focusIn and focusOut events, trying to handle them from my MXML code. After some experimentation and poking around, I discovered the solution was to override the focusInHandler and focusOutHandler methods. These are protected methods inherited mx.core.UIComponent class.

My particular application was to stop a timer that was triggering events when the control had focus, and to restart the timer when focus was lost. Since you’ll be overriding the method, be sure to call super.focusInHandler(event) to ensure the default behavior is still maintained (unless your reason is to override rather than extend the default behavior). Here are the method signatures:

override protected function focusInHandler(event : FocusEvent) : void
override protected function focusOutHandler(event : FocusEvent) : void
Categories : Actionscript, Flex 3
Comments (0)
May
01

Autoscrolling a Flex TextArea

Posted by: jwd | Comments (2)

In the little suite of console widgets I created, I was having more difficulty than necessary getting my console to scroll to the bottom as text was added. On account of (what I suspect were) timing issues, when I tried executing console.verticalScrollPosition = console.maxVerticalScrollPosition; the maxVerticalScrollPosition has not been updated to reflect the text that had been added.

I was not adding the text directly to the text property of the TextArea, rather it was bound to a String in my model. None of the obvious events fired by TextArea seemed to be doing the trick, the maxVerticalScrollPosition was always what it was previously. However, on the next update it would change to reflect what I wanted it to become after the previous update (in other words it was a step behind).

I solved the problem by adding a binding to console’s text property, like this:

BindingUtils.bindSetter(scroll, this.console, "text");

And the scroll method contained the boilerplate console.verticalScrollPosition = console.maxVerticalScrollPosition; statement. That seemed to do the trick. What I was going to try next was a little more extreme:

BindingUtils.bindSetter(scroll, this.console, "maxVerticalScrollPosition");

but fortunately I didn’t have to.

Categories : Actionscript, Flex 2, Flex 3
Comments (2)
May
01

Data Model Injector (poke)

Posted by: jwd | Comments (0)

I needed to build a simple command line interpreter for an application I am building, well, I didn’t need to but I wanted something inconspicuous that the testers (and interaction designers) wouldn’t see and complain about. So I threw something together, it was fun.

Two basic operations I was constantly needing to do was to get a value and/or modify a value. I modified my peek method to return the object in question. And then I also wrote a poke method that allows me to set a value specified by a dot notation.

Here’s the code to the modified peek:

private function peek(prop : String) : * {

  try {
    var a : Array = prop.split('.');
    var x : * = model;

    for (var i : int = 0; i < a.length; i++) {
      x = x[ a[i] ];
    }

    return x;
  }
  catch (error : Error) { return "undefined"; }
}

You can see it’s just a one line change from my previous implementation. And here is poke:

private function poke(prop : String, val : *) : void {

  try {
    var a : Array = prop.split('.');
    var x : * = model;

    for (var i : int = 0; i < a.length-1; i++) {
      x = x[ a[i] ];
    }

    x[ a[a.length-1] ] = val;
  }
  catch (error : Error) { trace(error.message); }
}

In this method I had to iterate one less time to get the parent of the object I wanted to assign to. And then on the final line I manually grabbed it to perform the assignment.

My initial wrong assumption was that I could do this in my loop:

for (var i : int = 0; i < a.length; i++) {
  x = x[ a[i] ];
}
x = val;

Take a look at it, or step through it in a debugger to see why that doesn’t work. It was pretty enlightening.

Categories : Actionscript, Flex 2, Flex 3, Uncategorized
Comments (0)

Search

Feedburner

Subscribe to

Get the latest updates delivered via email

Calendar

May 2009
M T W T F S S
« Apr   Jul »
 123
45678910
11121314151617
18192021222324
25262728293031

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