if ( anObject ) then do stuff

Manager taught me something today about Flash while I was bitching how Flash didn’t support overloading of functions.

6 Replies to “if ( anObject ) then do stuff”

  1. In typed languages statements like that must be boolean (you will get a compile time error checking on a non-boolean) in the world of flash it does its own thing. I try to never use if(something) becuase it opens up an unreadable, buggy, can o’ worms :)

  2. That’s funny because when teaching I always show ==true because I think people understand it easier (even though I have to explain double-equals). Anyway, this isn’t 100% new to me, but I still may revert to being clearer when programming.

    The thing is, if you’re the one who created and populated the variable… if you know that it’ll be true or false (not new Boolean() or whatever), then I don’t think it would matter practically.

    Here’s another sort of thing I use all the time–probably some reason I shouldn’t:

    That simply makes toggle go from 1 to 2 and back.

    Basically, when used in an mathematical expression, true evaluates as 1 and false as 0.

    Am I a bad boy? (Not “bad boy” like you say down in Atlanta… but bad boy, like not good.)


  3. Be carefull what you ask for…
    if you make it an object … it’s an object

    there’s also something as a “bare” type as in boolean

    foo = true;
    fooObj = new Boolean(true);


    trace(“typeof foo:” + typeof foo);
    trace(“foo.valueOf():” + foo.valueOf());
    trace(“foo.toString():” + foo.toString());

    trace(“typeof fooObj:” + typeof fooObj);

    trace(“fooObj.valueOf():” + fooObj.valueOf());
    trace(“fooObj.toString():” + fooObj.toString());

    foo = false;
    trace(“foo:” + foo)
    } else {
    trace(“FooFalse:” + foo)

    fooObj = new Boolean(false);

    trace(“fooObj:” + fooObj)
    } else {
    trace(“fooObjFalse:” + fooObj)

    trace(“fooObj:” + fooObj)
    } else {
    trace(“fooObjFalse:” + fooObj)

  4. Actually Phillip, I did this, taken from my Director daze:
    <pre>toggle = !toggle</pre>
    Since you could say “not” in Director, you just replace that with a bizz-ang symbol.

  5. it=!it is different than my toggle which went between 1 and 2.


Comments are closed.