1
votes

I'm trying to write a custom fadeTo(component, x, y):void method, which takes an arbitrary Flex Component as an argument and moves it to a given location, but smoothly.

The problem I'm running into is the following.

I want to send the component itself as argument, like this: (using Button as an example only)

fadeTo(myButton, 200, 500);

(this should move myButton smoothly from its current position to the position indicated as parameter)

However, I don't really know what type an arbitrary Flex Component is. How should I handle that?

What I would like is some advice as to how to proceed.

Thank you

1

1 Answers

4
votes

Use UIComponent as the argument type:

public function fadeTo(component:UIComponent, x:int, y:int):void{
 // do stuff
}

Or possibly IUIComponent:

public function fadeTo(component:IUIComponent, x:int, y:int):void{
 // do stuff
}

If you want to be truly generic, you can use the type Object:

public function fadeTo(component:Object, x:int, y:int):void{
  if(component is IUIComponent){
    // do stuff
  }
}