Skip navigation
Currently Being Moderated

Altering Boolean states on external classes

Jun 12, 2012 5:59 PM

Tags: #3.0 #button #action #3 #code_snippets #actionscript #as3.0 #movieclip #ac3 #actionscript3 #actionscript_3.0

Hey guys, I have a question about Booleans and OOP.

 

Say I have 3 class, Class A, B and C.

Class C contains the boolean variable which will determine whether an option is in default of custom mode.

 

Class A controls the boolean state of Class C from detecting which buttons are inputted by the user.

 

Class B reads from Class C's boolean state to see whether it should generate a default answer or custom answer.

 

The problem I'm having is, after giving both Class A and B Class C's inheritence for the boolean, both A and B's inherited boolean seems to be a completely different set of boolean (When alterations are made on A, I assume A would alter the boolean state in C, thus returning the result to A as false, but B still thinks it's true).

 

Is there a reason for that? Or am I having the wrong programming logic here ?

 
Replies
  • kglad
    62,117 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 12, 2012 9:45 PM   in reply to BlazeRazgriz

    unless your boolean is a static variable or class C is a singleton, the reference to class C in A and the reference to class C in B are different so that boolean is different.

     

    to remedy, use a public static property (which both A and B would reference by using C.yourboolean) or make C a singleton class so both A and B reference the same class instance.

     
    |
    Mark as:
  • kglad
    62,117 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 13, 2012 6:05 AM   in reply to BlazeRazgriz

    you're welcome.

     

    p.s.  please mark helpful/correct responses, if there are any.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points