ActionScript 3 class over multiple files - how?
So how do I write a class over multiple files in script 3 action?
There is a "partial" keyword in C #.
In C ++ this is natural (you just "#include ..." all files).
In Flex 3, the component you add this tag: <mx:Script source="myfile.as"/>
.
How to split the following class into multiple files:
package package_path
{
public class cSplitMeClass
{
public function cSplitMeClass()
{
}
public function doX():void
{
// ....
}
public function doY():void
{
// ....
}
}
}
For example, I want to have doX () and doY () functions implemented in another .as file.
Can I do it?
And please don't tell me something like "it's a good practice to have them in the same file" :)
a source to share
As per your request, I will spare you a "best practices lecture". So, I'll just say what to include directive in AS 3.0, which might help you here.
Basically, you can do:
package package_path
{
public class cSplitMeClass
{
public function cSplitMeClass()
{
}
include "the_file_where_doX_and_doY_live.as"
}
}
And then in "the_file_where_doX_and_doY_live.as"
public function doX():void
{
// ....
}
public function doY():void
{
// ....
}
a source to share
This is good practice, nothing wrong with that.
Here is the key word import
. Example:
import Class_A.as;
import Class_B.as;
Now, of course, in order to use them, you need to declare them, preferably in your constructor.
public function Class_C()
{
//Create a new instance of Class_A
var objA:Object = new Class_A("parameter one", "parameter two");
//Create a new instance of Class_B
var objA:Object = new Class_B("parameter one", "parameter two");
}
Of course, it all depends on how you are going to do this job. I also suggest that you use a main class from which you can run your code. I think you already knew that.
Good luck.
a source to share