nwebb

Flex, Flash, AIR

Archive for August, 2008

Tweaking an mx_internal property

I wanted to tweak a NumericStepper component so that when I set enabled=false on the component, the input field would not become greyed out (...this makes it too difficult to see any value which has previously been entered in to the field).

Therefore I wanted to subclass NumericStepper and set the editable property to false rather than have the TextInput's enabled property set to false. (I still wanted both of the buttons disabled when appropriate).

Looking at the NumericStepper class, the property inputField is declared within the mx_internal namespace. Also the flag enabledChanged is a private property and so could not be used in my subclass.

I got around the latter by declaring my own property (_enabledChanged) and overriding the getter/setter for enabled - see code below.

I got access to inputField by importing mx.core.mx_internal and working within that namespace as described here (thanks Daniel).

Actionscript:
  1. import mx.core.mx_internal;
  2.         
  3. private var _enabledChanged:Boolean = false;
  4.  
  5. override protected function commitProperties():void
  6. {
  7.     super.commitProperties();
  8.     use namespace mx_internal; 
  9.         if(!_enabledChanged)
  10.         {
  11.          _enabledChanged = false;
  12.          mx_internal::inputField.enabled = true;
  13.             mx_internal::inputField.editable = false;
  14.         }
  15.         else
  16.         {
  17.          mx_internal::inputField.editable = true;
  18.         }
  19. }
  20.  
  21. [Inspectable(category="General", enumeration="true,false", defaultValue="true")]
  22. override public function set enabled(value:Boolean):void
  23. {
  24.         super.enabled = value;
  25.         _enabledChanged = value;
  26.         invalidateProperties();
  27. }
  28.    
  29. override public function get enabled():Boolean
  30. {
  31.         return super.enabled;
  32. }

I'm amazed I've not really run in to the need to do something like this before - I guess because the other app I've been writing is largely a graphical tool. Apologies for lack of example and not going in to masses of detail (heading off to 360|Flex soon so very pushed for time and this is as much a reminder for myself as anything) :]

2 comments

Writing Testable Code

Miško Hevery has written a great post on the Google Testing Blog. It explains the steps needed to write testable code: http://googletesting.blogspot.com/2008/08/by-miko-hevery-so-you-decided-to.html

No comments

Twitter

I'm going to start using Twitter more to let people know about the little things which don't really warrant a blog post of their own but may still be of interest - an upcoming talk, an interesting article or useful application I've seen ...

Please feel free to follow my feed if you're interested:
http://twitter.com/nwebb

I'm currently using TweetDeck (AIR app) for the PC and Twitterrific for the iPhone.

No comments

Next Page »

Bad Behavior has blocked 399 access attempts in the last 7 days.