AS3 文件系统 Hello World [英] AS3 Filesystem Hello World

查看:37
本文介绍了AS3 文件系统 Hello World的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ActionScript3 将Hello World"写入文本文件.我想从命令行编译并运行该代码.

I would like to use ActionScript3 to write "Hello World" to a text file. I'd like to compile and run that code from the command line.

已安装:Windows 10、Adobe AIR 18.0 SDK、flex_sdk_4.6

Installed: Windows 10, Adobe AIR 18.0 SDK, flex_sdk_4.6

(TLDR:我想从命令行对更大的一段代码进行自动化测试,当然我无法弄清楚这一段)

(TLDR: I want to do automated testing for a much larger piece of code from the command line, and of course I can't figure out this piece)

我遗漏了一些我无法弄清楚的步骤.这是我的代码:

I am missing some steps that I can't figure out. Here's my code:

MainF.as

package {
    import flash.display.*;
    import flash.text.*;
    import flash.filesystem.*;

    public class MainF extends Sprite
    {
        public function MainF()
        {
            var file:File =  new File("output.txt");
            var stream:FileStream = new FileStream();
            stream.open(file, FileMode.WRITE);
            stream.writeUTFBytes("Hello World!");
            stream.close();
        }
    }
}

我先运行了这个命令:

amxmlc MainF.as -dump-config aircfg.xml

现在我用它来编译我的项目:

And now I am using this to compile my project:

amxmlc MainF.as -load-config aircfg.xml

我的 AirSdk\bin 路径在我的 PATH 环境变量中,所以它正确地找到了 AirSdk\bin\amxmlc.bat.

My AirSdk\bin path is in my PATH environment variable, so it finds AirSdk\bin\amxmlc.bat correctly.

我尝试使用 air 编译器(如上所示)和 flex 编译器 (flex_sdk_4.6\bin\mxmlc.exe) 编译它.我试过的所有东西都有这个错误:

I have tried compiling this with the air compiler (shown above) and the flex compiler (flex_sdk_4.6\bin\mxmlc.exe). Everything I have tried has this error:

Warning: No definitions matching flash.filesystem.* could be found.
        import flash.filesystem.*;

这个答案没有解决我的问题:​​Flash Builder:无法找到 1172 定义

This answer has not resolved my issue: Flash Builder: 1172 Definition Could not be found

我需要更具体的说明,我对 AS3 很陌生.而且,正如我所说,我需要它在从命令行编译和运行时工作.

I need much more specific instructions, I'm very new to AS3. And, as I said, I need it to work when compiled and run from the command line.

推荐答案

从最有用的帮助页面开始:

Starting with the most useful help page:

http://help.adobe.com/en_US/air/build/WS901d38e593cd1bac25d3d8c712b2d86751e-8000.html

这里的所有说明都很好,在HelloWorld.xml中保存一行.替换:

All the instructions here are good, save one line in HelloWorld.xml. Replace:

<application xmlns="http://ns.adobe.com/air/application/2.7">

与:

<application xmlns="http://ns.adobe.com/air/application/18.0">

大概这应该与您机器上安装的 AirSDK 版本相匹配.

Presumably this should match the version of AirSDK that you have installed on your machine.

创建 flexcfg.xml:

Create flexcfg.xml:

mxmlc -dump-config flexcfg.xml

这会抛出编译器错误,忽略它们.这个文件会有很多问题,需要修复.几个路径设置不正确:

This will throw compiler errors, ignore them. There will be many problems with this file, which need to be fixed. Several paths will not be set correctly:

<path-element>libs</path-element>

(以及其他,都以 < path-element > 开头)这些将引用来自您的 AirSDK 的文件,但不会正确引用它们.我把我本地 AirSDK 的完整路径:

(and others, all starting with < path-element >) These will reference files from your AirSDK, but it will not reference them correctly. I put the full path to my local AirSDK:

<path-element>C:/dev/AirSdk/frameworks/libs</path-element>

此路径对于您安装的 AirSDK 来说是唯一的.再一次,将有几个,修复所有这些,分散在文件中.

This path will be unique to your installation of the AirSDK. Once again, there will be several of these, fix all of them, scattered in the file.

这得到了一个基本的 hello-world 工作.现在,对于文件访问部分,此链接提供了部分解决方案:

This gets a basic hello-world working. Now, for the file-access part, this link provides part of the solution:

​​Flash Builder:无法找到 1172 定义

具体来说,再次在您的 flexcfg.xml 文件中,您需要找到这一行:

Specifically, once again in your flexcfg.xml file, you need to find this line:

<external-library-path>

并在其下方添加另一行:

And add another line below it:

<path-element>C:/dev/AirSdk/frameworks/libs/air/airglobal.swc</path-element>

(再次说明,您的 AirSdk 可能安装在另一个目录中)

(once again, your AirSdk may be installed in another directory)

有几个地方可以为您提供将Hello World"写入文件所需的行,这里有一个:在 AS3 中将字符串保存到文本文件确保您使用writeUTFBytes"作为答案,而不是问题.

There are several places that will give you the necessary lines to write "Hello World" to a file, here's one: Saving string to text file in AS3 Make sure you use "writeUTFBytes" as the answer indicates, rather than the question.

HelloWorld.as 的最终版本如下所示:

The final version of HelloWorld.as looks like this:

package
{
    import flash.display.Sprite;
    import flash.text.*;
    import flash.filesystem.*;

    public class HelloWorld extends Sprite
    {
        public function HelloWorld()
        {
            var textField:TextField = new TextField();
            stage.addChild( textField );
            textField.text = "Hello, World!";

            var outputFile:File = new File("C:/depot/sdks/ActionScriptSDK/HelloWorld/output.txt");
            var stream:FileStream = new FileStream();
            stream.open(outputFile, FileMode.WRITE);
            stream.writeUTFBytes("Hello, File World!");
            stream.close();
        }
    }
}

flexcfg.xml 主要是自动生成的.这是一个长文件,我不会全部分享,但我会分享一些相关的行:

flexcfg.xml is MOSTLY generated automatically. It's a long file, I won't share it all, but I will share some relevant lines:

<external-library-path>
    <path-element>C:/dev/AirSdk/frameworks/libs/player/{targetPlayerMajorVersion}.{targetPlayerMinorVersion}/playerglobal.swc</path-element>
    <path-element>C:/dev/AirSdk/frameworks/libs/air/airglobal.swc</path-element>
</external-library-path>

以及稍后在文件中:

<library-path>
    <path-element>C:/dev/AirSdk/frameworks/libs</path-element>
    <path-element>C:/dev/AirSdk/frameworks/locale/{locale}</path-element>
</library-path>

HelloWorld.xml 几乎是从 help.adobe.com 复制粘贴的,但这里是:

HelloWorld.xml is almost copy paste of the one from help.adobe.com, but here it is:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/18.0">
    <id>samples.android.HelloWorld</id>
    <versionNumber>0.0.1</versionNumber>
    <filename>HelloWorld</filename>
    <initialWindow>
        <content>HelloWorld.swf</content>
    </initialWindow>
    <supportedProfiles>mobileDevice</supportedProfiles>
</application>

最后,将其打包成一个步骤,go.bat:

Finally, to wrap it up into one step, go.bat:

call mxmlc HelloWorld.as -load-config flexcfg.xml
call adl HelloWorld.xml

这篇关于AS3 文件系统 Hello World的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆