flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jude <flexcapaci...@gmail.com>
Subject Re: Is there a way to check if a style exists on an object
Date Wed, 14 Jan 2015 02:36:36 GMT
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/styles/CSSStyleDeclaration.html#clearStyle()
[2]
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/CSSStyleDeclaration.html#getStyle()
[3]
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message