What's the best way to reuse functions in a Flex MVC framework?
3 answers
Create a static class or static method in one of the Cairngorm classes.
class MyStatic
{
public static function myFunction(value:String):String
{
return "Returning " + value;
}
}
Then where do you want to use your function:
import MyStatic;
var str:String = MyStatic.myFunction("test");
Another option is to create a top-level function (a la "trace"). Check this post, I wrote here .
+1
source to share
You have many options here - publicly defined functions in your model or controller, for example:
var mySharedFunction:Function = function():void
{
trace("foo");
}
... static methods for new or existing classes, etc. The best practice probably depends on what the function is supposed to do. Can you clarify?
+1
source to share