开发者

Programmatically Detecting Valid Style Properties In Flex

开发者 https://www.devze.com 2023-01-02 23:45 出处:网络
If I want to know if an object has a particular property I can code this: if (SomeObject.hasOwnProperty(\'xyz\')) {

If I want to know if an object has a particular property I can code this:

if (SomeObject.hasOwnProperty('xyz')) {
  // some code
}

But some styles masquerade as properties at design time such as Button.color... How can I know what style properties are valid at runtime? ie: What is the equivalent of hasOwnProperty for getStyle/setStyle?

In other words how can I know i开发者_Python百科f an object HAS A particular style variable... When I write:

MyButton.setStyle('qsfgaeWT','-33');

It won't accomplish anything, but it also doesn't error. How can I know programmatically that 'qsfgaeWT' is NOT a valid style of 'Button'??


setStyle fails silently for invalid style properties. You could try checking the style property after setting it:

MyButton.setStyle('qsfgaeWT','-33');
if (MyButton.getStyle('qsfqaeWT') == "-33") {
    // Not valid
} else {
    // valid
}


displayObject is a Button added to the stage.

var value:* = displayObject.getStyle("borderColor");
trace( StyleManager.isValidStyleValue(value).toString() );  // outputs true
value = displayObject.getStyle("qwerty");
trace( StyleManager.isValidStyleValue(value).toString() );  // outputs false
value = displayObject.getStyle("color");
trace( StyleManager.isValidStyleValue(value).toString() );  // outputs true
0

精彩评论

暂无评论...
验证码 换一张
取 消