DataGrid w Flash CS3 i AS3
: ndz mar 23, 2008 10:55 pm
witam, mam problem, czy mogłby ktoś na to zaradzić. Poniższy kod to wycinek z helpa flasha, Wstawia przycisk do komponentu listy, chciałbym w ten sposób umieścić przycisk w komponencie Datagrid. Z góry dziękuję za pomoc, pozdrawiam
1. Add the List and Button components to the library.
2. Save this code as ICellRendererExample.as in the same directory as your FLA file.
3.Set the Document class in the FLA file to ICellRendererExample.
Save the following code as MyRenderer.as in the same directory as your FLA file:
1. Add the List and Button components to the library.
2. Save this code as ICellRendererExample.as in the same directory as your FLA file.
3.Set the Document class in the FLA file to ICellRendererExample.
Kod: Zaznacz cały
package
{
import fl.controls.List;
import fl.data.DataProvider;
import fl.events.ListEvent;
import flash.display.Sprite;
import flash.events.Event;
public class ICellRendererExample extends Sprite
{
public function ICellRendererExample() {
var dp:DataProvider = new DataProvider();
var totalEntries:Number = 42;
var i:Number;
for(i=0; i<totalEntries; i++) {
dp.addItem( { label:Math.random(), data:null } );
}
var myList = new List();
myList.setSize(300,300);
myList.move(10,10);
myList.setStyle('cellRenderer', MyRenderer);
myList.dataProvider = dp;
addChild(myList);
}
}
}
Kod: Zaznacz cały
package
{
import fl.controls.LabelButton;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
public class MyRenderer extends LabelButton implements ICellRenderer {
private var _listData:ListData;
private var _data:Object;
public function MyRenderer() {
}
public function set listData(newListData:ListData):void {
_listData = newListData;
label = "Random: " + _listData.label;
drawRandomColor();
}
private function drawRandomColor():void {
graphics.beginFill(Math.random()*0xFFFFFF);
graphics.drawRect(0,0,20,20);
graphics.endFill();
}
public function get listData():ListData {
return _listData;
}
public function set data(newData:Object):void {
_data = newData;
}
public function get data():Object {
return _data;
}
}
}