2011-07-16 62 views
0
package com.rubenswieringa.interactivemindmap { 

    import flash.display.DisplayObject; 
    import flash.filters.BlurFilter; 
    import flash.text.TextField; 
    import flash.text.TextFieldAutoSize; 

    import mx.flash.UIMovieClip; 

    public class NodeRendererBase extends UIMovieClip { 

     private var _transparent:Boolean = false; 
     private var _text:String = ""; 

     private static const NUM_DEPTHS:uint = 5; 

     public function NodeRendererBase():void { 
      this.cacheAsBitmap = true; 
      // set settings for all TextFields: 
      var i:int; 
      var textField:TextField; 
      for (i=1; i<=NodeRendererBase.NUM_DEPTHS; i++){ 
       textField = this.getChildByName("textField"+i) as TextField; 
       textField.autoSize = TextFieldAutoSize.CENTER; 
      } 
     } 

     public function setSkinByID (id:String):Boolean { 
      this.gotoAndStop(id); 
      if (this.currentLabel != id){ 
       return false; 
      } 
      this.applyText(); 
      return true; 
     } 

     public function setSkinByDepth (depth:int):Boolean { 
      return this.setSkinByID("depth"+depth); 
     } 

     public function get text():String { 
      return this._text 
     } 
     public function set text (value:String):void { 
      if (this._text == value){ 
       return; 
      } 
      this._text = value; 
      this.applyText(); 
     } 

     /** 
     * 
     */ 
     private function applyText():void { 
      var i:int; 
      // this method is not needed if the item-renderer is not displaying a certain depth: 
      if (this.currentLabel.slice(0, 5) != "depth"){ 
       return; 
      } 
      // textField (TextField): 
      var textField:TextField; 
      for (i=1; i<=NodeRendererBase.NUM_DEPTHS; i++){ 
       textField = this.getChildByName("textField"+i) as TextField; 
       if (i.toString() == this.currentLabel.slice("depth".length)){ 
        textField.text = this._text; 
       }else{ 
        textField.text = ""; 
       } 
      } 
      // background (MovieClip): 
      var background:DisplayObject; 
      //for (i=1; i<=NodeRendererBase.NUM_DEPTHS; i++){ 
      for (i=1; i<=NodeRendererBase.NUM_DEPTHS; i++){ 
       background = this.getChildByName("background_mc"+i); 
       if (i.toString() == this.currentLabel.slice("depth".length)){ 
        textField = this.getChildByName("textField"+i) as TextField; 
        background.height = textField.height + (textField.y - background.y) * 2; 
       }else{ 
        background.visible = false; 
       } 
      } 
     } 

     public function setColor (index:int):void { 
      var background:DisplayObject = this.getChildByName("background_mc"+this.currentLabel.slice("depth".length)); 
      background['gotoAndStop'](index); 
     } 

     public function get transparent():Boolean { 
      return this._transparent; 
     } 
     public function set transparent (value:Boolean):void { 
      if (this._transparent == value){ 
       return; 
      } 
      this._transparent = value; 
      // set visuals: 
      var newFilters:Array = (value) ? [new BlurFilter(3, 3)] : []; 
      this.filters = newFilters; 
     } 

    } 

} 

如果我將private static const NUM_DEPTHS:uint = 5;更改爲5以外的任何值(我試圖增加它的值),則腳本將失敗。任何投入爲什麼?actionscript問題

+0

「失敗」是什麼意思?你看到什麼行爲? – Herms

+0

生成的swf有一個背景,這就是它的全部!低於5的數值產生這樣的結果:0:黑色氣泡,1個白色氣泡,2:第一個氣泡可以休息,有奇怪的渲染3:4:5:同樣地畢業,但如果你超過5,一切都是空白的 – sam

回答

1

我認爲這個問題就出在這裏:

for (i=1; i<=NodeRendererBase.NUM_DEPTHS; i++){ 
    textField = this.getChildByName("textField"+i) as TextField; 
    textField.autoSize = TextFieldAutoSize.CENTER; 
} 

基本上,當你增加NUM_DEPTHS的價值,你告訴這個循環中,將有超過5個文本框。大概情況並非如此,或者你創建了更多並且沒有正確命名它們(textField6,textField7等),因此在第五次迭代之後,對getChildByName()的調用將失敗。

+0

http:// www .rubenswieringa.com/blog/wp-content/uploads/2007/interactivemindmap/source/ – sam

+0

@sam,抱歉,您的鏈接與答案相關的方式如何?你想說什麼? – apscience

+0

我想知道是否查看其餘文件可能有所幫助。我終於搞清楚了問題所在。隨附的flashcomponents.swc文件僅包含五個圖層。這是限制因素。如果我想支持超過5個不同顏色的節點,我將需要添加自定義圖層!感謝您的關注。 – sam