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:
    toggle=1;
    toggle=1+(toggle==1);

    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.)

    Phillip

  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(foo);
    //true
    trace(fooObj);
    //true

    trace(“typeof foo:” + typeof foo);
    //boolean
    trace(“foo.valueOf():” + foo.valueOf());
    //fooObj.valueOf():true
    trace(“foo.toString():” + foo.toString());
    //foo.toString():true

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

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

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

    fooObj = new Boolean(false);

    trace(“if(fooObj)”);
    if(fooObj)
    {
    trace(“fooObj:” + fooObj)
    } else {
    trace(“fooObjFalse:” + fooObj)
    }
    //fooObj:false

    trace(“if(fooObj.valueOf())”);
    if(fooObj.valueOf())
    {
    trace(“fooObj:” + fooObj)
    } else {
    trace(“fooObjFalse:” + fooObj)
    }
    //fooObjFalse:false

  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.

    Phillip

Comments are closed.