Reputation: 11982
In AS3
, the below method accepts a parameter of any type:
public function myFunc(data:*) :void
Is it possible to limit the type to a specific package? Something like this maybe:
public function myFunc(data:(my.package:*)) //Accepts any type from my.package
Upvotes: 1
Views: 54
Reputation: 17237
This sounds like a design issue. One way to make this work during compile is if the parameter type is a custom class:
public function myFunc(data:MyCustomClass):void
Assuming that all the classes within my.package
are varied, you could create a custom base class that extends Object
and have all of your classes within my.package
extend from this base class. Of course, If, however, the inheritance of your my.package
classes is less broad you wouldn't need to reach so far. For example, you should only extend from DisplayObject
if all the classes within my.package
are of that type.
There may also be a way to accomplish what you want using namespaces
, but I'm unsure.
Upvotes: 1
Reputation: 18757
It is possible, but will only have type control at runtime.
import flash.utils.getQualifiedClassName;
public function myFunc(data:*):void {
if (data is Object) {
var fqcn:String=getQualifiedClassName(data);
if (fqcn.slice(0,10)!='my.package') return; // otherwise work
// work here
} // simple types process if needed
}
Upvotes: 3