ちょっとActionScriptの調べ物をすると3.0がヒットすることが多いが、最近ようやくActionScriptを触る機会が増えてきたといっても2.0のオレにはちょっと敷居が高い。
2.0でもオーバーライドが可能なようで、ちょっと驚いた。
LoadVarsクラスでデータをサーバにPOST(やGET)するときにURLエンコードしないようなオーバーライドは、こんな感じに実装するらしい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
///////////////////////////////////////////////// // URLエンコードしないsendメソッド // LoadVars.sendNoEnc() LoadVars.prototype.sendNoEnc = function( url, target, method) { // 正規toStringを退避 LoadVars.prototype._toString = LoadVars.prototype.toString; // toStringメソッドを上書きする // unescapeをかませる LoadVars.prototype.toString = function() {return unescape(this._toString());}; // _toStringに権限設定 3 : CanDelete=Yes, IsHiden=Yes ASSetPropFlags(LoadVars.prototype, "_toString", 3); // send実行 this.send(url, target, method); // 退避した正規toStringを戻す LoadVars.prototype.toString = LoadVars.prototype._toString; }; ASSetPropFlags(LoadVars.prototype, "sendNoEnc", 3); |
これを実際に利用するには、
1 2 3 |
my_lv = new LoadVars(); my_lv.hoge = "GETする文字列"; my_lv.sendNoEnc("http://example.com/", "_self", "GET"); |
とするだけのようなので簡単。
No comments yet. You should be kind and add one!
By submitting a comment you grant typista a perpetual license to reproduce your words and name/web site in attribution. Inappropriate and irrelevant comments will be removed at an admin’s discretion. Your email is used for verification purposes only, it will never be shared.