2013-03-07 30 views
0

我必須做的事情是,我需要添加一個50%的阿爾法在9圈豁免第五個,繼承人我到目前爲止嘗試...我缺少什麼東西?順便說一句,如果我用「休息」來代替「繼續」,它就可以完美地工作。(Actionscript 3 noob)你如何正確使用「繼續」?

function rendreAlpha(pEvt:MouseEvent) 
{ 
    for (var i:int=1; i<=9; i+=1) 
    { 
     trace(i); 
     this["balle" + i + "_mc"].alpha = 0.5; 
     if (i == 5) 
     { 
      continue; 
     } 
    } 
} 
btn2.addEventListener(MouseEvent.CLICK,rendreAlpha); 

回答

2

if運行後設置alpha。因此,continue;不會跳過任何其他代碼。

+0

謝謝回答! – user1953511 2013-03-07 03:29:48

1

continue將在您的for循環中結束當前迭代,並跳到下一個循環,跳過在該迭代的continue語句之後發生的任何操作。

break將結束整個循環並跳過該迭代之後的任何代碼。

這裏有一個小的演示,應該幫助你瞭解雙方多一點明確:

for(var i:int = 0; i < 10; i++) 
{ 
    if(i < 5) 
    { 
     // Skip the rest of the code in this block and move to the 
     // next iteration. 
     continue; 
    } 

    trace(i); 

    if(i === 8) 
    { 
     // End the entire loop. 
     break; 
    } 
} 

你會發現你的輸出僅包括5,6,7 & 8。這是因爲我們continue並跳過trace語句塊中如果i小於5,並結束循環一旦它擊中8

0

在Flash Player 10.1:

private static function stackDump():void 
    { 

     //obj can be an object, dictionary, vector, array. 
     //probably anything that can be accessed using bracket notation. 
     var obj:Array = [1, 2]; 
     var dex:int = 0; 

     //if you access an object,vector,array,or dictionary using a nested incrimentor operator 
     //followed by a continue statement, you will get a stack dump. 
     //The loop can be a for, while, or do loop. 
     while (false) 
     { 
      obj[dex++] = 0; 
      continue; 
     } 

    }//end stackDump 
相關問題