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

Running Adobe AsDoc on my Mac using ANT!

Wow, this was really challenging! But now, finally, I found out how to use AsDoc on my Mac.There must be another solution out there, but I simply want to document this workaround hoping that this also works on your Mac.

What you need is a Flex SDK 2.0.1 which comes with Flex Builder or as a free download from Adobe and the knowledge how to use ANT (I use eclipse).

I tried this tutorial several times but it never worked for me. I don’t know why.But after hours of testing I Â hopefully found a proper solution which works find with Flex SDK 2.0.1. The main idea simply is separating the AsDoc functionality from the normal Flex Builder environment. Basically the only thing you have to do is avoiding whitespaces from your directory names. However I tried to use Flex Builder for this and Flex Builder installs into the directory “Flex Builder 3”.So this is what I did and you might try:

  • Create a new directory within the applications folder (don’t use whitespace!) “Applications/Adobe_AsDoc”
  • Copy the Flex SDK 2.0.1 into that “Adobe_AsDoc” directory
  • Rename the Flex SDK directory to “FlexSDK_201” (which might not be necessary, but I tried to avoid any special characters within the directory names)

Great. So all you have to do now is download and use this ANT build.xml (download):

<?xml version="1.0" encoding="UTF-8"?>
<project name="Documentation" default="asdoc">
 
	<property environment="env"/>
 
	<!--
			Markus Raab - derRaab.com / superclass.de
 
			This ANT build.xml works on a Mac with a FLEX SDK 2.0.1 in the following location:
			/Applications/Adobe_AsDoc/FlexSDK_201
 
			For more informations see: blog.derraab.com
 
			ATTENTION: Use relative paths (according to this build.xml)
	-->
 
 
	<!--
	ActionScript directory location in source-path and doc-sources (both are needed?)
	-->
	<property name="source-path" value="../src/as/"/>
	<property name="doc-sources" value="../src/as/"/>
 
	<!--
	List with all your used library SWC files (using a directory causes asdoc not to write any documentation files?)
	-->
	<property name="library-path" value="../src/as/mdm.swc ../src/as/layout.swc"/>
 
	<!--
	Documentation output directory
	-->
	<property name="output" value="./classes"/>
 
	<!--
	SDK Location (without whitespace!)
	-->
	<property name="flex-sdk" value='/Applications/Adobe_AsDoc/FlexSDK_201'/>
 
	<!--
	Location of the asdoc templates
	-->
	<property name="templates-path" value='${flex-sdk}/asdoc/templates'/>
 
 
	<!--
	run
	-->
	<target name="asdoc">
 
		<exec executable='${flex-sdk}/bin/asdoc'>
 
			<arg value='-source-path ${source-path}'/>
			<arg value='-doc-sources ${doc-sources}'/>
			<arg value='-library-path ${library-path}'/>
			<arg value='-output ${output}'/>
			<arg value='-templates-path ${templates-path}'/>
 
		</exec>
 
	</target>
 
</project>