A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: switch command is bad?

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    19

    switch command is bad? HELP!!

    Code:
    stop();
    
    trace (flag1value.getItemAt(0))
    var getvalue =(flag1value.getItemAt(0))
    switch(getvalue) {
    	
    case "active":
    
    this.createEmptyMovieClip("flag1holder", this.getNextHighestDepth());
    flag1holder.createEmptyMovieClip("flag1container",flag1holder.getNextHighestDepth());
    flag1holder.flag1container.attachMovie("BUTTflag1", "new_name", flag1holder.flag1container.getNextHighestDepth());
    flag1holder.flag1container._x=271.1;
    flag1holder.flag1container._y=152.9;
    flag1holder.flag1container.new_name.onRelease=function(){
    loadlang1.trigger();
    gotoAndPlay(23);
    }
    }
    break;
    
    trace (flag2value.getItemAt(0))
    var getvalue =(flag2value.getItemAt(0))
    switch(getvalue) {
    	
    case "active":
    
    this.createEmptyMovieClip("flag2holder", this.getNextHighestDepth());
    flag1holder.createEmptyMovieClip("flag2container",flag1holder.getNextHighestDepth());
    flag1holder.flag1container.attachMovie("BUTTflag2", "new_name", flag1holder.flag1container.getNextHighestDepth());
    flag1holder.flag1container._x=349.4;
    flag1holder.flag1container._y=152.9;
    flag1holder.flag1container.new_name.onRelease=function(){
    loadlang2.trigger();
    gotoAndPlay(23);
    }
    }
    break;
    yes, thinking about it, i was silly.

    what happening is i am tracing values from a list components, and if the value is "active" i want buttons created. Using the switch command though, its just running through the code and creating the last button, instead of all them.

    any ideas guys?!

    i can't tell you how much i love you flash gurus!!!

    TIA,
    James
    Last edited by jameskeane; 07-05-2006 at 08:17 AM.

  2. #2
    Senior Member
    Join Date
    Nov 2005
    Location
    Milan
    Posts
    119
    Your syntax is wrong: break should come after each item and the switch keyword should be declared only once. Plus you're always checking for "active"... not too sure what you're trying to achieve here.

    Anyway the correct syntax is:

    switch (condition) {
    case A :
    // statements
    break;
    case B :
    // statements
    break;
    case Z :
    // statements
    break;
    default :
    // statements
    break;
    }

  3. #3
    Junior Member
    Join Date
    May 2006
    Posts
    19
    Hi Carod, thanks for your response.

    a value of 'active' is being passed from an xml file via the xml connector for each language listed there to be activated for my application. so for each language that is 'active' i need a button loaded and positioned in a pre-defined location on the stage with a command to trigger another connector for different specific language file.

    the value doesn't have to be 'active' everytime, it could be active 1 for english, active 2 for spanish etc.. would this help my code?

    thanks,
    James

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    you dont need a switch statement just to check whether one condition is right or not..switch is usually used when testing mutilple conditions. In you case a simple 'if' statement should be fine:

    Code:
    stop();
    
    trace (flag1value.getItemAt(0));
    var getvalue =(flag1value.getItemAt(0));
    
    if(getvalue == "active"){
    this.createEmptyMovieClip("flag1holder", this.getNextHighestDepth());
    flag1holder.createEmptyMovieClip("flag1container",flag1holder.getNextHighestDepth());
    flag1holder.flag1container.attachMovie("BUTTflag1", "new_name", flag1holder.flag1container.getNextHighestDepth());  
    flag1holder.flag1container._x=271.1;
    flag1holder.flag1container._y=152.9;
    flag1holder.flag1container.new_name.onRelease=func  tion(){
    loadlang1.trigger();
    gotoAndPlay(23);
    }
    }
    trace (flag2value.getItemAt(0));
    var getvalue =(flag2value.getItemAt(0));
    
    
    if(getvalue == "active"){
    
    this.createEmptyMovieClip("flag2holder", this.getNextHighestDepth());
    flag1holder.createEmptyMovieClip("flag2container",flag1holder.getNextHighestDepth());
    flag1holder.flag1container.attachMovie("BUTTflag2", "new_name", flag1holder.flag1container.getNextHighestDepth());  
    flag1holder.flag1container._x=349.4;
    flag1holder.flag1container._y=152.9;
    flag1holder.flag1container.new_name.onRelease=func  tion(){
    loadlang2.trigger();
    gotoAndPlay(23);
    }
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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