几天来我一直在研究的这个ActionScript代码在 JavaScript 中已经工作了100%,但当我试图在 ActionScript 中编译它时,它会说我出乎意料 /, 和 }符号。 这个语法是否是错误的, 如果是这样, 我该如何修正它? 我想我可以测试它为“Javascript ”, 使用 但是现在我喜欢 (http://jsfiddle. net/ < / a > ) 。
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);
}