Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : Case Statement


Tim A. Setliff
2/4/2004 6:25:21 PM
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
[quoted text, click to view]


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

tsetliff
2/4/2004 8:22:28 PM
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
2/4/2004 11:58:46 PM
in Flash <switch>

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

--

Pierre Alain

pie@lifnet.com


"tsetliff" <webforumsuser@macromedia.com> a écrit dans le message de
news:bvrka4$8ns$1@forums.macromedia.com...
[quoted text, click to view]

PierreAlain
2/5/2004 12:50:10 AM
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 = parseint( 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

pie@lifnet.com


"Tim A. Setliff" <tsetliff@earthlink.net> a écrit dans le message de
news:bvrupg$jl4$1@forums.macromedia.com...
[quoted text, click to view]

Jeckyl
2/5/2004 10:59:31 AM
[quoted text, click to view]

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
documented. Grrr.

tsetliff
2/5/2004 12:32:16 PM
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 documentation, 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
2/5/2004 12:42:53 PM
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
2/5/2004 7:55:19 PM
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 = parseInt(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

pie@lifnet.com


"tsetliff" <webforumsuser@macromedia.com> a écrit dans le message de
news:bvtdoc$c8s$1@forums.macromedia.com...
[quoted text, click to view]

PierreAlain
2/6/2004 12:26:00 AM
you said :

[quoted text, click to view]

Sorry having tried to help some users. Seems that your field. bye

--

Pierre Alain

pie@lifnet.com


"Jeckyl" <jeckyl@hyde.com> a écrit dans le message de
news:bvug3e$o0$1@forums.macromedia.com...
[quoted text, click to view]

Jeckyl
2/6/2004 9:26:24 AM
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.

[quoted text, click to view]
monitor!

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

AddThis Social Bookmark Button