爲什麼此程序始終從函數year()輸出「future」的文本?函數返回
在這種情況下,B + C等於56,VAR年應歸入(B + C)> 0 & &(B + C)< 1000),並返回 「羅馬」,但它不是返回 「未來」 ...
我得到了這一點,如果我添加此能夠成功:
var period:String = (year(b,c));
,並在我的身體機能,使條件語句檢查期間。例如
if (period == "future")
但我不明白爲什麼我需要這樣做。我返回一個字符串,爲什麼我必須設置另一個變量?沒有編譯器錯誤,因此它顯然不是語法的?
var a:String = "Tim";
var b:int = 50; //CHANGE TO ANY INT YOU WANT
var c:int = 6; //CHANGE TO ANY INT YOU WANT
var d:String = "Kyle";
var sum:int = b+c;
function friend(d:String, a:String):String
{
return d+" and "+a;
}
function year(b:int, c:int):String
{
if((b+c) > 2000)
return "future";
else if((b+c)> 1000 && b+c< 2000)
return "colonial";
else if((b+c) > 0 && (b+c) < 1000)
return "roman";
else if((b+c) < 0)
return "medieval";
else
return "fail";
}
function intro(sum, friend):String
{
return "Once upon a time, in the year "+ b+c +", "+friend;
}
function body(year):String
{
if ("future")
return " saw a flying saucer and descided they wanted do be an alien.";
else if ("colonial")
return " just got off the the Mayflower and descided they wanted to eat some turkey.";
else if ("roman")
return " are taking a break after a fierce battle with the Romans.";
else if ("medieval")
return " saved the princess in shining armor after slaying the dragon.";
else if ("fail")
return " just got an F on their exam.";
else
return " just got an F on their test.";
}
trace (b+c);
trace(intro(sum, friend(d, a)) + body(year));
在乾淨的FLA中粘貼代碼會得到年份函數的「roman」(帶參數50和6)。你確定別的東西沒有用嗎? – 2011-02-23 21:39:27
如果我將代碼完全粘貼到閃存中,我會得到「曾幾何時,在506年,凱爾和蒂姆看到一個飛碟,並決定他們想成爲一名外星人。」 – dukevin 2011-02-23 22:03:58