我正在開發一個Flash(Flash 9,AS3)來連接到服務器併發送/接收/解析數據到JavaScript/HTML上的聊天。 我有這樣的結構:原型和靜態類型變量的ActionScript問題
package {
public class myClass {
String.prototype.escapeHtml = function() {
var str = this.replace(/&/g, "&");
str = str.replace(/</g, "<");
str = str.replace(/>/g, ">");
return str;
}
function writeToBrowser(str:String) {
ExternalInterface.call("textWrite",str.escapeHtml());
}
}
}
當我編譯它,我得到這個錯誤:
1061: Call to a possibly undefined method escapeHtml through a reference with static type String.
如果我刪除:String
,這一切工作正常,但後來我不得不檢查str
是否是一個字符串,以及它是否未定義等等。
我在我的代碼中有很多像這樣的函數,其中許多函數接收用戶輸入的數據,所以我認爲刪除:String
並對每個函數進行多次檢查並不是最好的方法。
我該如何解決這個問題?
這將解決這個問題,但是當你有函數(function2(function3(str)))時,它只是醜陋而已。可能這是我的錯誤編碼。 – Mauricio 2009-02-19 15:45:53