Import aliases in ActionScript

-allow-import-aliases

Apache Royale adds support for declaring import aliaes in ActionScript. An import alias allows a class to be imported, but referenced in later code using a different base name. It is intended to help differentiate between multiple imported classes that have the same base name, but are in different packages, without having to use the fully-qualified name.

Requires Apache Royale 0.9.6 or newer.

Compiler option

Royale enables import aliases by default. To disable import aliases in your application, use the -allow-import-aliases compiler option.

mxmlc -allow-import-aliases=false MyApp.mxml

Code example

Consider the following code that imports two classes named Event, but gives them aliases to differentiate between them:

package
{
    import ExampleEvent = com.example.events.Event;
    import RoyaleEvent = org.apache.royale.events.Event;

    public class MyClass
    {
        public function MyClass()
        {
            addEventListener(RoyaleEvent.CHANGE, onRoyaleEvent);
            addEventListener(ExampleEvent.EXAMPLE, onExampleEvent);
        }

        public function onRoyaleEvent(event:RoyaleEvent):void
        {

        }

        public function onExampleEvent(event:ExampleEvent):void
        {

        }
    }
}

Limitations of import aliases in Royale

Other ActionScript compilers, such as the one in the Apache Flex SDK, may not recognize import aliases. Attemping to pass ActionScript or MXML source code that contains import aliases to another compiler will result in compile-time errors. In other words, to write 100% portable ActionScript code that works with any compiler, avoid using abstract classes and any of Royale’s other extensions to the ActionScript language.