One of my favorite things about Flex is first-class functions. They make my life easy. I recently wanted to add some utility functions to my app, and since Flex has first-class functions, I thought to myself, I can just define them outside of a class, instead of having to define (and use, more importantly) static methods on a class. Apparently, FlexBuilder does not like this--it does not complain about the definition, but when I try to use it, it does not recognize that the symbol is defined. Is there a way to define publically visible first-class functions (rather than static methods), like escape, isNaN, trace, etc? Ideally, I'd like these in a package or namespace, but I'm curious in any case.
I believe you can, but the rules for public functions are similar to those for classes:
Only one public function per AS file
Filename must match public function name
Public function must be placed within a package declaration
Private functions must be placed outside and after package declaration
You must import the function before you use it
public function publicFunc() : int
return 4 + privateFuncA() * privateFuncB();
function privateFuncA() : int
function privateFuncB() : int
You would use the above by importing publicFunc and then calling it:
var result : int = publicFunc();
On Mon, Nov 30, 2009 at 2:14 PM, paul.williams <email@example.com> wrote:
These are what I was missing. It's working now--thank you.