A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] trying to access variable...

  1. #1
    LukewarmSteak - Jordan Embury
    Join Date
    Jul 2009
    Location
    Toronto Ontario Canada
    Posts
    24

    resolved [RESOLVED] trying to access variable...

    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?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Use
    Code:
    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.

  3. #3
    LukewarmSteak - Jordan Embury
    Join Date
    Jul 2009
    Location
    Toronto Ontario Canada
    Posts
    24
    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

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center