When you do
public function showLogin():void {
var helpWindow:EditStudentLogInForm = ...
}
you're declaring and instantiating a new variable helpWindow
inside the scope of the showLogin
method. This means that the instance you assigned to this locally scoped variable can not be accessed outside the showLogin
method.
You did declare another variable helpWindow
on the class scope (your class being the main application in this case), but you're never assigning any instance to it (since you're assigning this popup instance to the helpWindow
variable that lives only in showLogin
.
Hence when you try to access this variable in another method, it's value is null
.
The solution is simple enough: just assign the popup instance to the class-scoped variable:
public function showLogin():void {
helpWindow = EditStudentLogInForm(
PopUpManager.createPopUp(this, EditStudentLogInForm, true)
);
...
}
On a side note: if you have a variable of the same name on the class and inside a method, the most locally scoped one always takes precedence:
public var s:String = 'class';
public function myMethod():void {
var s:String = 'method';
trace(s); // prints method
trace(this.s); // prints class
}
public function myOtherMethod():void {
trace(s); // prints class
trace(this.s); // prints class
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…