开发者

Programmatically Detecting Valid Style Properties In Flex

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜