forked from: forked from: OOP way of prototype extension

by ohisama forked from forked from: OOP way of prototype extension (diff: 23)
♥0 | Line 44 | Modified 2013-02-03 10:13:23 | MIT License
play

ActionScript3 source code

/**
 * Copyright ohisama ( http://wonderfl.net/user/ohisama )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9DEK
 */

// forked from 9re's forked from: OOP way of prototype extension
// forked from 9re's OOP way of prototype extension
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 = ("substring" in "") + "";
            tf.text = 'result : ' + new StringEx(str).replaceAll('b', 'c').replaceAll('c', 'a').substring(4);
            addChild(tf);
        }
    }
}
import flash.utils.Proxy;
import flash.utils.flash_proxy;
dynamic class StringEx extends Proxy 
{
    private var string : String;
    flash_proxy override function getProperty(name : *) : * 
    {
        return string[name];
    }    
    flash_proxy override function callProperty(name : *, ...rest) : * 
    {
        if (name in string && (typeof string[name] == 'function'))
            return string[name].apply(string, rest);
    }
    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;
    }
}