ActionScript意外斜杠,括号和Squiggly括号?

时间:2012-05-24 17:25:20

标签: actionscript

这个我已经工作了几天的ActionScript代码现在可以在JavaScript中100%正常工作,但是当我尝试在ActionScript中编译时,它说我有意外的/,)和}符号。这种语法是错误的,如果是这样,我该如何解决?我想我可以用Javascript测试它,以便使用http://jsfiddle.net/进行更快速的测试,但现在我喜欢=(

var txt = "This is a [rainbow]test to show that I can[/rainbow] make whatever I want [rainbow]appear as a rainbow[/rainbow] because I am [rainbow]awesome[/rainbow].";


    if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
        var colors = ['f0f', 'f0c', 'f09', 'f06', 'f03', 'f00', 'f30', 'f60', 'f90', 'fc0', 'ff0', 'cf0', '9f0', '6f0', '3f0', '0f0', '0f3', '0f6', '0f9', '0fc', '0ff', '0cf', '09f', '06f', '03f', '00f', '30f', '60f', '90f', 'c0f'];

        function rainbowify(text) {
            return text.replace(/\[rainbow\](.+?)\[\/rainbow\]/g, function(_, inner) {
                return inner.replace(/./g, function(ch, i) {
                    return '<font color="#' + colors[i % colors.length] + '">' + ch + '</font>';
                });
            })
        }
        txt = rainbowify(txt);
        document.write(txt);
    }​

1 个答案:

答案 0 :(得分:0)

嗯,就是这样:

    txt = txt.replace("&apos;", "@");
if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
    var firstChar = txt.indexOf("[rainbow]") + 9;
    var lastChar = txt.indexOf("[/rainbow]");

    while (lastChar <= txt.lastIndexOf("[/rainbow]")) {
        var RAINBOWTEXT = '';
        var i = firstChar;
        while (i < lastChar) {
            RAINBOWTEXT += txt.charAt(i);
            i++
        }
        var text = RAINBOWTEXT;
        var texty = '';

        colors = new Array('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000','ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00','99ff00','66ff00','33ff00','00ff00','00ff33','00ff66','00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff','0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff');

        i = 0;

        while (i <= text.length) {
            var t = text.charAt(i);

            if (t != undefined) {
                texty += "<font color=\"#" + colors[i % colors.length] + "\">" + t + "</font>";
                i++;
            }
        }

        texty = texty.replace("> <", ">&nbsp;<");
        var REPLACEME = "[rainbow]" + RAINBOWTEXT + "[/rainbow]";
        txt = txt.replace(REPLACEME, texty);

        if (lastChar == txt.lastIndexOf("[/rainbow]")) {
            break;
        }
        nextChar = lastChar + 10;
        firstChar = txt.indexOf("[rainbow]", lastChar) + 9;
        lastChar = txt.indexOf("[/rainbow]", lastChar);
    }
}
txt = txt.replace("@", "&apos;");