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

发布于 2024-07-07 07:47:03 字数 2613 浏览 3 评论 0原文

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

我尝试使用三个 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);



        }

    }

What is the best way to create several scrollable regions in an ActionScript 3 visualization that extends flash.display.Sprite and makes use of hierarchy of of low level DisplayObjects (Sprite'a, Shape's, TextField)?

I have tried to use three mx.containers.Canvas objects added as children of the main Sprite and have also tried converting the main Sprite to a Canvas but am unable to get anything to show up using either method. I have also tried adding my DisplayObjects using both Canvas.addChild and Canvas.rawChildren.addChild.

Is it necessary/possible to rewrite the whole thing to use mx.* components or is there a trick to displaying more primitive objects inside of a Canvas object?

Here is some sample code for the way that works using sprites. We would like to make _colSprite, _rowSprite and _mapSprite sroll with linked scrolling bars. When i convert them to Canvas objects the code hangs silently before any display objects are drawn (at the addChild lines if i recall correctly).

Below is an excerpt of the code. This is all from a single actionscript class that extends sprite.

Seting up three regions i wish to scroll:

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

Sample drawing function:

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



        }

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭⌒浅淡时光〆 2024-07-14 07:47:03

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

是否需要执行此操作取决于您要添加子组件的组件生命周期的哪个阶段 - 即当您调用“_drawColumLabels”时。

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

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

After adding the children to each Canvas you may need to call Canvas.invalidateSize() (on each one) to get them to recalculate their sizing.

Needing to do this depends on which stage in the Component Lifecycle you're adding the children - i.e. when you're calling '_drawColumLabels'.

I presume you're wanting a scollbar to appear on _colSprite (and _rowSprite) if there are more labels in it than can be displayed in it's visible area? If this is the case you'll need to use something other than Sprite, like Canvas as Sprite doesn't support scrolling.

You may also want to debug the x/y/width/height values of each of your components to make sure they're what you expect - something I find helpful with doing layout is to draw the layout on paper and start writing sizes and coordinates so that I can see that my calculations are right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文