jameskyle
08-21-2010, 05:25 PM
Hi. I'm making the jump to AS3 and working with classes and I'm having a little trouble understanding where I'm going wrong. I have a series of variables in my document class that I'd like to be able to access in other classes, though I'm not sure how I'd manage this, as no amount of experimenting with parent, root, Main, etc. seems to bring anything but compile errors. I'll show what I have so far:
document class "Main.as"
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public var healthSpending:Number = 1;
public function Main() {
}
}
}
Second class:
package {
import flash.display.MovieClip;
public class titleScreen extends MovieClip {
public function titleScreen() {
trace(healthSpending); // returns possibly undeclared variable error.
}
}
}
How would I access the variable healthSpending declared in the document class from within the second class?
document class "Main.as"
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public var healthSpending:Number = 1;
public function Main() {
}
}
}
Second class:
package {
import flash.display.MovieClip;
public class titleScreen extends MovieClip {
public function titleScreen() {
trace(healthSpending); // returns possibly undeclared variable error.
}
}
}
How would I access the variable healthSpending declared in the document class from within the second class?