OOP way of prototype extension
http://stackoverflow.com/questions/4085566/adding-the-replaceall-method-to-the-actionscript-string-class
♥0 |
Line 27 |
Modified 2010-11-03 21:02:22 |
MIT License
archived:2017-03-09 19:18:31
ActionScript3 source code
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uILO
*/
package {
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
var tf:TextField = new TextField;
var str:String ="abbbcccaa";
tf.text = 'result : ' + new StringEx(str)
.replaceAll('b', 'c')
.replaceAll('c', 'a');
addChild(tf);
}
}
}
class StringEx {
private var string:String;
public function StringEx(string:String) {
this.string = string;
}
public function replaceAll(replace:String, replaceWith:String):StringEx {
string = string.replace(new RegExp(replace, 'g'), replaceWith);
return this;
}
public function toString():String {
return string;
}
}