Professional Web Applications Themes

Case Statement - Macromedia Flash Actionscript

HI All, I use Macromedia Director and often use case statements so that I don't have to have a separate script for each button. An Example in Director: property pMember // sets pMember property on beginSprite me pMember=sprite(me.spriteNum).member end // Identifies the sprite object - similar to one item on a layer in Flash on mouseUp me case (pMember).name of "a": go to "start" // Identifies the button "a" and sends the user to frame label "start" "b": go to "end" // Identifies the button "b" and sends the user to frame label "end" otherwise nothing end case end I've ...

  1. #1

    Default Case Statement

    HI All,

    I use Macromedia Director and often use case statements
    so that I don't have to have a separate script for each button.
    An Example in Director:
    property pMember
    // sets pMember property

    on beginSprite me
    pMember=sprite(me.spriteNum).member
    end
    // Identifies the sprite object - similar to one item on a layer in Flash

    on mouseUp me
    case (pMember).name of
    "a":
    go to "start"
    // Identifies the button "a" and sends the user to frame label "start"
    "b":
    go to "end"
    // Identifies the button "b" and sends the user to frame label "end"
    otherwise
    nothing
    end case
    end

    I've searched diligently but haven't been able to find something similar in Flash.

    Thanks in advance for any help!

    Tim


    tsetliff webforumsuser@macromedia.com Guest

  2. #2

    Default Re: Case Statement

    in Flash <switch>

    switch ( Value ){
    case 0 : ....
    break;
    case 1 :.....

    --

    Pierre Alain

    [email]pielifnet.com[/email]


    "tsetliff" <webforumsusermacromedia.com> a écrit dans le message de
    news:bvrka4$8ns$1forums.macromedia.com...
    > HI All,
    >
    > I use Macromedia Director and often use case statements
    > so that I don't have to have a separate script for each button.
    > An Example in Director:
    > property pMember
    > // sets pMember property
    >
    > on beginSprite me
    > pMember=sprite(me.spriteNum).member
    > end
    > // Identifies the sprite object - similar to one item on a layer in Flash
    >
    > on mouseUp me
    > case (pMember).name of
    > "a":
    > go to "start"
    > // Identifies the button "a" and sends the user to frame label "start"
    > "b":
    > go to "end"
    > // Identifies the button "b" and sends the user to frame label "end"
    > otherwise
    > nothing
    > end case
    > end
    >
    > I've searched diligently but haven't been able to find something similar
    in Flash.
    >
    > Thanks in advance for any help!
    >
    > Tim
    >
    >

    PierreAlain Guest

  3. #3

    Default Re: Case Statement

    HI Pierre,

    I'm not sure how to use this. After case - you put "0" - is that the button
    name?
    do you put the action after that ":" where you put the "...."?
    What is the purpose of "break"?

    Thanks,
    T
    >
    > switch ( Value ){
    > case 0 : ....
    > break;
    > case 1 :.....
    >
    > --
    >
    > Pierre Alain
    >
    > [email]pielifnet.com[/email]
    >
    >
    > "tsetliff" <webforumsusermacromedia.com> a écrit dans le message de
    > news:bvrka4$8ns$1forums.macromedia.com...
    > > HI All,
    > >
    > > I use Macromedia Director and often use case statements
    > > so that I don't have to have a separate script for each button.
    > > An Example in Director:
    > > property pMember
    > > // sets pMember property
    > >
    > > on beginSprite me
    > > pMember=sprite(me.spriteNum).member
    > > end
    > > // Identifies the sprite object - similar to one item on a layer in
    Flash
    > >
    > > on mouseUp me
    > > case (pMember).name of
    > > "a":
    > > go to "start"
    > > // Identifies the button "a" and sends the user to frame label "start"
    > > "b":
    > > go to "end"
    > > // Identifies the button "b" and sends the user to frame label "end"
    > > otherwise
    > > nothing
    > > end case
    > > end
    > >
    > > I've searched diligently but haven't been able to find something similar
    > in Flash.
    > >
    > > Thanks in advance for any help!
    > >
    > > Tim
    > >
    > >
    >
    >

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.572 / Virus Database: 362 - Release Date: 1/27/2004


    Tim A. Setliff Guest

  4. #4

    Default Re: Case Statement

    hum, in fact I always used it with numeric value. Have to try with text.
    the <break;> is to make it jump to the end without testing other values.

    example (with numbers, you will have to try with chars :-)

    buttonNumber = pint( callingButton.substr( callingButton.lenght-2), 10);
    // lets suppose I received a call from a button sending its name, witch ends
    buy a number)

    switch ( ButtonNumber ){
    case 0 : trace( "my button 0 has called"); break;
    case 1 : trace( "my button 1 has called"); break;
    case 2 : trace( "my button 2 has called"); break;
    default : trace("I haven't set a call for " + ButtonNumber);
    }

    hope that helps

    --

    Pierre Alain

    [email]pielifnet.com[/email]


    "Tim A. Setliff" <tsetliffearthlink.net> a écrit dans le message de
    news:bvrupg$jl4$1forums.macromedia.com...
    > HI Pierre,
    >
    > I'm not sure how to use this. After case - you put "0" - is that the
    button
    > name?
    > do you put the action after that ":" where you put the "...."?
    > What is the purpose of "break"?
    >
    > Thanks,
    > T
    > >
    > > switch ( Value ){
    > > case 0 : ....
    > > break;
    > > case 1 :.....
    > >
    > > --
    > >
    > > Pierre Alain
    > >
    > > [email]pielifnet.com[/email]
    > >
    > >
    > > "tsetliff" <webforumsusermacromedia.com> a écrit dans le message de
    > > news:bvrka4$8ns$1forums.macromedia.com...
    > > > HI All,
    > > >
    > > > I use Macromedia Director and often use case statements
    > > > so that I don't have to have a separate script for each button.
    > > > An Example in Director:
    > > > property pMember
    > > > // sets pMember property
    > > >
    > > > on beginSprite me
    > > > pMember=sprite(me.spriteNum).member
    > > > end
    > > > // Identifies the sprite object - similar to one item on a layer in
    > Flash
    > > >
    > > > on mouseUp me
    > > > case (pMember).name of
    > > > "a":
    > > > go to "start"
    > > > // Identifies the button "a" and sends the user to frame label "start"
    > > > "b":
    > > > go to "end"
    > > > // Identifies the button "b" and sends the user to frame label "end"
    > > > otherwise
    > > > nothing
    > > > end case
    > > > end
    > > >
    > > > I've searched diligently but haven't been able to find something
    similar
    > > in Flash.
    > > >
    > > > Thanks in advance for any help!
    > > >
    > > > Tim
    > > >
    > > >
    > >
    > >
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    > Version: 6.0.572 / Virus Database: 362 - Release Date: 1/27/2004
    >
    >

    PierreAlain Guest

  5. #5

    Default Re: Case Statement

    > What is the purpose of "break"?

    Try reading the help files on the switch statement.

    It is all explained there with examples etc. It would help if people read
    the docs before asking questions about things that are already well
    doented. Grrr.


    Jeckyl Guest

  6. #6

    Default Re: Case Statement

    In response to the last post, since you've wasted the space with a rebuke that provided no useful information, I will respond. I did read the doentation, I was asking for a clarification since Lingo and Action Script are similar but quite different!

    Get a life and stop wasting everyone's time by trying to be a room monitor!




    tsetliff webforumsuser@macromedia.com Guest

  7. #7

    Default Re: Case Statement

    Hi Pierre,

    I am trying your code and not getting it to work.
    I copied and pasted the script into a frame.
    I labeled the buttons: 0,1,2.

    I don't have a clue as what to do now.

    Thanks again for the information!

    Tim


    tsetliff webforumsuser@macromedia.com Guest

  8. #8

    Default Re: Case Statement

    here is a function srite from one of my menu :
    ----------------------------------------
    function bouton_HT_numero(objet_in){

    var objet = string(objet_in);
    var L = objet.length;
    var Numero = 999;

    for ( var i=objet.length-1; i > 0; i-- ){
    var M = pInt(objet.substr(i,10));
    if ( M > -1 ) {
    Numero = M;
    }
    else
    {
    return Numero;
    }
    }

    return Numero;
    }

    //------------------------------------------------------------
    function bouton_HT_init(objet){

    var Numero = bouton_HT_numero(objet);

    switch ( Numero ){

    case 1 : objet.btn_init( "mon texte 1");
    break;


    case 2 : objet.btn_init( "et le texte 2");
    break;


    case 3 : objet.btn_init( "voilà le 3");
    break;

    default : // objet.btn_init( "");
    // juste pour les tests
    objet.btn_init( "bouton "+Numero);

    }
    }
    -----------------------------------

    my buttons instances are called <bouton1>, <bouton2>....<bouton919>;

    telle me if it is clearer like that. The <bouton_HT_init() is called from
    inside the button once instancied (last instruction) with this syntax :

    _root.bouton_HT_init(this);

    --

    Pierre Alain

    [email]pielifnet.com[/email]


    "tsetliff" <webforumsusermacromedia.com> a écrit dans le message de
    news:bvtdoc$c8s$1forums.macromedia.com...
    > Hi Pierre,
    >
    > I am trying your code and not getting it to work.
    > I copied and pasted the script into a frame.
    > I labeled the buttons: 0,1,2.
    >
    > I don't have a clue as what to do now.
    >
    > Thanks again for the information!
    >
    > Tim
    >
    >

    PierreAlain Guest

  9. #9

    Default Re: Case Statement

    What's the point of responding with information that is already right in
    front of your face if you simply look in the actionscript docs.

    Try helping your self rather than wanting to be spoon fed information. Its
    not that hard.
    > Get a life and stop wasting everyone's time by trying to be a room
    monitor!

    Stop wasting everyone else's time by asking questions that you already have
    answer for.


    Jeckyl Guest

  10. #10

    Default Re: Case Statement

    you said :
    > > Get a life and stop wasting everyone's time by trying to be a room
    > monitor!
    Sorry having tried to help some users. Seems that your field. bye

    --

    Pierre Alain

    [email]pielifnet.com[/email]


    "Jeckyl" <jeckylhyde.com> a écrit dans le message de
    news:bvug3e$o0$1forums.macromedia.com...
    > What's the point of responding with information that is already right in
    > front of your face if you simply look in the actionscript docs.
    >
    > Try helping your self rather than wanting to be spoon fed information.
    Its
    > not that hard.
    >
    > > Get a life and stop wasting everyone's time by trying to be a room
    > monitor!
    >
    > Stop wasting everyone else's time by asking questions that you already
    have
    > answer for.
    >
    >

    PierreAlain Guest

Similar Threads

  1. sql select case statement
    By Anderson11983 in forum Coldfusion Database Access
    Replies: 1
    Last Post: May 9th, 01:50 PM
  2. List in case statement
    By lingo smith in forum Macromedia Director Basics
    Replies: 2
    Last Post: April 17th, 02:05 AM
  3. #23026 [Com]: Make Zend case-sensitive (classes, functions, remove case-insensitive)
    By nvivo at mandic dot com dot br in forum PHP Development
    Replies: 0
    Last Post: October 19th, 12:17 PM
  4. Problems with CASE statement
    By Sean C. in forum IBM DB2
    Replies: 9
    Last Post: October 15th, 06:03 AM
  5. CASE statement and CONTAINS
    By steve in forum Macromedia Director Lingo
    Replies: 2
    Last Post: July 31st, 12:12 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139