# Applying variables only once?

**URL:** <https://forum.kirupa.com/t/applying-variables-only-once/221970>\
**Category:** Uncategorized\
**Created:** [April 9, 2007, 7:22pm UTC](https://forum.kirupa.com/t/applying-variables-only-once/221970 "2007-04-09T19:22:08Z")\
**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 9, 2007, 7:22pm UTC](https://forum.kirupa.com/t/applying-variables-only-once/221970/1 "2007-04-09T19:22:08Z")

</div>

Hi, is there a way to apply variables only once?  
Like in an MC when you can use Load to give it variables et c. Can you use anything like this for an function?

I have this problem:  
[AS]  
ai\_foe = function (target)  
{  
if (target.action == undefined)  
{  
target.action = “idle”;  
}  
if (target.hitTest (\_root.char))  
{  
target.action = “attack”;  
}  
switch (target.action)  
{  
case “idle” :  
target.gotoAndPlay (target.action);  
break;  
case “attack” :  
target.gotoAndPlay (target.action);  
break;  
case “dead” :  
target.gotoAndPlay (target.action);  
break;  
}  
};  
[/AS]  
The problem is that the target MC is going to freeze at the first frame of “action”, since this is loaded every onEnterFrame.  
How do i get around this?
