Packaging an AIR installation file

I found this adobe help page but I didn’t want to use command line for packaging an AIR installation file. Simply because I’m not used to it. So I was looking for a different way.

Well, actually Flex Builder provides the possibility to do that, but you must ensure to activate the “Copy non-embedded files to output folder” compiler option in the project properties. Otherwise Flex Builder won’t let you select your additional sources.

And for that reason you have to put your additional sources to the src-folder.

Using the Loader-Class with Adobe AIR

Just a quick note because it took me a little while to find out that it’s necessary to use “file://” syntax to access the local file system.

// Basic example:
var url: String = "file:///Users/markusraab/Desktop/yourfile.swf";
 
// or use a file reference:
var file: File = new File();
var url: String = file.url;
 
var loader: Loader = new Loader();
loader.load( new URLRequest( url ) );

Adobe AIR flash.filesystem.File methods throw Error 2037 when no nativePath is set

While developing an Flex based AIR Application I figured out an issue with the flash.filesystem.File class. I tried to access properties like exists, nativePath etc. before a nativePath was set using a browse method. So the while debugging the following error was triggered:

Error #2037: Functions called in incorrect sequence, or earlier

Well, I would expect to get at least some default values. For example File.exists should be false or something. But you will always get an exception. So after research I found a note about it here.

Anyway, the only chance you have is to catch the error.

But there is one thing more: If you publish the AIR application, install it and try it then, you won’t get an exception. Everything works fine than.

Select and access local SWF files within an AIR application

Well, it took me a little time to figure out how to select and load a local SWF file into an SWFLoader instance. Several times I got this error message:

SecurityError: Error #3015: Loader.loadBytes() is not permitted to load content with executable code.

After some research I found this “dreaming in flash” blog entry which basically contains the solution I was looking for.

But then it took me a little more time to figure out how to use this with the SWFLoader. So here is a basic code example:

import flash.display.Loader;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
import mx.controls.SWFLoader;
 
// File reference
var swfFile: File;
 
// Open the SWF file
var fileStream: FileStream = new FileStream();
	fileStream.open( swfFile, FileMode.READ );
 
// Read SWF bytes into byte array and close file
var swfBytes: ByteArray = new ByteArray();
	fileStream.readBytes( swfBytes );
	fileStream.close();
 
// Prepare the loader context to avoid security error
var loaderContext: LoaderContext = new LoaderContext();
	loaderContext.allowLoadBytesCodeExecution = true; // that's it!
 
// Now you could use this with a Loader instance
var loader: Loader = new Loader();
	loader.loadBytes( swfBytes, loaderContext );
 
// Or you could use this with a SWFLoader instance
var swfLoader: SWFLoader = new SWFLoader();
	swfLoader.loaderContext = loaderContext;
	swfLoader.source = swfBytes;

Adobe technology platform RIA guide

This is simply the link list contained in the recently released Adobe technology platform ActionScript Reference PDF.

API References

Documentation

Developer Centers

Downloads

Miscellaneous Resources

Mailing Lists

Forums

Write with AIR applications to the application resource directory

AIR applications are not permitted to write to the application resource directory. This seems to be a security feature and makes sense, because some systems would not allow to write into this directory at system level.

But for testing purposes you might hack this by using a single line of code:

// Writing into that file would fail
var yourFileInAppDir: File = File.applicationDirectory.resolvePath( "yourFile.xml" );
// This is the simple hack:
yourFileInAppDir = new File( yourFileInAppDir.nativePath );

But this only avoids a AIR security error! You must be sure to have write access to the directory!