;

PDA

Click to See Complete Forum and Search --> : [RESOLVED] trying to access variable...


LukewarmSteak
07-18-2009, 01:56 PM
hey! i'd like to access a variable in an associated class from my Document class

document class - (index)

package{
class index...{
public static var somevar:Boolean = false;
public function index....{

if (somevar !== false) {
trace (somevar);
}
}}}

other class - (otherclass)

package {
class otherclass...{
public static var somevar:Boolean;
public function otherclass {
somevar = true;
trace (somevar);
}}}


- in my document class im trying to see if the class has changed the variable... if it has changed i'd like to obviously do something... if this isn't possible what's the simplest way to check a variable in another class?

5TonsOfFlax
07-18-2009, 08:06 PM
Use

if (otherclass.somevar == false){
//...


Also, the somevar declared in the document class is completely separate from that declared in the other class. You probably only want the otherclass one.

LukewarmSteak
07-18-2009, 10:21 PM
the idea is that i don't want them seperate... i'm trying to be able to access the same variable in both classes... but obviously i'm a fricken noob -

i did try that once however i got some silly error... maybe i'll try it again! thanks 5tons

5TonsOfFlax
07-18-2009, 10:48 PM
Only declare in either otherclass or the document class. Use classname.somevar to access a static variable in a different class.

Declaring variables in two places results in two variables. Always. They may refer to the same object, of course. But in this case they don't.