# Class variable scope

**URL:** <https://forum.kirupa.com/t/class-variable-scope/190211>\
**Category:** flash\
**Created:** [June 9, 2006, 3:04pm UTC](https://forum.kirupa.com/t/class-variable-scope/190211 "2006-06-09T15:04:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balala](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@Balala](https://forum.kirupa.com/u/Balala)\
**Post date:** [June 9, 2006, 3:04pm UTC](https://forum.kirupa.com/t/class-variable-scope/190211/1 "2006-06-09T15:04:59Z")

</div>

Take a look at this code:

```auto
import mx.utils.Delegate;

class Test
{
  var secret:Number = 50;

  function Test(mc:MovieClip)
  {
    var i:Number;
    var new_mc:MovieClip;
    for(i = 0; i < 5; i++)
    {
      new_mc = mc.attachMovie("my_movie", "new_name" + i, mc.getNextHighestDepth(), {_x: i * 50});
      new_mc.i = i;
      new_mc.onRelease = Delegate.create(this, alert);
    }
  }

  function alert()
  {
    trace(this.i);
    trace(this.secret);
  }
}

```

Well… Doesnt work at all… In the class, there isnt a instance of **i** , so, how may i access this property inside a class function? But i still have an way to access the class.

I could do this way:

```auto
class Test
{
  function Test(mc:MovieClip)
  {
    var i:Number;
    var new_mc:MovieClip;
    for(i = 0; i < 5; i++)
    {
      new_mc = mc.attachMovie("my_movie", "new_name" + i, mc.getNextHighestDepth(), {_x: i * 50});
      new_mc.i = i;
      new_mc.class = this;
      new_mc.onRelease = function()
      {
        trace(this.i);
        this.class.alert();
      }
    }
  }

  function alert()
  {
    trace(this.secret);
  }
}

```

But this way, doesnt sounds good ☹

Any suggests?
