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 th开发者_如何学Cem 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
// 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
What are the names of the libraries? Try just mx.adobe.utils.ArrayUtil for the reference to the first class.
You can most likely use the package names to reference them directly (i.e. com.domandtom.MyUtils (open it up, and you'll see it defined at the top of the class file).
精彩评论