2008-10-02 90 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值,以確保它們符合您的期望 - 我發現佈局有幫助的一種方法是在紙上繪製佈局並開始寫大小和座標,以便我可以看到我的計算是正確的。