flexcoders  

Re: [flexcoders] Re: Styling AdvancedDataGridItemRenderer

Jonathan Branam
Thu, 26 Jun 2008 08:27:43 -0700

Hi Amy,

I'm trying to follow along, but you've asked several questions now!

Setting the alpha property should work based on a simple test that I did. As
I look at your code, though, I think you have some confusion between the
alpha *property* and an alpha *style*. The alpha property is from Flash and
indeed you cannot see the source to it. It does appear to apply correctly to
Flex components and their skins. However, if you have a style called "alpha"
that does not affect the alpha property (unless you have coded this
connection).

OK. I think I see the problem. ADGItemRenderer extends UITextField which is
not a rendering component. The flexpearls post notes this, but doesn't
really get into the implications. The inheritance tree is: UITextField <
FlexTextField < TextField < InteractiveObject < DisplayObject. Therefore, a
UITextField doesn't have a graphics property (only descendants of Shape and
Sprite do), nor is it a DisplayObjectContainer. This means you cannot use
the drawing API or addChild(). Looking at the livedocs for TextField, it
doesn't appear to support alpha for background, so this is probably just not
possible. If you set the Flash alpha property, it might fade the background,
but it will also fade the text (if you have it embedded). The alpha property
is almost never used in Flex components. Although I don't know why, I would
steer away from it for that reason.

I would recommend forgetting about ADGItemRenderer. It is a very optimized
class that only displays text.

Subclass something else and do your background manipulation there. You can
make a fairly simple subclass of Label that is still pretty lightweight and
supports rowColor and rowAlpha (if you add the drawing yourself).

This is about as simple as I could get. You should keep all the nice code
you have about initializing styles and all that, of course!

[Style(name="rowColor")]
[Style(name="rowAlpha")]
public class ADGItemRendererBackgroundAlpha extends Label
{
    override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
    {
        super.updateDisplayList(unscaledWidth, unscaledHeight);

        // Don't get styles this way in real code!
        graphics.beginFill(getStyle("rowColor"), getStyle("rowAlpha"));
        graphics.drawRect(0,0,unscaledWidth, unscaledHeight);

        textField.setActualSize(unscaledWidth, unscaledHeight);
    }

}



On Thu, Jun 26, 2008 at 9:40 AM, Amy <[EMAIL PROTECTED]> wrote:

>   --- In flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>, "Amy"
> <[EMAIL PROTECTED]> wrote:
> >
> > I'm trying to extend AdvancedDataGridItemRenderer to allow the
> > styleFunction to set both the backgroundColor and the alpha of the
> > item in. I've used a combination of the custom style example in
> the
> > docs and the example here
> http://flexpearls.blogspot.com/2008/02/row-
> > background-color-in.html. The problem I'm having is that it
> doesn't
> > matter what you set the alpha property to, it doesn't affect the
> > visual appearance of the component.
> >
> > I tried using the graphics object to draw the box, but it seems
> like
> > the base component doesn't support this. If anyone has any ideas,
> > please share.
>
> I suppose I should feel flattered that I've asked a question that is
> so hard that no one here can answer it. Let me try again...maybe
> someone knows the answer to just this piece of it and if I know that
> I can perhaps find a fix: Why is it that setting the alpha property
> on the component does not modify the visual appearance of this class?
>
> I've really tried to figure this out myself, but the inheritance
> trail disappears into the Flash classes, and I haven't been able to
> find the source of those.
>
> Thanks!
>
> Amy
>
>  
>