A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: checking array in switch statement

  1. #1
    Senior Member
    Join Date
    Nov 2004
    Location
    Amsterdam
    Posts
    212

    checking array in switch statement

    hi,

    how can I check the content of an array with a switch statement?

    Code:
    var array :Array =[0,0];
    switch (array) {
    									
    		    case [0,0]:
    		        trace("yes sir");
    		      break;
    								    
    		   default:
    		 trace("No sir");
    		}
    This one isn't working,

    thanks!

    Jerryjj.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Switch uses strict equality (===) so "array" and [0,0] are equal but not identical...consider:

    PHP Code:
    var a:Array = [10];
    var 
    b:Array = [01];

    function 
    test(arr:Array):String{    
        switch(
    arr){
            case 
    a:
                return 
    'a';
                break;
            case 
    b:
                return 
    'b';
                break;
            
        }
        
        return 
    'null';
    }

    trace(test(a));            //  a
    trace(test(b));            //  b
    trace(test([1,0]));        //  null 

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