Thanx for ur reply. But I dont have only a single button their, there could be more than that. Then in that case I want to call a funtion and pass a parameter to it based on the button pressed.
If I have to wirte instancename with _name then does it make sense of using it? What u say?
I hope u understand what i am trying to say :sure:
The scope of the static on(release) handler is the parent of the instance it was assigned to. Therefore, if you have:
on(release){
trace(this._name);
}
Then this will refer to the parent of the instance this was placed on. So if your button is on the main timeline, this will refer to the main timeline (_root), and not the button itself. Because _root’s _name is set to nothing by default, you get a blank trace.
As Ubik said, to fix this you need to use
on(release){
trace(instance_name._name);
}
Where instance_name is the instance name of your instance. So say your button has the instance name ‘foo’, then you’d use this:
on(release){
trace(foo._name);
}
This is actually the same as:
on(release){
trace(this.foo._name);
}
But you can omit the this, unless really needed. This code is pretty useless though, because you need to go look at the instance name anyway, so it’s no use to first target foo, and then ask for it’s name, which is obviously foo too. You’d rather want to use dynamic event handlers instead:
foo.onRelease = function(){
trace(this._name);
}
In dynamic event handlers, this does reference the instance, because it’s a method of the instance.