*Disclaimer:* This is a cross post with Stack Overflow. I know at least one
person on this list saw it there.
http://stackoverflow.com/questions/3507313/flex-switch-item-renderer

Hi

I was wondering if anyone had any luck with the following senario in flex.

I'd like to be able to have a custom item renderer which delegates to
another renderer inside.

The reason for this would be in a datagrid for instance displaying a
checkbox if the dataprovider for the row had a boolean value. Using the
default item renderer when the value was a non boolean.

Basically I was hoping to use a proxy object (though not necessarily the
proxy class) so that I could a renderer which delegated all of its
responsibilties to a sub renderer.

Hard to explain.

*Edit 1*

I think the following gives a clearer idea of what I had in mind. This is
only knocked up quickly for the purpose of showing the idea.

*SwitchingRenderer.as*

package com.example
{
    import mx.controls.CheckBox;
    import mx.controls.dataGridClasses.DataGridItemRenderer;
    import mx.controls.listClasses.BaseListData;
    import mx.controls.listClasses.IDropInListItemRenderer;
    import mx.core.IDataRenderer;
    import mx.core.UIComponent;

    public class SwitchingRenderer extends UIComponent implements
IDataRenderer, IDropInListItemRenderer
    {
        private var checkboxRenderer:CheckBox;
        private var defaultRenderer:DataGridItemRenderer;
        private var currentRenderer:IDataRenderer;
        public function SwitchingRenderer()
        {
            this.checkboxRenderer = new CheckBox();
            this.defaultRenderer = new DataGridItemRenderer();
            this.currentRenderer = defaultRenderer();
            super();
        }

        public function get data():Object
        {
            //If the data for this cell is a boolean
            //  currentRender = checkBoxRenderer
            // otherwise
            //  currentRenderer = defaultRenderer
        }

        public function set data(value:Object):void
        {
            currentRenderer.data = value;
        }

        public function get listData():BaseListData
        {
            return currentRenderer.listData;
        }

        public function set listData(value:BaseListData):void
        {
            currentRenderer.listData = value;
        }



    }
}

Reply via email to