Reputation: 410
i try to set value for my two variables in my Class. But flash throw me exception - 'Access of undefined property myFirstText'
and 'Access of undefined property mySecondText'
. Where is my STUPID mistake?
My class:
package eu.gabrielatanasov.myclasses {
public class myClass {
private var myFirstText: String;
private var mySecondText: String;
public function myClass() {
trace('Class loaded!');
}
public static function getMyText($myFirstText: String, $mySecondText: String): void {
myFirstText = $myFirstText;
mySecondText = $mySecondText;
}
private static function justTrace(): void {
trace('My first text: ' + myFirstText + '\n' + 'My second text: ' + mySecondText);
}
}
}
Upvotes: 1
Views: 158
Reputation: 4665
Your instance variables cannot be set from a class (static) function. That's why you are getting the error.
If you want to set your variables with a static function, those variables have to be static as well. Remember the static functions do not have access to 'this' inside of the function and you are setting:
this.myFirstText = $myFirstText; //this: because they are instance variables; there is no this in a static function, error
Upvotes: 1