R – How to render a component with dynamic visibility in ActionScript

actionscript-3apache-flex

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;
}

Best Answer

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.

Related Topic