And*_*ver 0 apache-flex actionscript-3 flash-builder
在FlashBuilder中我想从CSV文件动态生成大约1200个矩形(这些都是不同的颜色),它们将对Click执行操作.
这样做的最佳方法是什么?我已经读过Air和Android上的绘图API不是一个好主意,我正在考虑使用Spark Rectangle类,但是如果我生成它们,我似乎无法弄清楚如何应用颜色动态使用AS?
读完CSV后,循环遍历元素并调用函数:
private function addRect(color:uint, xPos:Number, yPos:Number, width:Number, height:Number):void {
var rect:Rect = new Rect();
rect.x = xPos;
rect.y = yPos;
rect.width = width;
rect.height = height;
var fillColor:SolidColor = new SolidColor(color);
rect.fill = fillColor;
var obj:Group = new Group();
obj.addElement(rect);
obj.addEventListener(MouseEvent.CLICK, this.onClick);
this.addElement(obj);
}
private function onClick(e:Event):void {
trace("clicked");
}
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.