Can I put two or more actionscript classes in one .as file like this:
//A.as package classes { public class A { public function A() { var b:B = new B(); } } internal class B { public function B() { trace("Hello"); } } }
It doesn't work in Flash Builder:
A file found in a source-path can not have more than one externally visible definition. classes:A; classes:B
If it possible, I'm going to ask next question.
Can I place two or more packages with multiple classes in one .as file?
In Java, you can define multiple top level classes in a single file, providing that at most one of these is public (see JLS §7.6).
No. This is bad advice. Take the advice of the accepted answer. You should separate the object repository from the class you saving.
No and no. The following works:
//A.as
package classes {
public class A {
public function A() {
var b:B = new B();
}
}
}
class B { // <--- Note the class is outside of the package definition.
public function B() {
trace("Hello");
}
}
The class B
is only visible to the class A
- you cannot have more than one visible class in one file (exactly what the error message states). And you cannot have more than one package in a file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With