问题描述
我在显示影片剪辑的数据网格中创建了一列(每一行都出现相同的影片剪辑.如何控制每行显示哪个帧?
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?
从影片剪辑内部使用 this.parent 不起作用.影片剪辑所在的特定行的路径是什么?
using this.parent from inside the movieclip doesn't work.What's the path to the specific row in which a movieclip resides?
谢谢
推荐答案
我已经使用 这篇开发网络文章:请注意,在 data 中,我传递了另一个具有 source 的对象,refence 用于显示剪辑和frame,用于控制剪辑的frame.
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 clipand 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);
这里是 ClipCell 在数据列中使用了单元格渲染器:
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 {
}
}
}
我在库中有一个名为 Star 的剪辑,导出用于 actionscript.在里面我放了一些代码来看看我是否可以到达 ClipCell:
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]);
我得到这个输出:
clip Star at frame1
frame:1
source:Star
clip:[object Star]
HTH
这篇关于在 AS3 的数据网格中添加影片剪辑(并控制它们)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!