9/11/2010 7:57:10 PM
Title:
Scope issue in Class - AS2
Hello, I'm having a scope issue with a button in my class. I've got a Header Class which draws and arranges a series of buttons. They're all dynamically assigned _key properties and when clicked they need to be able to trace this property.
What's the best way to trace their _key property when you rollOver the button?
Cheers,
class head extends MovieClip {
.....
.........
..............
var TL:MovieClip = timeline;
var hit:MovieClip = TL.attachMovieClip("button", "button", TL.getNextHighestDepth());
var hit._key = "hello"
hit.onRollOver = overEvent; // Delegate.create(this, overEvent);
//-------------------------------------------------------------------
// overEvent
//-------------------------------------------------------------------
private function overEvent():Void {
trace(this) // this traces the button instance when clicked as desired
trace(this._key) // causes error because the _key property has not yet been created yet and won't compile
}
9/11/2010 11:17:04 PM
instead of using this first declare the variable type then point "this" to that variable
//declare it to the class type that has _key property
var myClip:button ;
myClip=this;
trace(myClip._key)
9/13/2010 1:39:57 AM
if your _key variable is inside the clas you are accessing then you should be able to access it directly without using "this"
trace(_key)