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.
Installed: Windows 10, Adobe AIR 18.0 SDK, flex_sdk_4.6
(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();
}
}
}
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
My AirSdk\bin path is in my PATH environment variable, so it finds AirSdk\bin\amxmlc.bat correctly.
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.*;
This answer has not resolved my issue: Flash Builder: 1172 Definition Could not be found
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
All the instructions here are good, save one line in HelloWorld.xml. Replace:
With:
Presumably this should match the version of AirSDK that you have installed on your machine.
Create 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:
(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:
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.
This gets a basic hello-world working. Now, for the file-access part, this link provides part of the solution:
Flash Builder: 1172 Definition Could not be found
Specifically, once again in your flexcfg.xml file, you need to find this line:
And add another line below it:
(once again, your AirSdk may be installed in another directory)
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.
The final version of HelloWorld.as looks like this:
flexcfg.xml is MOSTLY generated automatically. It's a long file, I won't share it all, but I will share some relevant lines:
and later in the file:
HelloWorld.xml is almost copy paste of the one from help.adobe.com, but here it is:
Finally, to wrap it up into one step, go.bat: