Hi,
The problem I'm facing is that I'm trying to manipulate (in this particular case add eventListeners) objects (in this case some MovieClips) on the stage from a class that isn't the document class.
1120: Access of undefined property trans.
Now I know that it's probably a scope thing and I probably can't access stage objects directly from a non document class (as I'm doing in the code below) but I can't figure out how to access them properly. I've been stuck with this problem for a couple of hours already and I've read a lot of solutions to similar problems and explanations on scope related problems but I still haven't figured out a solution. I'm hoping now that someone here can help me out.
Anyway, here's the deal:
I've got 3 dynamic text fields (called "NL", "FR" and "EN") on my stage in a movieclip called "trans". I'm trying to add eventlisteners in a second class to make them do something when clicked on.
Here's my document class:
package {
import flash.display.MovieClip;
// Import custom classes.
import classes.Translate;
public class Main extends MovieClip {
// Init Translation class on load.
public var translate:Translate = new Translate();
public function Main() {
}
}
}
And here's my custom class Translate (which is in a subfolder "classes").
package classes {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Translate extends MovieClip {
public function Translate() {
// Init translation eventListeners.
trans.NL.addEventListener(MouseEvent.CLICK,
function(event:MouseEvent):void {
loadNl();
}
);
trans.FR.addEventListener(MouseEvent.CLICK,
function(event:MouseEvent):void {
loadFr();
}
);
trans.EN.addEventListener(MouseEvent.CLICK,
function(event:MouseEvent):void {
loadEn();
}
);
}
public function loadNl() {
trace("NL");
}
public function loadFr() {
trace("FR");
}
public function loadEn() {
trace("EN");
}
}
}
Thanks in advance for taking time to help me out.
Dries