Hey guys. I know that this is not in the best practices manual, but I need to place a method DIRECTLY inside a package of mine. Pretty much like flash does with the as3 new flash.utils.* package methods.
Could anyone guide me on this :)… I’ve been searching around hardly with zero results.
The link you’ve reported brings that there can be only one public function per AS file. So, taking the example of flash.utils.* methods, to do something like that (with may methods directly inside a package), should I have to create multiple AS with the same package name? One for each method?
What? You can have as many public functions as you please, can’t you? I know I certainly have custom packages with a bunch of public functions in a single file. You can only have a single constructor, but that’s different.
[QUOTE=Anogar;2350429]What? You can have as many public functions as you please, can’t you? I know I certainly have custom packages with a bunch of public functions in a single file. You can only have a single constructor, but that’s different.[/QUOTE]
Are you sure that you’re talking about package functions? Obviously you can have multiple public methods in a class, but package functions don’t have an enclosing class (thus the name).
If I try to put multiple, publicly-visible functions in a file, like this:
package funcs {
public function a(){
trace('a');
}
public function b(){
trace('b');
}
}
… then I get the error “5006: An ActionScript file can not have more than one externally visible definition: funcs.b, funcs.a”, which is expected because you always name the file after the one externally visible definition.
It’s for functions that aren’t specific to a class. Stuff like flash.utils.getTimer and trace are packaged functions because they are used throughout. Many people create singleton classes which is the same sort of idea.