views:

8

answers:

2

I have a NumericStepper declared as a UIComponent:

<![CDATA[
private var component:UIComponent;
component = new NumericStepper();
]]>

I need to change the .maximum value of the NumericStepper but due to the UIComponent not having a .maximum property the following code fails with the error: 1119: Access of possibly undefined property maximum through a reference with static type mx.core:UIComponent.

component.maximum = 11;

My question is how would I define a property in this scenario?

A: 

You can define it using the dynamic/string syntax:

component["maximum"] = 11;

I use that a lot, the only downsides are:

  • decreased performance (3-5x), but considering it only takes 0.001ms at most to set a property, that doesn't matter.
  • no compile-time checking, so Flex Builder won't throw any errors until runtime
viatropos
+1  A: 

Another solution you can use is "casting":

var component:UIComponent;
component = new NumericStepper;
(component as NumericStepper).maximum = 500;

This has compile-time checking, but i don't know if it has any "downsides"
Hope this helps.

Fabi1816