# Can A variable change be detected?

**URL:** <https://forum.kirupa.com/t/can-a-variable-change-be-detected/330464>\
**Category:** flash\
**Created:** [January 25, 2013, 1:29pm UTC](https://forum.kirupa.com/t/can-a-variable-change-be-detected/330464 "2013-01-25T13:29:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FJW](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@FJW](https://forum.kirupa.com/u/FJW)\
**Post date:** [January 25, 2013, 1:29pm UTC](https://forum.kirupa.com/t/can-a-variable-change-be-detected/330464/1 "2013-01-25T13:29:42Z")

</div>

Hi once again  
I have one of my usual switch statements that perhaps shows my age:-)  
The code snippet shows 2 key presses that set oldText to a String.  
What I am looking for is to detect the text change from “Forward” to “Left”  
and to reset \_counter to 0 on change value of oldText.

As usual, all help is so very much appreciated  
\<code\>  
private var oldText:String;  
private var \_counter:int=0;

public function onKeyDown(e:KeyboardEvent):void{  
switch(e.keyCode)  
{  
case 38:\_moveForward  
//If oldtext has changed reset \_counter= true;  
oldText = “Forward”;  
\_counter++;  
break;  
case 37: \_moveLeft = true;  
//If oldtext has changed reset \_counter to 0  
oldText = “Left”;  
\_counter++;  
break;  
}

public function changeEnterFrame (e:Event)  
{ if (oldText != textField.text)  
{ \_counter = 0}

stage.addEventListener(Event.ENTER\_FRAME, changeEnterFrame);

\</code\>
