# Problems with eventDispatcher and inaccessible variables

**URL:** https://forum.kirupa.com/t/problems-with-eventdispatcher-and-inaccessible-variables/317097
**Category:** flash
**Created:** [December 10, 2010, 1:12pm UTC](https://forum.kirupa.com/t/problems-with-eventdispatcher-and-inaccessible-variables/317097 "2010-12-10T13:12:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tomii01](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@tomii01](https://forum.kirupa.com/u/tomii01)
#### Post date: [December 10, 2010, 1:12pm UTC](https://forum.kirupa.com/t/problems-with-eventdispatcher-and-inaccessible-variables/317097/1 "2010-12-10T13:12:00Z")

</div>

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:

```auto
public var RNDMCOLOR:String = "rndmColor";

```

and further down…

```auto

dispatchEvent(new Event("rndmColor"));

```

Then, in class A I have this in an ENTER FRAME function:

```auto

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:

```auto

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?
