在 AS2 中嵌入文本,例如 HEREDOC 或 CDATA
我正在使用 LoadVars() 将文本文件加载到字符串变量中。对于代码的最终版本,我希望能够将该文本作为动作脚本代码的一部分并将其分配给字符串,而不是从外部文件加载它。
类似于 PHP 中的 HEREDOC 语法或 AS3 中的 CDATA ( http://dougmccune.com/blog/2007/05/15/multi-line-strings-in-actionscript-3/ )
快速而肮脏的解决方案我发现是将文本放入影片剪辑中的文本对象中,然后获取值,但我不喜欢它
顺便说一句:文本是多行的,可以包含单引号和双引号。
谢谢!
I'm loading a text file into a string variable using LoadVars(). For the final version of the code I want to be able to put that text as part of the actionscript code and assign it to the string, instead of loading it from an external file.
Something along the lines of HEREDOC syntax in PHP, or CDATA in AS3 ( http://dougmccune.com/blog/2007/05/15/multi-line-strings-in-actionscript-3/ )
Quick and dirty solutions I've found is to put the text into a text object in a movieclip and then get the value, but I dont like it
Btw: the text is multiline, and can include single quotes and double quotes.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为在 AS2 中唯一的方法似乎是肮脏的。在 AS3 中,您可以使用 Embed 标签嵌入资源,但据我所知,在 AS2 中不能。
如果它是最终版本并且意味着您不想再编辑文本,则可以转义字符并使用 \n 作为换行符。
输出:
现在只需将文本复制到您最喜欢的文本编辑器中,并将每个 ' 和 " 更改为 \' 和 \",还将换行符更改为 \n。
I think in AS2 the only way seems to do it dirty. In AS3 you can embed resources with the Embed tag, but as far as I know not in AS2.
If it's a final version and it means you don't want to edit the text anymore, you could escape the characters and use \n as a line break.
outputs:
Now just copy the text into your favourite text editor and change every ' and " to \' and \", also the line breaks to \n.
Cristian,当您意识到它是一条线时,anemgyenge 的解决方案就会起作用。只需简单的操作即可选择和更换。
不要在代码编辑器中编辑文档。在文档编辑器中编辑文档并创建一个将其转换为长字符串的进程(例如通过快速 PHP 脚本运行它)。获取转换后的字符串并将其粘贴到旧字符串上。根据需要重复。
从长期管理的角度来看,这不太理想,特别是如果在没有移交解析器的情况下移交代码维护,但它可以解决一些维护问题。
Cristian, anemgyenge's solution works when you realize it's a single line. It can be selected and replaced in a simple operation.
Don't edit the doc in the code editor. Edit the doc in a doc editor and create a process that converts it to a long string (say running it through a quick PHP script). Take the converted string and paste it in over the old string. Repeat as necessary.
It's way less than ideal from a long-term management perspective, especially if code maintenance gets handed off without you handing off the parser, but it gets around some of your maintenance issues.
在每行上使用一对新的引号,并添加一个空格作为单词分隔符:
有一个项目可能有助于向 ActionScript 2 添加部分 E4X 支持:
以及一个为 Haxe 添加 E4X 支持的项目,它可以编译为 JavaScript 目标:
Use a new pair of quotes on each line and add a space as the word delimiter:
There is a project which may help that adds partial E4X support to ActionScript 2:
As well as a project which adds E4X support to Haxe, which can compile to a JavaScript target: