在ActionScript 3可视化中创建多个可滚动区域的最佳方法是什么,这些可视化扩展了flash.display.Sprite并使用了低级DisplayObjects(Sprite'a,Shape's,TextField)的层次结构?

我曾尝试使用三个mx.containers.Canvas对象作为主Sprite的子项添加,并且还尝试将主Sprite转换为Canvas,但无法使用任何一种方法显示任何内容。我还尝试使用Canvas.addChild和Canvas.rawChildren.addChild添加我的DisplayObjects。

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

以下是使用精灵工作方式的一些示例代码。我们想用链接的滚动条使_colSprite,_rowSprite和_mapSprite滚动。当我将它们转换为Canvas对象时,代码会在绘制任何显示对象之前静默挂起(如果我没记错的话,在addChild行处)。

以下是代码的摘录。这完全来自一个扩展精灵的动作脚本。

设置我想滚动的三个区域:

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'时。

我认为你想要一个scollbar出现在_colSprite(和_rowSprite)上,如果其中有更多的标签可以显示在它的可见区域?如果是这种情况,你需要使用Sprite以外的东西,比如Canvas,因为Sprite不支持滚动。

您可能还想调试每个组件的x / y / width / height值以确保它们符合您的预期 - 我发现布局的有用之处是在纸上绘制布局并开始编写大小和坐标,以便我可以看到我的计算是正确的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top