注:我已阅读https://meta.stackexchange.com/questions/128548/what-stack-overflow-is-not/129362#129362将此PHP转换为Actionscript?
它说:“尝试自己写代码和发布,当你遇到问题你已经尝试了什么。”这是我在这里做的。
原来的PHP代码:
$text = "Hello world, I am rainbow text!";
$texty = '';
$colors = 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;
$textlength = strlen($text);
while($i<=$textlength){
foreach($colors as $key=>$value){
if (isset($text[$i])) {
$texty .= "<font color=\"#".$value."\">".$text[$i]."</font>";
}
$i++;
}
$texty = str_replace("> <","> <",$texty);
echo $texty;
}
我已经宰杀它归结为:
var text = "Hello world, I am rainbow text!";
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');
var i = 0;
var textlength = text.length;
var key = '';
var value = '';
while(i <= textlength){
for each(colors as key=>value){
if (text[i] != undefined) {
texty .= "<font color=\"#" + value + "\">" + text[i] + "</font>";
}
i++;
}
texty.replace("> <","> <");
//document.write(texty);
}
我一直在测试这个如JavaScript,这就是为什么我有document.write在代码中注释。但是,我仍然无法完成它的工作。我讨厌这么模糊,但是......有人能告诉我我搞错了什么吗?
当您尝试运行此为ActionScript会发生什么?如果我们不知道运行时会发生什么,我们不能说错误发生在哪里。你在Flash或Flex项目中使用这个吗?它编译好吗? – halfer