# Watch function in as 3

**URL:** <https://forum.kirupa.com/t/watch-function-in-as-3/309654>\
**Category:** Uncategorized\
**Created:** [May 20, 2010, 9:54pm UTC](https://forum.kirupa.com/t/watch-function-in-as-3/309654 "2010-05-20T21:54:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunilshrestha](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@sunilshrestha](https://forum.kirupa.com/u/sunilshrestha)\
**Post date:** [May 20, 2010, 9:54pm UTC](https://forum.kirupa.com/t/watch-function-in-as-3/309654/1 "2010-05-20T21:54:50Z")

</div>

I have been trying to convert the watch function code into AS 3. I am totally new to AS 3 and could not find the solution yet. Here is my code -

* * *

var buttons = {left:0, right:0};

function buttonCallback(prop, oldvalue, newvalue, userdata) {  
if (newvalue == 0) {  
buttonUp(userdata);  
}  
if (newvalue == 1) {  
buttonDown(userdata);  
}  
return newvalue;  
}

function buttonDown(buttonID){  
trace(buttonID +" down");  
};  
function buttonUp(buttonID){  
trace(buttonID +" up");  
};

## buttons.watch(“left”, buttonCallback, “LEFT”); buttons.watch(“right”, buttonCallback, “RIGHT”);

The variable ‘buttons’ must be in the root timeline. And, I cannot use this variable inside any other class.

Is it possible to convert it to AS 3?

Thanks!
