Alex,

Thanks for the heads-up.  I was on that path as I was looking up what
type 'parent' was.

Actually, I couldn't just assume parent would have backgroundColor set. 
Sometimes it was 2 or 3 parents up the chain where backgroundColor was
set.  So, I ended up with this:

<code>
var bgColor:* = undefined;
var currentParent:* = this.parent;

// This should loop through until it hits the top-most application.
// Hopefully this will prevent infinite looping.
while(currentParent is IStyleClient) {

    bgColor = IStyleClient(currentParent).getStyle("backgroundColor");

    if (StyleManager.isValidStyleValue(bgColor)) {
       __labelCanvas.setStyle("backgroundColor", bgColor);
       break;
    }
    else {
       currentParent = currentParent.parent;
     }
}
</code>

I typed bgColor as * because if I used uint, it always returned 0 (zero)
if getStyle() didn't find anything.  This caused isValidStyleValue() to
return a false true since 0 is a valid uint value.

Thanks for the help,
GT
--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Parent is of type DisplayObjectContainer which does not have getStyle.
>
>
>
> So you have to cast:
>
>
>
>             (parent as IStyleClient).getStyle("backgroundColor");
>
> Or
>
>             IStyleClient(parent).getStyle("backgroundColor");
>
>
>
> ________________________________
>
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
On
> Behalf Of Geoffrey
> Sent: Tuesday, May 15, 2007 10:10 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Getting Parent's Style
>
>
>
> I'm converting some Flex1.5 code to flex 2.0.  One of the classes (a
> commonly used custom component) uses the following to set the
background
> color to that of the parent container:
>
>
>
__labelCanvas.setStyle("backgroundColor")=_parent.getStyle("backgroundCo
> lor");
>
>
> This doesn't work in Flex2.0, nor does
> parent.getStyle("backgroundColor");
>
> How can I get a style attribute of a parent container?
>
> BTW, I can't just let it be transparent because I need to obscure some
> drawn graphic elements of the parent, but I want __labelCanvas to have
> the same background color as the parent.  Also, the parent might not
> always be the same color, else I would set a CSS descriptor for ! it.
>
> Thanks,
> GT
>

Reply via email to