2008-10-02 94 views
0

什么是扩展flash.display.Sprite和利用水平低的DisplayObject层次的ActionScript 3的可视化,以创建多个滚动区域的最佳方式(Sprite'a,形状的,文本字段) ?滚动区域

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

是否有必要/可能重写使用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); 



     } 

    } 
+0

画布应自动显示滚动条,除非verticalScrollPolicy为“off”。你有一些你可以发布的代码来给出更多关于发生的事情的想法吗? – 2008-10-02 18:25:23

回答

1

增加孩子的每个画布后,您可能需要调用Canvas.invalidateSize()(上每一个)让他们重新计算他​​们的大小。

需要做这取决于哪个阶段组件的生命周期要添加的孩子 - 也就是当你调用“_drawColumLabels”。

我相信你想要一个scollbar如果在它更多的标签,无法在它的可视面积显示出现在_colSprite(和_rowSprite)?如果是这种情况,则需要使用Sprite之外的其他内容,例如Canvas,因为Sprite不支持滚动。

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