0

在扩展 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);



        }

    }
4

1 回答 1

1

将孩子添加到每个 Canvas 后,您可能需要调用 Canvas.invalidateSize() (在每个 Canvas 上)以让他们重新计算其大小。

是否需要这样做取决于您在组件生命周期中的哪个阶段添加子项 - 即当您调用“_drawColumLabels”时。

我想如果 _colSprite(和 _rowSprite)中的标签多于可见区域中显示的标签,您希望 scollbar 出现在 _colSprite(和 _rowSprite)上?如果是这种情况,您将需要使用 Sprite 以外的其他东西,例如 Canvas,因为 Sprite 不支持滚动。

您可能还想调试每个组件的 x/y/width/height 值,以确保它们符合您的期望 - 我发现对布局很有帮助的是在纸上绘制布局并开始写尺寸和坐标这样我就可以看到我的计算是正确的。

于 2008-10-02T18:29:54.410 回答