2012-05-24 2 views
0

이 ActionScript 코드는 며칠 동안 JavaScript에서 100 % 잘 작동하지만 ActionScript에서 컴파일하려고하면 예기치 않은 /,) 및} 기호가 있음을 나타냅니다. 이 구문이 잘못 되었습니까? 그렇다면 어떻게 수정해야합니까? 내가 http://jsfiddle.net/를 사용하여 빠른 테스트를 위해 자바 스크립트로 테스트 할 수있는 것이라고 상상하지만 지금은 = (ActionScript 예기치 않은 대시, 괄호 및 대괄호?

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

? AS2 문제는 아마도 AS2가 기본 지원을하지 않기 때문에 가능합니다. – PanterA

+0

그래, AS2입니다. : (Dang it ... – Dav

+1

AS2를 사용해야하는 경우에도 타사 ** [RegExp] (http://mathfest.blogspot.com.br/2010/03/regular-expressions-in-actionscript-2.html)** 클래스. – PanterA

답변

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;"); 
관련 문제