AS3文件系统的Hello World [英] AS3 Filesystem Hello World
问题描述
我想用的ActionScript3写的Hello World到一个文本文件中。我想编译和运行的命令行code。
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的SDK 18.0,flex_sdk_4.6
Installed: Windows 10, Adobe AIR 18.0 SDK, flex_sdk_4.6
(TLDR:我想要做自动化测试的一个更大的一块code命令行,当然我想不通这片)
(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)
我错过了一些步骤,我想不通。这是我的code:
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();
}
}
}
我第一次运行这个命令:
I ran this command first:
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.
我曾尝试与空气中的编译器(如上图所示)和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.*;
这个答案并没有解决我的问题: <一href="http://stackoverflow.com/questions/5446536/flash-builder-1172-definition-could-not-be-found">Flash制造商: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">
presumably这应该与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>
(和其他人,都开始以&lt;路径元素>) 这将引用文件从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:
<一个href="http://stackoverflow.com/questions/5446536/flash-builder-1172-definition-could-not-be-found">Flash制造商:1172定义找不到
具体而言,再次在flexcfg.xml文件,你需要找到这一行:
Specifically, once again in your flexcfg.xml file, you need to find this line:
<external-library-path>
和另起一行在它下面:
<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屋!