flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <aha...@adobe.com>
Subject Re: Is there a way to check if a style exists on an object
Date Wed, 14 Jan 2015 04:53:24 GMT
Did you rule out your suggestion of:


("style" in object.inheritedStyles || "style" in object.nonInheritedStyles)



Or similarly, walking the protochain on this objects and using
hasOwnProperty?

-Alex

On 1/13/15, 6:36 PM, "jude" <flexcapacitor@gmail.com> wrote:

>Unfortunately, there are styles where the default value is undefined:
>http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core
>/UIComponent.html#style:baseline
>http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core
>/UIComponent.html#style:bottom
>http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core
>/UIComponent.html#style:left
>
>I don't think that object.getStyle("style") === undefined will be
>reliable.
>I've run into places in my own code where I check if a styles value is
>undefined. IIRC I got the idea from seeing it in the SDK or somewhere but
>I
>can't find any proof of that at the moment. I've used this in a bunch of
>skins:
>
>if (getStyle("somethingSomething") !== undefined) {
>      // style does not equal undefined so style is set to something
>}
>
>To add more information for discussion the SDK sets the value of a style
>to
>undefined when the clearStyle() method [1] is called. So could it be read
>back as undefined later?
>
>However, and this part is unclear to me, the getStyle() method [2] defines
>undefined as invalid value, which might be the value that proves the style
>does not exist. I'm taking that from the documentation here [2]. But that
>looks like it only means that the style is not declared in the
>CSSStyleDeclaration and not the component itself. But maybe there is a way
>to use this to see if a style exists? Maybe the default class selector
>defines all the styles? I don't think the compiler is adding a list of
>styles somewhere though only what is in defaults.css.
>
>Finally {
>  There is a method called, matchesStyleClient() that does something.
>}
>
>[1]
>http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styl
>es/CSSStyleDeclaration.html#clearStyle()
>[2]
>http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styl
>es/CSSStyleDeclaration.html#getStyle()
>[3]
>http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styl
>es/CSSStyleDeclaration.html#matchesStyleClient()
>
>
>
>
>On Mon, Jan 12, 2015 at 7:23 PM, Gordon Smith <gsmithsf@hotmail.com>
>wrote:
>
>> What about object.getStyle("style") === undefined? I don't think any
>> styles are ever deliberately set to undefined.
>>
>> - Gordon
>>
>> > From: flexcapacitor@gmail.com
>> > Date: Mon, 12 Jan 2015 17:45:45 -0800
>> > Subject: Is there a way to check if a style exists on an object
>> > To: users@flex.apache.org
>> >
>> > Is there a way to check if there is a style on an object?
>> >
>> > We can use the following for properties:
>> >
>> >  ("property" in object || object.hasOwnProperty("property"))
>> >
>> > I'm looking for something like this:
>> >
>> > ("style" in object || object.hasOwnStyle("style"))
>> >
>> > If not does anyone want to write it or recommend a way or API for it
>>to
>> be
>> > written?
>> >
>> > Just this second I thought of this:
>> >
>> > ("style" in object.inheritedStyles || "style" in
>> object.nonInheritedStyles)
>> >
>> > If that works maybe we can add it:
>> >
>> > // check if style exists
>> > public function hasStyle(styleName:String, inherited:Boolean = false)
>>{
>> >
>> > }
>> >
>> > Jude
>>
>>

Mime
View raw message