0

I know that ActionScript3 allows functions to be passed as arguments to be other functions. Is it possible for an MXML component to be passed as an argument for a function? If so how?

For instance, I would like to do something like this:

private function getGlobalXY(comp:UIComponent):Point{
    return comp.localToGlobal(new Point(0, 0)));
}

But I get an error: "Type was not found or was not a compile-time constant: UIComponent."

This is as part of a Flex Project. I am using Flex 4.7.

Community
  • 1
  • 1
danxinnoble
  • 155
  • 1
  • 6
  • 1
    Yes you can pass anything as argument, this error has nothing to do with passing arguments. – BotMaster Nov 11 '15 at 15:52
  • That error indicates that you don't have the Flex framework available in your project. Did you create an "Actionscript project" in Flash Builder? – Brian Nov 11 '15 at 16:26
  • @Brian It is a Flex project, not Actionscript project (just added as edit). Could that be causing the error? – danxinnoble Nov 11 '15 at 16:34
  • You *do* have the import statement in your code, right? (sorry if this is asking a too-obvious question) – Brian Nov 11 '15 at 16:42
  • Another thought: Check any libraries that you're importing. I think it can cause problems if you're importing e.g. a Flex 3 .swc in a Flex 4 project. – Brian Nov 11 '15 at 16:46
  • @Brian :/ "import mx.core.UIComponent;" was missing. Thanks. Add it as an answer and I'll accept the answer. – danxinnoble Nov 11 '15 at 17:02

1 Answers1

0

Try to change UIComponent on DisplayObject:

private function getGlobalXY(comp:DisplayObject):Point {
    return comp.localToGlobal(new Point(0, 0)));
}

Also, don't forget to import the classes you want to use.

Mark Dolbyrev
  • 1,887
  • 1
  • 17
  • 24