onRelease twice on same button(simple)

  • meAsking
  • Beginner
  • Beginner
  • meAsking
  • Posts: 38

Post 3+ Months Ago

Dear list,
I'm confused about the logic here.
I'm trying to get a drawer to open and then close once clicked.

Code: [ Select ]
var outSide = 0;

dr1.onRelease = function() {
    if (outSide == 0) {
        slideOut();
        var outSide = 1;
    }else{
        slideIn();
        var outSide = 0;
    }
};
  1. var outSide = 0;
  2. dr1.onRelease = function() {
  3.     if (outSide == 0) {
  4.         slideOut();
  5.         var outSide = 1;
  6.     }else{
  7.         slideIn();
  8.         var outSide = 0;
  9.     }
  10. };


so the first time i click, the drawer slides out.
why doesn't it slide in when I click it again? because the way I see it, the second time i click, var outSide = 1 so shouldn't it go the "}else{" part of the loop?
I don't get it...

thanks,[/code]
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • meAsking
  • Beginner
  • Beginner
  • meAsking
  • Posts: 38

Post 3+ Months Ago

solved!!

I took out the "var" in my variables, beause it made "outSide" variable local when i needed it to be global.
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

very nice - sorry we couldn't get to your post to help in time, but
it's nice that you posted the resolution for us. Good work. :)
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

using var in your function indeed did make it local instead of "global" (it's technically not global as the correct timeline needs to be address, but as far as being addressed from inside or outside a function it is global), but another thing to keep in mind is that including var before the variable name re-defines the variable... which overwrites the already existing variable. Not exactly effeciant :)
  • meAsking
  • Beginner
  • Beginner
  • meAsking
  • Posts: 38

Post 3+ Months Ago

didn't know var is such a trouble maker.
good to know. thanks. :wink:
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

It's not exactly a trouble maker, you just gotta know when to use it correctly :)

When you create a variable using
Code: [ Select ]
var variableName = value
You can change the value of that variable just by using
Code: [ Select ]
variableName = value
By adding "var" to the beginning you will just be overwriting the current variable with a new one that contains a different value.

Some things useful to know with variables in ActionScript...

Var Declaration
Variable Scope

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 11 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.