如何使 actionscript 2 将代码解释为纯文本?

Posted

技术标签:

【中文标题】如何使 actionscript 2 将代码解释为纯文本?【英文标题】:How to make actionscript 2 interpret code as plain text? 【发布时间】:2013-01-21 19:55:23 【问题描述】:

我正在尝试创建一个基于 Flash 的活动,最终用户将输入一些 Java 作为写作练习,完成后,他们将按 Enter 键,Flash 将检查他们是否输入正确。

问题出在我正在编写动作脚本的地方。当我测试这部电影时,flash 会抛出很多错误,因为它认为我在输入文本框中键入的 Java 只是格式不正确的代码。我使用的代码过去曾用于简单的事情,例如键入名称或数字,但使用代码类型输入时,它会中断。我知道 html 中有标签可以将代码显示为文本,但我在 actionscript 2 中找不到任何关于如何执行此操作的信息。这就是我所拥有的:

keyListener = new Object();
keyListener.onKeyDown = function() 
if(Key.getCode() == Key.ENTER)
if(allthecode.text == "
    // Import the required API classes.
    import java.util.Scanner;
 
    public class ShowByte 
    
    public static void main(String[] args) 
    
    // Create the scanner.
    Scanner GetByte = new Scanner(System.in);

    // Obtain a byte value.
    System.out.print("Type any number: ");
    byte MyByte = GetByte.nextByte();

    // Display the value on screen.
    System.out.println("The value of MyByte is: " + MyByte);
    
    
    ") gotoAndPlay(150);
        
    
;
Key.addListener(keyListener);

编辑:Lee 发现代码位于多行。一旦我将所有内容都放在“ ”标记内并将所有内容压缩成一行,它就起作用了!

【问题讨论】:

【参考方案1】:

我认为由于您格式化字符串的方式而出现错误 - 您有 " 围绕字符串但也在其中 - flash 会混淆。使用 " 或 ' 来围绕字符串,然后在字符串中使用其他类型。例如:

if (allthecode.text == '
    // Import the required API classes.
import java.util.Scanner;

public class ShowByte 

public static void main(String[] args) 

// Create the scanner.
Scanner GetByte = new Scanner(System.in);

// Obtain a byte value.
System.out.print("Type any number: ");
byte MyByte = GetByte.nextByte();

// Display the value on screen.
System.out.println("The value of MyByte is: " + MyByte);


') gotoAndPlay(150);

或发布您收到的错误消息并证明我错了;)

【讨论】:

请注意 stackExchange 本身对我的字符串的格式与您的不同 - 您的代码在内部字符串中有语法高亮显示;我的没有。 您好,感谢您对此进行调查。我尝试了这个想法,虽然它确实以不同的方式格式化代码(似乎是一个好兆头!)它仍然抛出错误...... 1.Line4:字符串文字没有正确终止 2.Line6:')'预期 3。第 7 行:语法错误。 4.Line8:类外使用的属性。 5.Line10:语法错误。 6.Line13:无法加载类或接口'java.util.Scanner'。 7.Line17:语法错误。 8.Line22:遇到意外的'' 9.Line23:字符串文字未正确终止。所以……有点乱。 :-/ 您的 不平衡 - 在“gotoAndPlay(150);”之后添加另一个“” 哇!你不需要额外的 - 我想我算错了。这可能是因为您的字符串跨越多行。我不再使用 AS2,所以我可能错了。 嗯。最后总是简单的答案。问题是有多条线路。我习惯了 HTML,其中文本编辑器中的多行通常没有区别。非常感谢!

以上是关于如何使 actionscript 2 将代码解释为纯文本?的主要内容,如果未能解决你的问题,请参考以下文章

将 Actionscript 2 转换为 Actionscript 3

将 ActionScript 2 SWF 转换为 ActionScript 3 SWF 文件(可以剥离代码)

actionscript 透明 textinput 背景

如何使子弹移动 Actionscript 3.0

Flash / Actionscript:如何使重叠的精灵不可见

将html代码转换为actionscript代码