views:

274

answers:

2

I have a custom ActionScript component that I'm using in a Flex application (Flex 3.3, ActionScript 3). This component contains an Image control whose visibility is set dynamically based on a property of the data element provided to the component.

The problem is that even when I set the image to be visible, it will not render onscreen. Is there something specific I need to do in order for the image to render? Snippets of relevant code below:

override public function set data( value:Object ):void
{
    _data = value;

    if( _data ) {

        if( _myImg ) {
            _myImg.source = someImageClass;
            _myImg.visible = _data.visibilityProperty;
            _myImg.includeInLayout = _data.visibilityProperty;
            _myImg.invalidateProperties();
            _myImg.invalidateDisplayList();
        }
    }

    invalidateProperties();
    invalidateDisplayList();
}

override protected function createChildren():void
{
    super.createChildren();

    if( !_myImg ) {
        _myImg = new Image();
        _myImg.height = 16;
        _myImg.width = 16;
        addChild( _myImg );
    }
}

override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
{
    super.updateDisplayList( unscaledWidth, unscaledHeight );

    _myImg.x = calculatedXCoordinate;
    _myImg.y = calculatedYCoordinate;
}
+1  A: 

Did you add the component to the display list? It looks like you've added the image to the displaylist of the component, but potentially haven't done anything with the component itself.

Alex Jillard
Yes, the component is actually being used as a drop-in item renderer so it is being used elsewhere in my application. I should also mention that there are other always-visible components in my renderer as well, and they display just fine.
Dan
A: 

It turns out the the above code I posted will, in fact, work properly. I discovered that due to a copy-and-paste bug that I should have caught, I wasn't adding the Image to the display list, hence why it was never appearing.

Dan