views:

585

answers:

1

I created a column in a datagrid which displays a movieclip (every row the same movieclip appears. How can I control which frame is displayed in each row?

using this.parent from inside the movieclip doesn't work. What's the path to the specific row in which a movieclip resides?

Thanks

A: 

I've done a test using this devnet article: Notice that in data I pass another object that has source, refence used to display a clip and frame, used to control the frame of the clip.

//imports
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
//data
var dp:DataProvider = new DataProvider();
//populate the provider, specifying the source (linkageID and frame of the clip to display)
for(var i:int = 0 ; i < 7; i++)
    dp.addItem({data:{source:'Star',frame:i+1}, title:"clip Star at frame"+(i+1)+""});
var dataCol:DataGridColumn = new DataGridColumn("data");
dataCol.cellRenderer = ClipCell;

var titleCol:DataGridColumn = new DataGridColumn("title");

var myDataGrid:DataGrid = new DataGrid();
myDataGrid.addColumn(dataCol);
myDataGrid.addColumn(titleCol);
myDataGrid.dataProvider = dp;
myDataGrid.rowHeight = 64;
myDataGrid.width = 500;
myDataGrid.rowCount = dp.length - 1;
addChild(myDataGrid);

And here is the ClipCell used a cell renderer in the data column:

package {
    // Import the required component classes.
    import fl.controls.listClasses.ICellRenderer;
    import fl.controls.listClasses.ListData;
    import fl.controls.Label;
    import fl.controls.TextInput;
    import fl.core.InvalidationType;
    import fl.core.UIComponent;
    import fl.data.DataProvider;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.utils.*;

    public class ClipCell extends UIComponent implements ICellRenderer {
        protected var _data:Object;
        protected var _listData:ListData;
        protected var _selected:Boolean;
        private var _clip:MovieClip;
        /**
         * Constructor.
         */
        public function ClipCell():void {
            super();
        }
        /**
         * Gets or sets the cell's internal _data property.
         */
        public function get data():Object {
            return _data;
        }
        /** 
         * @private (setter)
         */
        public function set data(value:Object):void {
            _data = value;
            if(value.data.source) {
                var Clip:Class = getDefinitionByName(value.data.source) as Class;
                _clip = new Clip();
                if(_clip.numFrames > 1) _clip.stop();
                addChildAt(_clip,0);
            }
            if(value.data.frame && _clip) _clip.gotoAndStop(value.data.frame);
        }
        public function get caca():String{return 'caca';}
        /**
         * Gets or sets the cell's internal _listData property.
         */
        public function get listData():ListData {
            return _listData;
        }
        /**
         * @private (setter)
         */
        public function set listData(value:ListData):void {
            _listData = value;
            invalidate(InvalidationType.DATA);
            invalidate(InvalidationType.STATE);
        }

        /**
         * Gets or sets the cell's internal _selected property.
         */
        public function get selected():Boolean {
            return _selected;
        }
        /**
         * @private (setter)
         */
        public function set selected(value:Boolean):void {
            _selected = value;
            invalidate(InvalidationType.STATE);
        }

        /**
         * Sets the internal mouse state.
         */
        public function setMouseState(state:String):void {
        }

    }
}

I have a clip in the library called Star exported for actionscript. Inside it I placed a bit of code to see if I can get to the ClipCell:

var cell:ClipCell = this.parent as ClipCell;
trace(cell.data.title);
for(var i in cell.data.data)
    trace(i+':'+cell.data.data[i]);

and I get this output:

clip Star at frame1
frame:1
source:Star
clip:[object Star]

HTH

George Profenza