Search code examples
actionscript-3importdisambiguation

How do I distinguish between two imports with the same name in as3?


I have two ArrayUtil classes I need to access from the same class - they each come from external libraries and have different code, so I can't just combine them.

How do I disambiguate them in the code?

I tried doing com.adobe.utils.ArrayUtil inline, and leaving the existing import, but that resulted in an undefined property com error.

Cheers


Solution

  • // In main class/timeline etc
    
    import package1.*;
    import package2.*;
    
    var a1:package1.A = new package1.A();
    var a2:package2.A = new package2.A();
    

    Package 1 Class

    // In package1.A.as
    package package1 {
    
        public class A {
    
            public function A() {
                // constructor code
                trace("P1");
            }
    
        }
    
    }
    

    Package 2 Class

    // In package2.A.as
    package package2 {
    
        public class A {
    
            public function A() {
                // constructor code
                trace("P2");
            }
    
        }
    
    }
    

    Output

    // Outputs
    P1
    P2
    

    If you need to access static methods or properties. You would do something similar to the following:

    import com.adobe.utils.ArrayUtil;
    
    var a:Array = ["A", "B", "C"];
    trace(com.adobe.utils.ArrayUtil.arrayContainsValue(a, "B")); // outputs true