1

I need to create a movieclip on the fly by coding, and then put it into datagrid.
Can anyone help me? I'll write the detail below.

On https://stackoverflow.com/a/2035638/1201144, thanks to George Profenza for providing an answer.
His answer can add predefined movieclip from library into the datagrid.
But I need to inherit that mc dynamically, then put tem into datagrid. This is George's answer

import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;

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

Object Star was already designed in the library.
Let's say I need to inherit the 'Star' to 'LittleStar' and 'BigStar'. Then attach them to datagrid? The first row for littleStar and second row for the bigStar.
I have tried like:

var LittleStar:Star = new Star();
dp.addItem({data:{source:'LittleStar',frame:i+1}, title:"clip Star at frame"+(i+1)+""});

But I got error that LittleStar was not defined. What should I do?
Note: George has inherited ClipCell class from iCellRenderer. And use it to his datagrid.

Community
  • 1
  • 1
wily
  • 11
  • 1
  • I would really appreciate for @GeorgeProfenza to help me out.
    Or anyone?
    – wily Feb 22 '12 at 19:45
  • 1- Make a class that contains all DataGrid implementations and functionality. 2- Simply add an instance of that class on your events (like mouse click) inside your main application. 3- Have an eye on Garbage Collection from memory. – Katax Emperore Aug 06 '12 at 02:52
  • You need something like 'var newGrid = new myGridData();' which myGridData() is the name of class that makes all datagrid for you. – Katax Emperore Aug 06 '12 at 02:57
  • `LittleStar` is not a class, it's the name of a variable holding a reference on an object of type `Star`. When it is time to create objects from the information stored in the data provider, then `ClipCell` is trying to create an object from the class with the name stored on `source`. This cannot work for `LittleStar` because there is no such class defined as you expected by `var LittleStar:Star = new Star();`. What you want is generating new classes on runtime, but I guess that cannot be done (so easy) in Flash/ActionScript. But check whether the keywords _ByteArray_ and _AMF_ will help you. – eddipedia Sep 04 '12 at 21:51

0 Answers0