A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: global variables??????

  1. #1
    Hello All!

    Ok, I need help with a variable for controlling a button / Movie clip.

    Here is the movie I am working on...
    http://isaid.com/test/mmibt_main002.html

    If you take a look at the movie you will notice that when you roll over the button(s) the doors for the box on the page close and then when you click the button the doors open back up with new content.

    With that said here is my problem.

    If you roll ever the button but you do not click it and then you roll over the next button the doors close again.

    This is what I am trying to stop.

    Once the doors are closed I want them to remain closed until you click a button.

    This is the script I currently have on the button to open and close the doors.

    on (rollOver) {
    _root.mainDoors_in.gotoAndPlay(30);
    }
    on (press) {
    _root.mainDoors_in.gotoAndPlay(60);
    }

    Pretty straight forward.

    Now here is what I was playing with to try and set a variable to keep them closed.

    on (rollOver) {
    set (IsDoorClosed,True);
    if (IsDoorClosed==False)
    {
    _root.mainDoors_in.gotoAndPlay(30);
    IsDoorClosed=True;
    }
    }
    on (press) {
    if (IsDoorClosed==True)
    {
    _root.mainDoors_in.gotoAndPlay(120);
    IsDoorClosed=False;
    }
    }

    When this is in use the buttons do not function at all.

    plus I think this is wrong anyway as I believe it would be a local variable and I think need a global variable.

    I have limited knowledge of scripting so I hope I am at least on the right track.

    Can anyone help me in this dilemma??

    Much thanks!!!!

    Rick

  2. #2
    Junior Member
    Join Date
    Aug 2002
    Posts
    5
    The buttons aren't working because your "if" is not executing, you need to set the variable outside of the "rollover" action.
    You can define the variable in your movie's first frame and then you can access it from anywhere using "_root.isDoorClosed".
    Hope this helps.

  3. #3
    Senior Member
    Join Date
    Jul 2002
    Posts
    461
    you could define a variable on _root like _root.IsDoorClosed
    and all the buttons could refer to it as _root.IsDoorClosed.
    global variables can cause you problems sometimes but if
    you just have a few its not a problem.

    are you trying to do something like this:

    on (rollOver) {
    if ( _root.IsDoorClosed==False) {
    _root.mainDoors_in.gotoAndPlay(30); // close the doors
    _root.IsDoorClosed=True;
    }
    }

  4. #4
    Senior Member
    Join Date
    Apr 2001
    Location
    Candyland
    Posts
    423
    place your variable "IsDoorClosed" in the main timeline.
    Code:
    on (rollOver) {
     if (!_root.IsDoorClosed){
      _root.mainDoors_in.gotoAndPlay("closeDoor");
      _root.IsDoorClosed=true;
     }
    }
    on (press) {
     if (_root.IsDoorClosed) {
      _root.mainDoors_in.gotoAndPlay("openDoor");
      _root.IsDoorClosed=false;
     }
    }
    this should work.
    k.

  5. #5
    Junior Member
    Join Date
    Aug 2002
    Posts
    5
    Forgot to add that the "if" isn't working because it always evaluates to false, you need to either set the variable to false when the movie starts or change it in the if statement, something like:

    if (_root.isDoorClosed==true){
    gotoAndPlay(30);
    _root.isDoorClosed=false;
    }

  6. #6

    Thank You!!!!!!!!!!!!!!

    Thanks Much everyone!!!

    I got it now.

    Naz, when I tried to use if outside the rollover statement I got a script error, just thought I would let you know but thanks very much for posting and the same for you gaz.

    Kay, your code is what worked for me.

    One question, what is the purpose of the ! in front of _root on line 2?

    Like I said I am new to scripting and I am learning all on my own, from sites like this so I have to ask.

    Once again thanks everyone, I am glad I was at least getting close before I posted.

    Have a great weekend!

    Rick

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