ActionScript 3可视化中的可滚动区域



在ActionScript 3可视化中创建几个可滚动区域的最佳方法是什么?该可视化扩展了flash.display.Sprite并利用了低级别DisplayObject(Sprite'a、Shape's、TextField)的层次结构?

我尝试过使用三个mx.containers.Canvas对象作为主精灵的子对象添加,也尝试过将主精灵转换为Canvas,但使用这两种方法都无法显示任何内容。我还尝试使用Canvas.addChild和Canvas.rawChildren.addChild.添加DisplayObjects

是否有必要/可能重写整个内容以使用mx.*组件,或者是否有在Canvas对象内部显示更原始对象的技巧?

下面是一些使用精灵的示例代码。我们希望使_colSprite、_rowSprite和_mapSprite sroll具有链接的滚动条。当我将它们转换为Canvas对象时,在绘制任何显示对象之前,代码将静默挂起(如果我记得正确的话,在addChild行)。

以下是代码的摘录。这一切都来自于一个扩展sprite的actionscript类。

设置三个区域我想滚动:

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);

        }
    }

将子项添加到每个Canvas后,您可能需要调用Canvas.invalidateSize()(对每个Canvas),让它们重新计算大小。

需要这样做取决于您在组件生命周期的哪个阶段添加子级,即何时调用"_drawColumLabels"。

我想你是想在_colSprite(和_rowSprite)上显示一个scollbar,如果其中的标签比它的可见区域中显示的标签多?如果是这种情况,您将需要使用"精灵"以外的东西,如"画布",因为"精灵"不支持滚动。

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

最新更新