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).
-
import mx.core.mx_internal;
-
-
private var _enabledChanged:Boolean = false;
-
-
override protected function commitProperties():void
-
{
-
super.commitProperties();
-
use namespace mx_internal;
-
if(!_enabledChanged)
-
{
-
_enabledChanged = false;
-
mx_internal::inputField.enabled = true;
-
mx_internal::inputField.editable = false;
-
}
-
else
-
{
-
mx_internal::inputField.editable = true;
-
}
-
}
-
-
[Inspectable(category="General", enumeration="true,false", defaultValue="true")]
-
override public function set enabled(value:Boolean):void
-
{
-
super.enabled = value;
-
_enabledChanged = value;
-
invalidateProperties();
-
}
-
-
override public function get enabled():Boolean
-
{
-
return super.enabled;
-
}
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 commentsWriting 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
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