2011-10-31 36 views
0

我找到了關於如何製作動態未填充和實心圓的教程。這將從滑塊獲取輸入以確定繪製圓的多少。我想用它作爲預加載器。與作者不同,我想在文檔類中使用它。我得到 1061: Call to a possibly undefined method createEmptyMovieClip through a reference with static type document.1120: Access of undefined property circ1.第二個是由第一個造成的。我怎樣才能在我的文檔類中工作?提前致謝!
在文檔類中動態繪製圓形預加載器錯誤1061

//original code 
// x: circles center x, y: circles center y 
// a1: first angle, a2: angle to draw to, r: radius 
// dir: direction; 1 for clockwise -1 for counter clockwise 
MovieClip.prototype.CircleSegmentTo = function(x, y, a1, a2, r, dir) { 
    var diff = Math.abs(a2-a1); 
    var divs = Math.floor(diff/(Math.PI/4))+1; 
    var span = dir * diff/(2*divs); 
    var rc = r/Math.cos(span); 
    this.moveTo(x+Math.cos(a1)*r, y+Math.sin(a1)*r); 
    for (var i=0; i<divs; ++i) { 
      a2 = a1+span; a1 = a2+span; 
      this.curveTo(
       x+Math.cos(a2)*rc, 
       y+Math.sin(a2)*rc, 
       x+Math.cos(a1)*r, 
       y+Math.sin(a1)*r 
     ); 
    }; 
    return this; 
}; 

// empty 
this.createEmptyMovieClip("circ1",1); 
circ1._x = 100; 
circ1._y = 150; 
circ1.radius = 35; 

circ1.onEnterFrame = function(){ 
    this.clear(); 
    var endAngle = 2*Math.PI*percentLoaded; 
    var startAngle = 0; 
    if (endAngle != startAngle){ 
     this.lineStyle(2,0,100); 
     this.CircleSegmentTo(0, 0, startAngle, endAngle, this.radius, -1); 
    } 
} 

//filled 
this.createEmptyMovieClip("circ2",2); 
circ2._x = 220; 
circ2._y = 150; 
circ2.radius = 35; 
/* code in tutorial i left out since its for a second filled in circle 
circ2.onEnterFrame = function(){ 
    this.clear(); 
    var endAngle = 2*Math.PI*slider.value/100; 
    var startAngle = 0; 
    if (endAngle != startAngle){ 
     this.lineStyle(2,0,100); 
     this.beginFill(0xFF9999,100); 
     this.lineTo(this.radius,0); 
     this.CircleSegmentTo(0, 0, startAngle, endAngle, this.radius, -1); 
     this.lineTo(0,0); 
     this.endFill(); 
    } 
} 
*/ 

回答

0

你明白我的代碼使用ActionScript 2製成,並且你正在構建它的ActionScript 3,所以你必須要麼重新編碼爲ActionScript 3或編譯的AS2。

+0

我最近開始動作,所以我不知道我將不得不改變,因爲我從來沒有使用2.0。你能否告訴我我需要重寫哪些部分? – Yamiko

+0

幾乎所有的。大部分是語法(本機屬性名稱前沒有下劃線,AS3中沒有事件回調,AS3中的圖形子屬性中存在圖形調用等),它將會基本瞭解AS2和AS3,以便誠實地將 – gthmb

+0

轉換爲I不想爲此學習as2。對於預加載程序,我會做一些不同的事情,並且當我更熟悉操作腳本時,可以在as3中做這件事。 thx爲輸入。 – Yamiko