# Class variables in on functions?

**URL:** <https://forum.kirupa.com/t/class-variables-in-on-functions/208672>\
**Category:** flash\
**Created:** [December 1, 2006, 3:31am UTC](https://forum.kirupa.com/t/class-variables-in-on-functions/208672 "2006-12-01T03:31:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torq](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/torq/32/2378_2.png) [@Torq](https://forum.kirupa.com/u/Torq)\
**Post date:** [December 1, 2006, 3:31am UTC](https://forum.kirupa.com/t/class-variables-in-on-functions/208672/1 "2006-12-01T03:31:22Z")

</div>

Hey, I was wondering if they found a better way of allowing the use of variables outside of an on function. For example in the script below I can use the variable bounds inside the target.onEnterFrame function because it’s declared inside the constructer. However I can’t use m\_Bounds even though it’s declared in the class.

[AS] private var m\_mcTarget:MovieClip;  
private var m\_Bounds:BoundsData;

```
function MotionHandler(target:MovieClip, bounds:BoundsData)
{
    m_mcTarget = target;
    m_Bounds = bounds;
    
    m_mcTarget.onEnterFrame = function()
    {
        this._x = bounds.current.x;
        this._y = bounds.current.y;
    }
    
}[/AS]

```

I find it annoying and unorganized to redeclare variables from my own class just to use them in the onClick/onRelease/onEnterFrame etc.

If I were to move that onEnterFrame to a different function, I would have to provide a copy of the bounds var inside that function.

[AS] private var m\_mcTarget:MovieClip;  
private var m\_Bounds:BoundsData;

```
function MotionHandler(target:MovieClip, bounds:BoundsData)
{
    m_mcTarget = target;
    m_Bounds = bounds;
}

public function Initialize():Void
{
    var bounds:BoundsData = m_Bounds;
    
    m_mcTarget.onEnterFrame = function()
    {
        this._x = bounds.current.x;
        this._y = bounds.current.y;
    }
}[/AS]

```

In AS3.0 will they let us use class variables in on functions or are there any other methods?
