# How to change the value of a class from a different class

**URL:** <https://forum.kirupa.com/t/how-to-change-the-value-of-a-class-from-a-different-class/308191>\
**Category:** flash\
**Created:** [April 18, 2010, 7:47pm UTC](https://forum.kirupa.com/t/how-to-change-the-value-of-a-class-from-a-different-class/308191 "2010-04-18T19:47:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fs\_tigre](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@fs\_tigre](https://forum.kirupa.com/u/fs_tigre)\
**Post date:** [April 18, 2010, 7:47pm UTC](https://forum.kirupa.com/t/how-to-change-the-value-of-a-class-from-a-different-class/308191/1 "2010-04-18T19:47:38Z")

</div>

Hi,

I have two classes, class A and class B, where class A contains an input fields and its value can be modified by calling its instance name and giving it a new value

```auto

package {
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	public class A extends MovieClip {
		public function A() {
			// constructor
			button.addEventListener(MouseEvent.CLICK, changeValue);
		}

		function changeValue(e:MouseEvent):void {
			myText_txt.text='.20';
			trace("size changed");
		}

	}
}

```

And it works fine, the problems is when I try to change the value of this input field (myText\_txt) from class B, I did something like this… and it didn’t work.

```auto

package {
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	public class B extends MovieClip {
		var a:A;

		public function B() {
			a=new A();
			button.addEventListener(MouseEvent.CLICK, changeValue);
		}

		function changeValue(e:MouseEvent):void {
			a.myText_txt.text='.20';
			trace("size changed");
		}

	}
}

```

I get the trace statement message but it doesn’t change the value of myText\_txt fields.

I tried extending class A in class B but I got an error that says”TypeError: Error #1009: Cannot access a property or method of a null object reference.” Thats why I’m using the composition method but as you can see it is not working.

Any idea what I’m doing wrong? I know it is hard without seeing the actual code from each class.

Oh, both classes are attached to a movieClip in the library.

Thanks
