PDA

View Full Version : Importing Functions, Possible?



Alpha eX
April 14th, 2008, 02:50 AM
I want to make an external as file that will have a set of functions in, I want to be able to include these functions to a class without having to rewrite them, is this possible?

For example

Game.as (will contain functions)

package Game{

function test(){
trace("hello");
}

}

Character.as

package{

public class Character
{
import Game;

public function Character()
{
test(); //hello
}

}
}

I know my code may be wrong, it is just an example of what I would like to achieve.

Thanks for reading and in advance for any replies.

Krilnon
April 14th, 2008, 10:11 AM
Things called 'package functions' exist, but I believe that you're only allowed to define one externally visible function in each AS file, so you would have to have a test.as that would hold test, test1.as to hold test1, etc.

It would probably be easier to have a class full of static functions, kind of like the Math class. At least, it would be easier in the sense that you could have all of the function definitions in one file.