Take a look at this code:
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:
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?