PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
case statement using < && >=
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: case statement using < && >=

  1. #1

    Question case statement using < && >=

    Ok. Thought I knew how to use case statements, but apparently I don't -- or at least, I don't know how to use comparisons. The script checker keeps throwing me "invalid XML name" errors, which I have never seen before.

    I have the microphone's level, which is a range of 0-100 saved a numerical variable called "micActivity". I have 10 frames corresponding to the different activity levels.

    Rather than using math to change the 0-100 range to the 0-10 range I want, I thought I'd make some case statements. Thing is: I'm doin' it wrong.

    switch (micActivity) {
    case <=9 :
    openess = 1
    break;
    case >9 && <=19 :
    openess = 2;
    break;
    case >19 && <=29 :
    openess = 3;
    break;
    case >29 && <=39 :
    openess = 4;
    break;
    case >39 && <=49 :
    openess = 5;
    break;
    case >49 && <=59 :
    openess = 6;
    break;
    case >59 && <=69 :
    openess = 7;
    break;
    case >69 && <=79 :
    openess = 8;
    break;
    case >79 && <=89 :
    openess = 9;
    break;
    case >89 && <=99 :
    openess = 10;
    break;

    }

  2. #2
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    If will fit this situation much better. Even better still, would be an else if.


    switches are more for the following (just a quick example):
    Actionscript Code:
    public static const EVENT_PICKUPPHONE:int = 0;
    public static const EVENT_LISTEN:int = 1;
    public static const EVENT_PRESSNUMBERS:int = 2;
    public static const EVENT_HANGUP:int = 3;

    public function asyncPhoneCall(e:Event):void{
        //lets say that the target of the event has one of the above static values set to a variable 'Phone';
        switch(e.currentTarget.Phone){
            case EVENT_PICKUPPHONE:
                PickUp();
                break;
            case EVENT_LISTEN:
                ListenForWords();
                break;
            case EVENT_PRESSNUMBERS:
                PressNumbers(5,5,5,1,2,3,4);
                break;
            case EVENT_HANGUP:
                HangUp();
                break;
            default:
                trace('Phone Event Not Found: ' + e.currentTarget.Phone );
                e.currentTarget.Phone=-1;
        }
        e.currentTarget.Phone++;
    }


    Now in your case this would be better than a switch:

    Actionscript Code:
    function findOpeness(mic):int{
        if(mic>89)
            return 10;
        else if(mic>79)
            return 9;
        else if(mic>69)
            return 8;
        else if(mic>59)
            return 7;
        else if(mic>49)
            return 6;
        else if(mic>39)
            return 5;
        else if(mic>29)
            return 4;
        else if(mic>19)
            return 3;
        else if(mic>9)
            return 2;
        else
            return 1;
    }

    Or Even Better:

    Actionscript Code:
    function findOpeness(mic):int{
        return Math.floor(mic/10);
    }

    Hope that helps,
    -GK>'.'<
    Last edited by guardiankitty; 01-05-2012 at 09:43 PM.

  3. #3
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    i use this sometimes:

    Actionscript Code:
    switch (true) {
        case micActiity > 90:
            trace ("10");
            break;
        case micActiity > 80:
            trace ("9");
            break;
        case micActiity > 70:
            trace ("8");
            break;
    }
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


Tags for this Thread

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