PDA

View Full Version : variable of unkown type


shotsy247
07-22-2008, 05:44 PM
Hi All,

How do I create a class that will accept a variable if I do not know the type?

For example, my class will perform some alterations to a Sprite or MovieClip, perhaps even a Shape. How can I write the class to accept these types such as:

public class MyClass{
public function MyClass(obj:???){
//Do stuff
}
}

Thanks.

_t

Bombdogs
07-22-2008, 05:55 PM
obj:*

tho in your example perhaps a better way is to use the superclass that encompasses them all..

obj:DisplayObject

PMF

Bombdogs
07-22-2008, 05:57 PM
^ is there any way to stop that?? it's meant to read...

obj: DisplayObject; (without the space)

PMF

sberry2a
07-22-2008, 06:22 PM
There are a couple ways you could do this.

First you could use the wildcard type as in

public function doSomething(myObj:*) {

Secondly, since you mention wanting to pass MovieClip, Sprite or Shape, you could just make the datatype a DisplayObject (as long as the property/s you want to affect are all part of that class)