forked from: OOP way of prototype extension

by 9re forked from OOP way of prototype extension (diff: 15)
♥0 | Line 38 | Modified 2010-11-04 11:04:14 | MIT License
play

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/38GV
 */

// 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;
    }
}

Forked