Where can I find a description of the import in clause?

I was browsing some of the starling code when I saw this:-

import openfl.display.Stage in OpenFLStage;

Where can I find a description of this? What is it doing? How do I read this?

In the manual: Import - Haxe - The Cross-platform Toolkit

Import with alias

If a type or static field is used a lot in an importing module it might help to alias it to a shorter name. This can also be used to disambiguate conflicting names by giving them a unique identifier.

import String.fromCharCode in f; 

class Main { 
    static function main() { 
        var c1 = f(65); 
        var c2 = f(66); 
        trace(c1 + c2); // AB 

Here we import String.fromCharCode as f which allows us to use f(65) and f(66) . While the same could be achieved with a local variable, this method is compile-time exclusive and guaranteed to have no run-time overhead.

1 Like

Not that import ... in is the old syntax for this feature, in modern Haxe code you would probably use import ... as instead (which reads more nicely in my opinion). OpenFL is probably trying to preserve support for older Haxe versions.

You took the words out of my mouth – “isn’t this ‘as’ ?”

There’s still a lot of old source-code out there, and I guess we can be thankful that Haxe wasn’t written by the PHP team, which “deprecates” and removes things from their language based on the latest fashion. … :roll_eyes: