Hi all!
I’ll try to explain my problem as simple as possible
So, I have class A (main class) and class B, and I need these to communicate with each other.
In class B, I have:
public var RNDMCOLOR:String = "rndmColor";
and further down…
dispatchEvent(new Event("rndmColor"));
Then, in class A I have this in an ENTER FRAME function:
hudColor.addEventListener(RNDMCOLOR, chooseColor, false, 0, true);
(hudColor) is the name of a MC which is supposed to show different colors, when needed.
Then, further down in class A:
private function chooseColor(e:Event):void {
var colorArray:Array = new Array("blue", "red", "green");
var c:int = Math.floor(Math.random() * 3);
hudColor.gotoAndStop(colorArray[c]);
}
This gives me the error: Access of undefined property RNDMCOLOR… but, I made it public, so it should be accessible by other classes right? Apparently, no
I have also tried to type the string “rndmColor” directly into the eventDispatcher and listener, and that gets rid of the error, but the chooseColor function is never called. So what the heck am I doing wrong? How do I make variables accessible from other classes if public doesn’t do it?