简体   繁体   中英

Set property of NumericStepper declared as UIComponent

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM