# How do i declare variables et c only ONCE in function?

**URL:** <https://forum.kirupa.com/t/how-do-i-declare-variables-et-c-only-once-in-function/222043>\
**Category:** flash\
**Created:** [April 10, 2007, 12:05pm UTC](https://forum.kirupa.com/t/how-do-i-declare-variables-et-c-only-once-in-function/222043 "2007-04-10T12:05:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [April 10, 2007, 12:05pm UTC](https://forum.kirupa.com/t/how-do-i-declare-variables-et-c-only-once-in-function/222043/1 "2007-04-10T12:05:07Z")

</div>

Hi. I have a problem with functions and variables… i need a kind of help with how to get functions that i use every onEnterFrame.  
et c:  
A MC is using this:  
ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#0000ff]onClipEvent[/COLOR] COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]\_root[/COLOR].[COLOR=#000080]randomWalk[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]

and this is the functions it calls:  
ActionScript Code:  
[FONT=Courier New][LEFT]randomWalk = [COLOR=#000000] **function** [/COLOR] COLOR=#000000[/COLOR]  
[COLOR=#000000]{[/COLOR]  
tXH = [COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_x[/COLOR] + [COLOR=#000080]15[/COLOR];  
tXL = [COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_x[/COLOR] - [COLOR=#000080]15[/COLOR];  
tYH = [COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_y[/COLOR] + [COLOR=#000080]15[/COLOR];  
tYL = [COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_y[/COLOR] - [COLOR=#000080]15[/COLOR];  
rwX = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]round[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]random[/COLOR] COLOR=#000000[/COLOR] \* [COLOR=#000000]([/COLOR]tXH - tXL[COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR] + tXL;  
rwY = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]round[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]random[/COLOR] COLOR=#000000[/COLOR] \* [COLOR=#000000]([/COLOR]tYH - tYL[COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR] + tYL;  
[COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_x[/COLOR] += [COLOR=#000000]([/COLOR][COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_x[/COLOR] - rwX[COLOR=#000000])[/COLOR] / [COLOR=#000080]100[/COLOR];  
[COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_y[/COLOR] += [COLOR=#000000]([/COLOR][COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]\_y[/COLOR] - rwY[COLOR=#000000])[/COLOR] / [COLOR=#000080]100[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[/LEFT]  
[/FONT]

As you can see it gets new variables onEnterFrame… How do i get around this?
