How to add AIR externs?

I’m working on trying to get Haxe/OpenFL running for a project that targets AIR. I’m fairly new to Haxe, so this might be obvious.

So far, I’ve been able to successfully use some AIR APIs/classes in a project that targets AIR, but the IDE I’m using (Intellij) doesn’t seem to have access to any AIR externs, so working with AIR APIs is a bit of a chore. What am I missing?

UPDATE: I tried importing haxe/lib/lime/6,4,0/externs/air as a module dependency, and it seems to fix the IDE’s access to the classes, but certain classes (ie, FileStream) now throw objectEncoding errors on compilation.

1 Like

When you building using openfl test air, it should automatically include the AIR externs.

You can get an idea of the paths used for your project (when building) by running openfl display air and seeing what paths it displays

Okay, I removed the module import, and I can confirm that when I run “openfl test air” the air extern path (/usr/local/lib/haxe/lib/lime/6,4,0/externs/air) shows up in the list.

However, Intellij now doesn’t recognize the AIR class references again, and although some class references compile fine anyway, others cause compilation errors.

For example, when I create the following Main class:

package;

import openfl.display.Sprite;
import flash.filesystem.FileStream;

class Main extends Sprite {
	
	public function new () {

		super ();

		var fileStream:FileStream = new FileStream();
	}
}

…FileStream is flagged by Intellij as an “unresolved symbol”, and testing from the command line gives the following errors:

/usr/local/lib/haxe/lib/lime/6,4,0/externs/air/flash/filesystem/FileStream.hx:3: lines 3-40 : Field objectEncoding has different type than in openfl.utils.IDataOutput
/usr/local/lib/haxe/lib/openfl/8,3,0/src/externs/core/openfl/openfl/utils/IDataOutput.hx:21: characters 8-42 : Interface field is defined here
/usr/local/lib/haxe/lib/lime/6,4,0/externs/air/flash/filesystem/FileStream.hx:3: lines 3-40 : UInt should be openfl.net.ObjectEncoding
/usr/local/lib/haxe/lib/lime/6,4,0/externs/air/flash/filesystem/FileStream.hx:3: lines 3-40 : Field objectEncoding has different type than in openfl.utils.IDataInput
/usr/local/lib/haxe/lib/openfl/8,3,0/src/externs/core/openfl/openfl/utils/IDataInput.hx:29: characters 8-42 : Interface field is defined here
/usr/local/lib/haxe/lib/lime/6,4,0/externs/air/flash/filesystem/FileStream.hx:3: lines 3-40 : UInt should be openfl.net.ObjectEncoding

Any idea what I’m doing wrong?

It sounds like there are some minor issues with the Lime externs that need to be resolved, which don’t appear until runtime, when using certain classes, I guess.

Could you try changing this line to #if openfl openfl.utils.ObjectEncoding #else UInt #end and see if it works?

1 Like

Thanks!

Replacing:

	var objectEncoding : UInt;

with:

	var objectEncoding : #if openfl openfl.utils.ObjectEncoding #else UInt #end;

…gives me this error when I test from the command line:

/usr/local/lib/haxe/lib/lime/6,4,0/externs/air/flash/filesystem/FileStream.hx:6: characters 33-60 : Type not found : openfl.utils.ObjectEncoding

FYI, doing a find for ObjectEncoding.hx in lib shows me the following:

.//lib/haxe/lib/openfl/8,3,0/lib/openfl/net/ObjectEncoding.hx
.//lib/haxe/lib/openfl/8,3,0/src/externs/core/flash/flash/net/ObjectEncoding.hx
.//lib/haxe/lib/openfl/8,3,0/src/externs/core/openfl/openfl/net/ObjectEncoding.hx
.//lib/haxe/lib/openfl/8,3,0/src/openfl/net/ObjectEncoding.hx
.//lib/haxe/std/flash/net/ObjectEncoding.hx

Oh, I guess it should be openfl.net.ObjectEncoding :slight_smile:

Ah, of course. That works!

The Intellij plugin still doesn’t know what to make of FileSystem (I don’t think it’s looking at the AIR externs) but I assume that’s an issue for the plugin developer?