Quick question. I have been Googling this all morning, but it's either not there, or else written in a way that doesn't register. I am inclined to believe the latter, as this seems like it should be something completely trivial to me.
I made a small Flash file using AS 3.0, and this is the first time I've really been able to stick to the OOP way of doing things and not hack together a mix of stuff from the timeline to get around not having everything work in the classes.
So I'd like to keep it that way, but one thing is eluding me: I can't call a method of an instance of another class (than the one I'm calling from) without resorting to "DocumentClass(root).instanceName.method."
Intuition tells me there has to be a better way of doing this (like, without having to reference the document class every time I call another class instance's function; and CERTAINLY without having to use the word "root" - that just seems so Flash 5 to me.
Does anybody have a better way of doing this that they can share?
Thanks in advance! SS
edit: Here's some relevant code: Main class:
package myApp {
import flash.display.*;
import flash.events.*;
public class Main extends flash.display.MovieClip {
public var background;
public var control;
public function Main() {
//load the background
this.background = new Background();
this.addChild(background);
//load the control
this.control = new Control;
this.addChild(control);
}
}
}
Background class:
package myApp {
import flash.display.*;
import flash.events.*;
public class Background extends flash.display.MovieClip {
public function Background() {
this.x = 0;
this.y = 0;
}
public function doSomething() {
//do something here
}
}
}
Control class:
package myApp {
import flash.display.*;
import flash.events.*;
public class Control extends flash.display.MovieClip {
private var section01;
private var section02;
private var section03;
public function Control() {
//some constructor code here
}
public function doSomethingCaller() {
MyApp(root).background.doSomething(); <--- HERE
}
}
}