# Watch Object Properties and Get Calling Function?

**URL:** https://forum.kirupa.com/t/watch-object-properties-and-get-calling-function/217513
**Category:** flash
**Created:** [February 27, 2007, 5:17pm UTC](https://forum.kirupa.com/t/watch-object-properties-and-get-calling-function/217513 "2007-02-27T17:17:11Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![duncanhall](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@duncanhall](https://forum.kirupa.com/u/duncanhall)
#### Post date: [February 27, 2007, 5:17pm UTC](https://forum.kirupa.com/t/watch-object-properties-and-get-calling-function/217513/1 "2007-02-27T17:17:11Z")

</div>

I want to watch a property of an object to see when it changes, like so:

[AS]  
var myObject:Object = new Object();  
myObject.xDirection = -1;

function objectWatcher(prop, oldVal, newVal) {  
trace ("xDirection is being changed from " + oldVal + " to " + newVal);  
return newVal;  
}

myObject.watch(“xDirection”, objectWatcher);  
myObject.xDirection = 22;  
[/AS]

This works as expected.

But if the value of the property being watched, is changed within a function, is there a way to tell which function that was?

EG:

[AS]  
var myObject:Object = new Object();  
myObject.xDirection = -1;

function objectWatcher(prop, oldVal, newVal) {  
trace ("xDirection is being changed from " + oldVal + " to " + newVal);  
//I want to be able to output something like this:  
trace("It was changed by " + NAME\_OF\_CALLING\_FUNCTION);  
return newVal;  
}

function changeTheValue():Void {  
myObject.xDirection = 22;  
}

myObject.watch(“xDirection”, objectWatcher);  
changeTheValue();  
[/AS]

Any help would be appreciated. Thanks.
