Hi. I would like to know how to communicate between two classes using the following method:
test.swf
game/Core.as
game.FirstClass.as
game.SecondClass.as
So, that's the basic structure. If I call oFirstClass.TraceText() in the Core.as file, it will output the text. However, if I call oFirstClass.TraceText() or this.oFirstClass.TraceText() from the SecondClass, it won't shows the text.
What I don't understand is that subclasses are supposed to get properties and methods from the superclass, but a trace(oFirstClass) or this.oFirstClass nor this.firstclass() will show undefined :/ All I want is to use classes without putting everrything static and calling stuff like dir.class.function() and dir.class.property
test.swf
Code:
_global.CORE = new game.core();
CORE.initialize();
game/Core.as
Code:
class Core extends Object
{
var oFirstClass, oSecondClass;
function Core(){
}
function initialize(){
oFirstClass = new game.FirstClass();
oSecondClass = new game.SecondClass();
}
function get firstclass(){
return oFirstClass;
}
}
game.FirstClass.as
Code:
class game.FirstClass extends game.Core
{
function FirstClass(){
}
function TraceText(){
trace("Test");
}
}
game.SecondClass.as
Code:
class game.SecondClass extends game.Core
{
function SecondClass(){
oFirstClass.TraceText()
}
}
So, that's the basic structure. If I call oFirstClass.TraceText() in the Core.as file, it will output the text. However, if I call oFirstClass.TraceText() or this.oFirstClass.TraceText() from the SecondClass, it won't shows the text.
What I don't understand is that subclasses are supposed to get properties and methods from the superclass, but a trace(oFirstClass) or this.oFirstClass nor this.firstclass() will show undefined :/ All I want is to use classes without putting everrything static and calling stuff like dir.class.function() and dir.class.property