在扩展 flash.display.Sprite 并利用低级 DisplayObjects(Sprite'a、Shape's、TextField)的层次结构的 ActionScript 3 可视化中创建多个可滚动区域的最佳方法是什么?
我尝试使用三个 mx.containers.Canvas 对象作为主 Sprite 的子对象添加,并且还尝试将主 Sprite 转换为 Canvas,但使用任何一种方法都无法显示任何内容。我还尝试使用 Canvas.addChild 和 Canvas.rawChildren.addChild 添加我的 DisplayObject。
是否有必要/可能重写整个事物以使用 mx.* 组件,或者是否有技巧在 Canvas 对象内显示更多原始对象?
以下是使用精灵的工作方式的一些示例代码。我们想让 _colSprite、_rowSprite 和 _mapSprite 与链接的滚动条一起滚动。当我将它们转换为 Canvas 对象时,代码会在绘制任何显示对象之前静默挂起(如果我没记错的话,在 addChild 行)。
下面是代码的摘录。这一切都来自扩展 sprite 的单个动作脚本类。
设置我希望滚动的三个区域:
this._log("Creating Sprites");
this._colSprite = new Sprite();
this._colSprite.y=0;
this._colSprite.x=this._rowLabelWidth + this._rowLabelRightPadding + this._horizontalPadding;
this._rowSprite = new Sprite();
this._rowSprite.y=this._columnLabelHeight+this._columnLabelBottomPadding + this._verticalPadding;
this._rowSprite.x=this._horizontalPadding;
this._mapSprite = new Sprite();
this._mapSprite.y=this._columnLabelHeight+this._columnLabelBottomPadding+ this._verticalPadding;
this._mapSprite.x=this._rowLabelWidth + this._rowLabelRightPadding+this._horizontalPadding;
this._log("adding kids");
addChild(this._mapSprite);
addChild(this._rowSprite);
addChild(this._colSprite);
样品绘制功能:
private function _drawColumLabels(colStartIndex: int): void {
for (var col : int = colStartIndex; col < myData.g.length; col++) {
var colName : String = this.myData.g[col].label;
var bottomLeftPoint : Object = this._getCellXYTopLeft(0, col);
bottomLeftPoint.y = this._columnLabelHeight + this._verticalPadding;
var centerX : int = Math.round(this._cellWidth / 2 + (this._fontHeight / 2) - 1);
var colLabel : TextField = new TextField();
colLabel.defaultTextFormat = this._labelTextFormat;
colLabel.width = this._columnLabelHeight+this._columnLabelBottomPadding;
colLabel.text = colName;
colLabel.embedFonts = true;
var colSprite : Sprite = new Sprite();
colSprite.addChild(colLabel);
colSprite.x = bottomLeftPoint.x;
colSprite.y = bottomLeftPoint.y;
colSprite.rotation = -45;
this._colSprite.addChild(colSprite);
}
}