Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




"Switch/Case" Syntax With Simultaneous Keypress



Hi, may I submit you this question:


Code:

function stageKey() {
//press "left"
if (Key.getCode() == 37) {
trace("left");
}
//hold "q" while pressing left
if (Key.isDown(81) && Key.getCode() == 37) {
trace("q+left");
}
}
var keyListener:Object = new Object();
keyListener.onKeyDown = stageKey;
Key.addListener(keyListener);
If I press "left"..OK it displays "left"

If I hold "q" then press "left" it will display "left" PLUS "q+left"



1) What to do to have it verify the second condition only ("q+left"), in other terms when both keys are pressed only have "q+left" displayed, without each seperate key more.

2) What would be the syntax using switch/case when there's a cunjonction of key pressed?



FlashKit > Flash Help > Flash ActionScript
Posted on: 07-14-2006, 02:52 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

"Switch/Case" Syntax With Simultaneous Keypress
Hi, may I submit you this question:


Code:

function stageKey() {
//press "left"
if (Key.getCode() == 37) {
trace("left");
}
//hold "q" while pressing left
if (Key.isDown(81) && Key.getCode() == 37) {
trace("q+left");
}
}
var keyListener:Object = new Object();
keyListener.onKeyDown = stageKey;
Key.addListener(keyListener);
If I press "left"..OK it displays "left"

If I hold "q" then press "left" it will display "left" PLUS "q+left"



1) What to do to have it verify the second condition only ("q+left"), in other terms when both keys are pressed only have "q+left" displayed, without each seperate key more.

2) What would be the syntax using switch/case when there's a cunjonction of key pressed?

"Switch/Case" Syntax With Simultaneous Keypress
Hi, may I submit you this question:

Code:
function stageKey() {
//press "left"
if (Key.getCode() == 37) {
trace("left");
}
//hold "q" while pressing left
if (Key.isDown(81) && Key.getCode() == 37) {
trace("q+left");
}
}
var keyListener:Object = new Object();
keyListener.onKeyDown = stageKey;
Key.addListener(keyListener);
If I press "left"..OK it displays "left"
If I hold "q" then press "left" it will display "left" PLUS "q+left"

1) What to do to have it verify the second condition only ("q+left"), in other terms when both keys are pressed only have "q+left" displayed, without each seperate key more.
2) What would be the syntax using switch/case when there's a cunjonction of key pressed?

"Switch/Case" Syntax With Simultaneous Keypress
Hi, may I submit you this question:


Code:

function stageKey() {
//press "left"
if (Key.getCode() == 37) {
trace("left");
}
//hold "q" while pressing left
if (Key.isDown(81) && Key.getCode() == 37) {
trace("q+left");
}
}
var keyListener:Object = new Object();
keyListener.onKeyDown = stageKey;
Key.addListener(keyListener);
If I press "left"..OK it displays "left"

If I hold "q" then press "left" it will display "left" PLUS "q+left"



1) What to do to have it verify the second condition only ("q+left"), in other terms when both keys are pressed only have "q+left" displayed, without each seperate key more.

2) What would be the syntax using switch/case when there's a cunjonction of key pressed?

"Switch/Case" Syntax With Simultaneous Keypress
Hi, may I submit you this question:


Code:

function stageKey() {
//press "left"
if (Key.getCode() == 37) {
trace("left");
}
//hold "q" while pressing left
if (Key.isDown(81) && Key.getCode() == 37) {
trace("q+left");
}
}
var keyListener:Object = new Object();
keyListener.onKeyDown = stageKey;
Key.addListener(keyListener);
If I press "left"..OK it displays "left"

If I hold "q" then press "left" it will display "left" PLUS "q+left"



1) What to do to have it verify the second condition only ("q+left"), in other terms when both keys are pressed only have "q+left" displayed, without each seperate key more.

2) What would be the syntax using switch/case when there's a cunjonction of key pressed?

"Switch/Case" Syntax With Simultaneous Keypress
Hi, may I submit you this question:

Code:


function stageKey() {
//press "left"
if (Key.getCode() == 37) {
  trace("left");
}
//hold "q" while pressing left
if (Key.isDown(81) && Key.getCode() == 37) {
  trace("q+left");
}
}
var keyListener:Object = new Object();
keyListener.onKeyDown = stageKey;
Key.addListener(keyListener);


If I press "left"..OK it displays "left"

If I hold "q" then press "left" it will display "left" PLUS "q+left"



1) What to do to have it verify the second condition only ("q+left"), in other terms when both keys are pressed only have "q+left" displayed, without each seperate key more.

2) What would be the syntax using switch/case when there's a cunjonction of key pressed?

Case/switch Help
I have this code which populates a "question" textbox and 2 "answer" textboxes (dependent of the question) and I need to set up a way to get the text in the question textbox, compare it to each of the answers, and from there determine which textbox has the right answer.

Here's what I have so far.
code:
stop();
//
qs = new Array();
qs[0] = [["What is 3+5?"], ["8"], ["12"]];
qs[1] = [["What is 4-5?"], ["-1"], ["9"]];
qs[2] = [["What is 6x5?"], ["30"], ["25"]];
qs[3] = [["What is 15+5?"], ["20"], ["10"]];
ran = Math.round(Math.random()*4)
for (i=0; i<4; i++) {
_root.question.text = qs[ran][0];
_root.answer1.text = qs[ran][1];
_root.answer2.text = qs[ran][2];
_root.q = qs[ran][0]
}


On a button next to the answers, I have this code:
code:
onClipEvent (load) {
this.answerkey = _root.answer1.text;
if (this.answerkey == _root.correctAns) {
this.hasAnswer = true;
} else {
this.hasAnswer = false;
}
onRelease();
}
on (release) {
if (this.hasAnswer) {
trace("Correct Answer Here");
} else {
trace("Not the correct Answer");
}
}

So here's the dilemma. I think a case/switch would be best here, something like this..
code: switch(_root.q){
case "What is 3+5?":
_root.correctAns="8";
break;
}
..for each of the questions. I can't get it to work though.

If there is a better way, please let me know. This is pretty important, so please help a brutha out.

A Switch Case
does it work:

<code>
switch (x) {
case "a","e","i","o","u": trace("vowel"); break;
case "0","1" : trace("binary"); break;
default : trace("other")
}
</code>

or do i have to do this:

<code>
switch (x) {
case "a" : trace("vowel"); break;
case "e" : trace("vowel"); break;
...
case "0" : trace("binary");
case "1" : trace("binary");
default : trace("other");
</code>

Thanx for help

If/while/case/switch?
I'm going nuts.

I have two buttons (which I've also made movie clips and used invisible buttons) with two states, an on state and an off.

What I want to do is:

OnRollOver, the "on" state shows (like a typical rollOver), on rollOut, it resorts to the "off" state. Upon clicking, load a text file into a dyn text box and set the other buttons' state to "off."

That's easy enough.

But, using an onRollOut to revert to an "off" stage shouldn't turn off the button that was just set to 'on' because it was clicked.

So, I just know some conditional loop could be used.

"If the button is already on, don't set it to off when rolling out."

The logic being that the on state is set upon clicking.

Any ideas?

Switch (this) - Case (that)... Some Help. :)
I came up with this code while trying some obvious ones,
to make all buttons disappear when one of them is clicked,
and at the same time, one other of each appear.


Home1.onPress = function(){
Home1._visible = false;
Home2._visible = true;
Home2.play()
switch (Empresa2._visible = false) {
case condition : Empresa2._visible = true
}
switch (Clientes2._visible = false) {
case condition : Clientes2._visible = true
}
switch (Forne2._visible = false) {
case condition : Forne2._visible = true
}

}

Now i would like to know if there is a away to put all those
- ._visible = false - conditions, in one "switch" sentence, then all those
- _visible = true - conditions in one "case".

Is there a possibility? or i am dreaming.

Switch - Case
im using a switch / case statement to choose from a list of images, it works great until i added more than 18, then for some reason the whole thing does not work. i would attach the .as file but its over 1400 lines long. does anyone have experience with switch - case that can give me a little deeper understanding? most of the code in the case statements look like this:

case 1:
mSlideContainer.mClip.hot.onRelease = function()
{
this.enabled = false;
this._alpha = 15;
mSlideContainer.mPopOut1._visible = true;

for (var k:Number = 0; k <$parsedObject.image[_global.num1].thumb.length; k++ )
{
mSlideContainer.mPopOut1["mc" + k]._visible = false;
}

TweenLite.to(mSlideContainer.mPopOut1.mc0, .4, { autoAlpha:99 } );

mSlideContainer.attachMovie("btn_rainbow1", "btn1", mSlideContainer.getNextHighestDepth() + 3, { _x:965, _y:560 } );
mSlideContainer.attachMovie("btn_rainbow2", "btn2", mSlideContainer.getNextHighestDepth() + 4, { _x:995, _y:560 } );
mSlideContainer.btn1._alpha = mSlideContainer.btn2._alpha = 75;

mSlideContainer.btn1.onRelease = function()
{
for (var k:Number = 0; k <$parsedObject.image[_global.num1].thumb.length; k++ )
{
TweenLite.to(mSlideContainer.mPopOut1["mc" + k], .4, { autoAlpha:0 } );
}
TweenLite.to(mSlideContainer.mPopOut1.mc0, .4, { autoAlpha:99 } );
mSlideContainer.mPopOut1.Text1.text = $parsedObject.image[_global.num1].thumb[0].TTXT;
mSlideContainer.mPopOut1.Text2.text = $parsedObject.image[_global.num1].thumb[0].col;
};

mSlideContainer.btn2.onRelease = function()
{
for (var k:Number = 0; k <$parsedObject.image[_global.num1].thumb.length; k++ )
{
TweenLite.to(mSlideContainer.mPopOut1["mc" + k], .4, { autoAlpha:0 } );
}
TweenLite.to(mSlideContainer.mPopOut1.mc1, .4, { autoAlpha:99 } );
mSlideContainer.mPopOut1.Text1.text = $parsedObject.image[_global.num1].thumb[1].TTXT;
mSlideContainer.mPopOut1.Text2.text = $parsedObject.image[_global.num1].thumb[1].col;
};

mSlideContainer.btn1.onRollOver = mSlideContainer.btn2.onRollOver = function()
{
this._alpha = 99;
};

mSlideContainer.btn1.onRollOut = mSlideContainer.btn2.onRollOver = function()
{
this._alpha = 75;
};
};
break;

[switch Case ?]
Hi,

is it posible to do a switch case in as ? i tried but it's not working

switch(var){
case "value" :
break;
case "othervalue" :
break
}

i wouldn't know how to do this different, now i cover it with if statements but a switch would be less code :-)

thanks
Galo

How To Do A Case Or Switch?
Is there a way to do a case or switch in acition script? If so, any example is apprciated.

Switch - Case
I need the switch case to recognize a reage of numbers e.g. 153 - 155. Is there a way of doing this?

Switch/case Help
I'm making a countdown timer, and I want different events to be triggered at different stages of the time. I'm using getTimer to calculate how long is left to an arbitrary finishtime.

The problem I am having is I am trying to use the switch/case command to trigger the events. All that happens, even when elapsedTime goes beyond the required time, is that it goes the default clause. Any idea how I can use ranges of numbers within the case clauses?

_root.onEnterFrame = function() {
currentTime = getTimer();
elapsedTime = Math.round((finishTime - currentTime)/1000);
switch (elapsedTime) {
case elapsedTime<=0 :
trace("finished");
case elapsedTime<=10 :
trace("10 seconds to go")
case elapsedTime<=60 :
trace("less than one minute");
default:
trace("long way to go yet")
}
countdownTime.text = Math.floor(elapsedTime/60) + ":" + elapsedTime%60;
}

Help With Switch Case
Hello..

Okay here I just having problem with passing the parameter to the switch () case..
Okay I pass the parameter from my combobox...
okay here my code so far ..really need help with this...what's wrong with my code..


ActionScript Code:
function fontType(j){//okay her when I trace j is show correct..but when it pass to the switch case its getting weird...it still detect "deafult"    //trace(j);    switch (j) {      case 1:            trace ("case 1 tested true");            break;      case 2:            trace ("case 2 tested true");            break;      case 3:            trace ("case 3 tested true");            break;      default:            trace ("no case tested true")    }}


any help would be appreaciate...tq

Switch Case
can you use ranges in a switch statement

eg,

case 1 to 5:
case 20 to 30:

or even

case 1 or 2:

cheers

John

Switch&case
Hello... somebody know what's wrong? Only use default value .-(


Code:
userClass = _root.userClass; //This is my class (7)

function msgGO(userClass:Number):Void
{
switch(userClass)
{
case 1:
socket.send("<b>["+userName+"]</b> "+uzenet.text);
break;
case 2:
socket.send("<b>["+userName+"]</b> "+uzenet.text);
break;
case 3:
socket.send("<b><font color="#FF6600">["+userName+"]</b></font> "+uzenet.text);
break;
case 4:
socket.send("<b>["+userName+"]</b> "+uzenet.text);
break;
case 5:
socket.send("<b><font color="#3399FF">["+userName+"]</b></font> "+uzenet.text);
break;
case 6:
socket.send("<b>["+userName+"]</b> "+uzenet.text);
break;
case 7:
socket.send("<b><font color="#FFFFFF">["+userName+"]</b></font> "+uzenet.text);
break;
default:
socket.send("<b>["+userName+"]</b>"+userClass+" "+uzenet.text);
}
uzenet.text = '';
}

Key.removeListener(this);
this.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
msgGO(userClass);
}
};
Key.addListener(this);
Thanks

Switch Oder Case
is the in actionscript something like a "switch" statement like there is in C++ or Java????

[F8] Switch/Case & GetCode()
So instead of using eight different if(Key.isDown(Key.Foo)) statements for movement of a clip, I thought using a switch/case statement would work better.


Code:
mc.onEnterFrame = function()
{
switch(Key.getCode() )
{
case Key.UP: this._x+=10;break;
ect. ect. ect.
}
}
The problem is that the code keeps executing even after the key is up, thus the movieclip keeps moving, and substituting Key.isDown() in the switch statement does nothing.

I think the problem stems from me not understanding under what conditions the function executes, but I can't be sure. Thanks you for your time.

-Halcyon

Switch Case Statements? Is There Something Better?
I don't really need help, just advice. (and if I am totally way off course than some redirection with examples )

I am working on a script that has 5 buttons. The script simply detects what webpage you are currently on and places the flash button into the down position.

I am currently utilizing a switch case statement for this. In AS3, is there something better to use?

Does the object I am using make sense or should I be storing the FlashVar in something else?


Code:
function wpdetect() {
var webpages:Array = ["home.php","about.php","services.php","specials.php","contact.php"];
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
switch(webpages[paramObj]) {
case "home.php":
//home button in down position here
trace("User is on the home page");
break;

case "about.php":
//about button in down position here
trace("User is on the about page");
break;

case "services.php":
//services button in down position here
trace("User is on the services page");
break;

case "specials.php":
//specials button in down position here
trace("User is on the specials page");
break;

case "contact.php":
//contact button in down position here
trace("User is on the contact page");
break;

case "fadingbutton.html":
//contact button in down position here
trace("We are practicing");
break;

default:
trace("Webpage not found. Update Case Statement.");
break;
}
}


Any advice would be great.

Thanks,

Wayne

[CS3] {as2} Help With Switch/case Statement
Hi my name is Freddy and I'm new to the forum , Nice to meet everybody )
I am a newbie but I figured the question would fit better in the AS section, hope I was right.. )

I have some Movie clips which I would like to include in a switch/case statement..
but I'm not sure how those work. perhaps I should use a if/else statement ?
basically I need the movie clips to fade away or disappear when I click a button and fade back in when the same button is clicked again. which statement is better for this ?

P.S
if some one knows of better idea than
//._alpha = 0 // for a fade/disappear code that would be super !

thanks in advance

F

Switch Case Trouble
Hello, I'm very new to ActionScript and I'm teaching myself a bit of the funtionality. At the minute I'm trying to create a clock program that outputs the current hour and minute as text, however the Switch Case I've included is simply ignored.

Am I missing something vitally important. I've also tried writing the cases with "break;" at the end too but they don't work.

EDIT: I'm such a tard! I realised I'd been converting the number to a string so that during the case it didn't read any numbers only a string with numbers in.

Assign Switch Case
Hi everyone,

I have a question about my setup that is not working. I have an array of movie clips that are placed on the stage (this works fine) but I want to give each movie clip a value so that I can check what the user types.


Code:
root.createEmptyMovieClip("Placement", 2);
var shapes:Array = new Array("square", "circle", "triangle");
function selectshape():String {
//get the index for the letter
var index:Number = random(shapes.length);
//assign the letter to a var
var s:String = shapes[index];
//display letter
return s;
}
trace(selectshape());
//calls the function that will place the shapes on the stage
pulltogether(shapes);
function pulltogether(test:Array) {
for (var i = 0; i < test.length; i++) {
Placement.attachMovie(shapes[i], shapes[i], i+10, {_x:random(200), _y:random(200)});
}
}


var storedvalue:String;
switch(storedvalue) {
case "square" :
trace("square stored");
storedvalue= "Red square";
break;
case "circle" :
trace("circle stored");
storedvalue= "Blue circle";
break;
case "triangle" :
trace("triangle stored");
storedvalue= " Green triangle";
break;
I just want to use the case to get what mc was picked and give it a value??
Thanks

Switch Case Question
Is it possible do set up a Switch/Case to do something like this with Multiple variables? When I check the code it comes up error free, however it doesn't seem to be working properly. Thanks.

switch (xLocationHolder, yLocationHolder) {case 1,2 :trace("test1");break;case 2,3 :trace("test2");break;}

AS 2.0 Help With Case Switch Array
I'm new to this forum and am trying to do something in flash that my collegues at work say is not possible, but I know it is, so here it goes.

I have AS 3.0 code that allows a user to select multiple radio buttons and depending on
what they select I have a gotoAndStop/Play event on certain buttons.

Problem:
my issue is that I want them to be able to select- for example "btn 1-3-2 or 5-8-3-2-4" and depending on which button they selct will take them to a certain frame.

this is what my radio buttons script looks like:

var rbL:Object = {};
rbL.click = function(obj:Object){
var sel = obj.target;
var dat = sel.data;
trace(sel+" - data - "+dat);
arr.push(dat);
};
////this gives me 6 buttons to choose from\
for(var n:Number=1; n!=6; n++){
var init:Object = {_x:50, _y:n*40+280, label:n, data:n, groupName:"rb"+n};
var ref:MovieClip = this.attachMovie("RadioButton", "RB_"+n, n+1000, init);
ref.addEventListener("click", rbL);
}

this.attachMovie("Button","btnSubmit",2000,{_x:75, _y:675, label:"Design Studio"});

var Submit:Object = {};
Submit.click = function(){
var str:String = "";
for(var m:Number=0; m!=5; m++){
///// notice- it takes first 5 entries only, but I would like to be able to pick less then 5 or more///////
str += arr[m];
}
switch(str){
case "12345":
_root.gotoAndStop("vocal1");
break;
case "21" :
_root.gotoAndStop("vocal2");
break;
case "231" :
_root.gotoAndPlay("studio1");
break;

So when I publish/compile I am only able to select 5 buttons no more and no less.
I would like to be able to have a user select ANY NUMBER OF COMBINATIONS, not only 5 radio buttons but maybe 3 or 2 if they want.
Any help is appreciated-- I can return the favor via audio services, I am professional musician and had a hit in 1998--long ago I know.

Thanks Echowalker

Switch / Case + Variable
Hi there

How can I add a variable inside the case ?

example:


ActionScript Code:
function mouseClickHandler(e:MouseEvent):void {
    for (i=1;i<10;i++) {
                switch (e.target) {
        case "choix3"+i:
            targetChoice3=i;
            break;

Less Bloated Than Switch Case?
I feel like this code is extremely bloated, is there a better way to code this so that it's not so repetitive and bloated? I can only think in terms of AS2 and eval functions to make it less bloated but that doesn't exist in AS3...


ActionScript Code:
private function fruits(event:MouseEvent):void {
            switch (event.currentTarget.name) {
                case "apple" :
                    apple_mc.visible = true;
                    apple_mc.gotoAndPlay("play");
                    this.stage.addChild(apple_mc);
                    apple_mc.x = popUpX;
                    apple_mc.y = popUpY;
                    break;
                case "orange" :
                    orange_mc.visible = true;
                    orange_mc.gotoAndPlay("play");
                    this.stage.addChild(orange_mc);
                    orange_mc.x = popUpX;
                    orange_mc.y = popUpY;
                    break;
                case "pear" :
                    pear_mc.visible = true;
                    pear_mc.gotoAndPlay("play");
                    this.stage.addChild(pear_mc);
                    pear_mc.x = popUpX;
                    pear_mc.y = popUpY;
                    break;
                case "grape" :
                    grape_mc.visible = true;
                    grape_mc.gotoAndPlay("play");
                    this.stage.addChild(grape_mc);
                    grape_mc.x = popUpX;
                    grape_mc.y = popUpY;
                    break;
            }

        }

How To Run A Function For Every Case In A Switch?
ActionScript Code:
function changeBox(event:MouseEvent):void {
    switch(box.boxclass.whichboxvar) {
        removeBox();
        case 3:
        box.boxclass.whichboxvar = 4;
        boxMC.gotoAndStop(1);
        break;
        case 4:
        box.boxclass.whichboxvar = 3;
        boxMC.gotoAndStop(2);
        break;}}

Ok, the above is a simplified version of a code I'm trying to use.. The problem is the removeBox(); line.. I want it to run that function for every case, but I can't put it before the switch because it reads and then changes whichboxvar so the switch would read the wrong thing, and I can't put it after the switch because the switch changes whichboxvar also so the function would read the wrong thing..

Is there any way I can put it in a place like that so I only need the one line of code, instead of putting removeBox(); under every case?

GetSeconds Using Switch/case Please Help
Hi,
I am trying to put together a LED type display for a clock using flash mx.

I would like certain objects to only be visible on certain seconds.

eg. only visible when the seconds read 0,2,3,5,6,8

I can only get it to work for one specific second when i use this line:
_root.sr1._visible = myDate.getSeconds( ) ==2;
with that line the object will only be visible when the seconds read 2 on my cpu clock

Does anyone know how i can do this for multiple seconds

I have tried using:
_root.sr1._visible = myDate.getSeconds( ) ==0;
_root.sr1._visible = myDate.getSeconds( ) ==2;
_root.sr1._visible = myDate.getSeconds( ) ==3;
_root.sr1._visible = myDate.getSeconds( ) ==5;
etc...
But it will only work once for the last number in the code

"sr1" is the instance name of the object that i am trying to make blink only on certain seconds 0,2,3,5,6,8

Can anyone help me??

Switch And Case Problems
Hi i have a minor(greater for me)problem.
I need to have 3 cases in a switch and when i press a button change the case.

Lets say :

test = 1;
switch (test) {
case 1 :
trace("im case 1");
break;
case 2 :
trace("im case 2");
break;
case 3 :
trace("im case 3");
break;
}

and when i press a button on stage change
test =2;

so now im in Case 2.

But when i press the button nothing happens

Thank you all.

Switch / Case Problem
Hi, it's me again, yesterday I had a problem with centering a MC on the Stage and falltimemusic helped me throught it, and now I need that:

if the image's width bigger than Stage's width, make the MC draggable Left and Right;

if the image's height's bigger than Stage's height, make the MC draggable Up and Down;

if both things happen, make it draggable;

if none of these happen, don't make it draggable;

So, here's my code:

Code:
if ((footer._height < Stage.height) && (footer._width < Stage.width)) {a = 4}
else if (footer._height > Stage.height) {a = 2}
else if ((footer._height > Stage.height) && (footer._width > Stage.width)) {a = 3}
else if (footer._width > Stage.width) {a = 1}

switch(a)
{
case 1:
trace ("case: 1!")
footer.onRollOver = function(){
footer.useHandCursor = true
}
footer.onPress = function() {
this.startDrag(false,0-this._width,this._y,Stage.width,this._y)
}
footer.onRelease = function() {
this.stopDrag()
}
break;

case 2:
footer.onRollOver = function(){
footer.useHandCursor = true
}
footer.onPress = function() {
this.startDrag(false,this._x,0-this._height,this._x,Stage.height+this._height)
}
footer.onRelease = function() {
this.stopDrag()
}
break;

case 3:
footer.onPress = function() {
this.startDrag()
}
footer.onRelease = function() {
this.stopDrag()
break;

case 4:
trace ("case: 4!")
footer.onRollOver = function(){
footer.useHandCursor = false
}
footer.onPress = function() {
footer.useHandCursor = false
footer.stopDrag();
}
break;
}
}
This is working kinda fine:
It works whit the width and height (a=1 and a=2). However, It does not work when both things happen at the same time (a=3) and when nothing happens (a=4)

So, where's the problem with my script, is it in the Ifs statements, before the Switch, or in the cases?

Thanks once again

Can I... Dynamic Switch Case
Hi All, I am loading an external XML and I have a for loop and that works great. Now I want to build a dynamic switch case but flash keeps deleteing my case statement in my j for loop. If I hard code the switch all is fine but not what I want

Any help would be great

Thanks
Bobby

stop ();
////////////////////////////////////////////////////////////////////////////////
ResponseObject666 = new xmlObject ();
var xml_file:String = "FileLoader.xml";
ResponseObject666.Open (xml_file);
ResponseObject666.ignoreWhite = true;
ResponseObject666.onLoad = function (success:Boolean) {
//trace ("Success Loader");
var nr = this.GetNumRows ();
//trace (nr);
Response666 = {};
Response666.GTitle = [];
Response666.GFile = [];
///////////////////////////////////////////////////////////////////////////
for (i = 0; i < nr; i++) {
Response666.GTitle = this.GetResult ("Game_Title");
Response666.GFile = this.GetResult ("Game_File");
fredName = Response666.GTitle;
fredFileName = Response666.GFile;
//trace (Response666.GFile);
systems_list.addItem ({label:fredName, data:i});
this.MoveNext ();
/////////////////////////////////////////////////////////////////////
}
var listHandler:Object = new Object ();
listHandler.change = function (evt:Object) {
fader_mc.play ();
switch (evt.target.selectedItem.data) {
//////////////////////
//for (j = 0; j < nr; j++) {
//case j ://<----- case j : //
//file2load = Response666.GFile[j];
//play ();
//break;
//}
/////////////////////

case 0 :
file2load = Response666.GFile[0];
play ();
break;
case 1 :
file2load = Response666.GFile[1];
play ();
break;
ECT...
default :
trace ("unhandled event: " + evt.target.selectedItem.data);
break;
}
};
systems_list.addEventListener ("change", listHandler);
};

Switch/case Limit
I am encountering a very strange problem.. after 39 cases in my switch case statement the 40th case does not get executed.. the code is in my go button and there are like 1000+ lines of code in there.. if I replace my 39th case with the 40th it works but it doesn't execute anything after that!! is there a limit on the number of case statements we can use in action script??? I am really confused with this problem...

Switch / Case Not Working
I need someone who help me with this:

I'm trying to send some variables from a page to a Movie into a PHP page, that is in a different frame. The idea is to make the movie goes to an specifyc scene when it receive an specifyc variable. To do this I'm using the switch / case script:


Code:
stop();
switch (codigo) {
case 1:
gotoAndPlay("news", 1);
break;
case 2:
gotoAndPlay("mailbox", 1);
break;
case 3:
gotoAndPlay("music", 1);
break;
}
The movie is in the file mainFrame.php, and it's embed in this way:


Code:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/s...rsion=7,0,19,0" width="597" height="356">
<param name="movie" value="flash/Mundo02.swf" />
<param name="quality" value="high" />
<param name="menu" value="false" />
<param name="codigo" value="<?= $_GET["codigo"] ?>" />
<embed src="flash/Mundo02.swf" width="597" height="356" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" codigo="<?= $_GET["codigo"] ?>"></embed>
</object>
And the page that send the variables is menu.htm, that have links like:


Code:

mainFrame.php?codigo=2
When I try this, the code <?= $_GET["codigo"] ?> on the mainFrame.php file is successfully replaced for the variable, but the flash movie don't do anything.

What's wrong with this. Can anybody help me.

Why's My Switch/case Not Working?
hi guys
having a problem using the switch/case thingy in flash - i am trying to use it for navigation - setting a variable to a certain value, then the switch should check for the value i have set and then navigate to the right part of the timeline. only it's not working. here's my code:

Code:
switch (clicked) {
case "contact" :
_root.gotoAndPlay("contact");
break;
case "whoweare" :
_root.gotoAndPlay("whoweare");
break;
default :
trace("ouch");
}
i get the "ouch" trace whatever i click. i have set it up so that when the user clicks the 'contact' button the variable "clicked" is set to "contact" and same with the who we are button, sets it to "whoweare"... these are also the lables on the timeline. what i think is happening is that flash is just continuing to play the timeline as it goes to the 'contact' page always, the next thing on the timeline. would be grateful if someone could take a look at the file and tell me what i'm doing wrong...
http://myweb.tiscali.co.uk/murderkins/gv/gv05.fla
thanks!
emma.

Problem With Switch/case, Or ? Something Help Please?
I have a menuing system which loads XML to populate itself, upon clicking a menu item, it sends an html string to the following function:

Code:
_global.loadHTMLpage = function(htmlToLoad){
thumbpath.text = htmlToLoad;
gallerypath.text = typeof(htmlToLoad);
switch (htmlToLoad){
case "/Projects/Photo_Gallery.htm":
if(behind_logo._y != 138){
glide(contentYwithGallery);
}else{
//glide(contentYwithGallery);
}
projectsPage();
break;
case "/Specialties/index.htm":
if(behind_logo._y != 138){
glide(contentYwithGallery);
}else{
//glide(contentYwithGallery);
}
break;
default:
if(behind_logo._y != 38){
glide(contentY);
}else{
}
closeProjectPhoto();
content_loader.removeMovieClip();
nextHTML = htmlToLoad;
test_next.text = nextHTML;
content_loader.attachMovie("textArea", "content", 10);
break;
}
}
ok- if I specify in the AS something like : loadHTMLpage("/"+selectedArea+"/index.htm");
(for example: "Specialties/index.htm")

thumbpath shows : Specialties.index.htm (correct)
gallerypath shows : string (correct)
and the correct area loads and everything works correctly

However, when the "loadHTMLpage" command comes from the dynamic menu
thumbpath shows : Specialties.index.htm (correct)
gallerypath shows : string (correct)
the correct area does not load...

So- I am thinking that the Switch/case is not able to equate the two values (htmlToLoad to the given value in the "case")

is there something I'm missing? types match up, traces look right, text output looks right, but I can't figure it out!

help!

Assigning With Switch/ Case
Hi everyone,

I have a question about my setup that is not working. I have an array of movie clips that are placed on the stage (this works fine) but I want to give each movie clip a value so that I can check what the user types.

Ex.

Code:
_root.createEmptyMovieClip("Placement", 2);
var shapes:Array = new Array("square", "circle", "triangle");
function selectshape():String {
//get the index for the letter
var index:Number = random(shapes.length);
//assign the letter to a var
var s:String = shapes[index];
//display letter
return s;
}
trace(selectshape());
//calls the function that will place the shapes on the stage
pulltogether(shapes);
function pulltogether(test:Array) {
for (var i = 0; i < test.length; i++) {
Placement.attachMovie(shapes[i], shapes[i], i+10, {_x:random(200), _y:random(200)});
}
}


var storedvalue:String;
switch(storedvalue) {
case "square" :
trace("square stored");
storedvalue= "Red square";
break;
case "circle" :
trace("circle stored");
storedvalue= "Blue circle";
break;
case "triangle" :
trace("triangle stored");
storedvalue= " Green triangle";
break;


Any help is appreciated! Thanks

AS 3.0 Help With Case Switch Array
I'm new to this forum and am trying to do something in flash that my collegues at work say is not possible, but I know it is, so here it goes.

I have AS 3.0 code that allows a user to select multiple radio buttons and depending on
what they select I have a gotoAndStop/Play event on certain buttons.

Problem:
my issue is that I want them to be able to select- for example "btn 1-3-2 or 5-8-3-2-4" and depending on which button they selct will take them to a certain frame.

this is what my radio buttons script looks like:

var rbL:Object = {};
rbL.click = function(obj:Object){
var sel = obj.target;
var dat = sel.data;
trace(sel+" - data - "+dat);
arr.push(dat);
};
////this gives me 6 buttons to choose from\
for(var n:Number=1; n!=6; n++){
var init:Object = {_x:50, _y:n*40+280, label:n, data:n, groupName:"rb"+n};
var ref:MovieClip = this.attachMovie("RadioButton", "RB_"+n, n+1000, init);
ref.addEventListener("click", rbL);
}

this.attachMovie("Button","btnSubmit",2000,{_x:75, _y:675, label:"Design Studio"});

var Submit:Object = {};
Submit.click = function(){
var str:String = "";
for(var m:Number=0; m!=5; m++){
///// notice- it takes first 5 entries only, but I would like to be able to pick less then 5 or more///////
str += arr[m];
}
switch(str){
case "12345":
_root.gotoAndStop("vocal1");
break;
case "21" :
_root.gotoAndStop("vocal2");
break;
case "231" :
_root.gotoAndPlay("studio1");
break;

So when I publish/compile I am only able to select 5 buttons no more and no less.
I would like to be able to have a user select ANY NUMBER OF COMBINATIONS, not only 5 radio buttons but maybe 3 or 2 if they want.
Any help is appreciated-- I can return the favor via audio services, I am professional musician and had a hit in 1998--long ago I know.

Thanks Echowalker

Actionscript Switch Case
I'm having a problem with this switch case statement. I'm using a random number and trying to determine from that which string to use by weighting the different options. Currently, the default option is *always* selected no matter what number for rand comes up.


Code:
rand = random(11);

powerupType = "";

trace(rand);

switch(rand){
case rand<=9 :
powerupType="laser_freq_increase";
break;
case rand>9 :
powerupType="add_extra_life";
break;
default :
powerupType="pop";
break;
}

trace(powerType);
Here's a sample of the numbers I get, which is expected:

Code:
4
7
10
9
0
8
4
2
9
10
6
Any ideas? Does Actionscript 2.0 not support > or < in switch case statements?

Case/Switch Statement
I am reading data from a XML file. I need to test the value of one of the nodes and then use a Swith/Case statement  to test the value of one of the nodes. Below is my code:

CODE_root.sixthnode = this.firstChild.childNodes[0].childNodes[6].firstChild.nodeValue;

var tmpCity = _root.sixthnode;

                trace(typeof(tmpCity)); //outputs string
        trace(tmpCity); // outputs MEM
        switch(tmpCity)
        {
            case 'MEM':
            tmpCity = 'Memphis';
            break;
            default:
                        trace("failure");
        }

Switch Case Statements...
Code:
switch (thisthing) {
case "somethingelse" :
houradd2 = 1;
break;
case "something" :
houradd2 = 3;
break;
default :
houradd2 = 0;
}
why won't that work?

in the top of the class i denote that thisthing is a string... and houradd2 is a number.

thanks.

'select Case' Or 'switch' In Actionscript?
Hi all,
I'm pretty new to actionscript 5, and i wonder if there's something like Visual Basic's "select case" or javascript's "switch"?

How Can I Use Multi Condition In Switch Case
Hi,

How can I use multi condition in switch case?

switch (number) {
case 1, 3: // doesn't work
trace ("case 1 or 3 tested true");
break;
}

Thank you

How To Re-interpret As Switch Case Statement?
I've created a soundObject that plays any one of 10 randomly chosen mp3's. The titles to these mp3's are impoted as variables from an external text file. Everything behaves as it should. However it's been suggested I could streamline the manner in which I determine the song title to be displayed. Currently I'm using a series of "if" statements. How would I convert the following to a switch case statement:
Code:
//Test results to determine songtitle and display//
if(randomSongNum==0){
display=title1;
}
if(randomSongNum==1){
display=title2;
}
if(randomSongNum==2){
display=title3;
}
if(randomSongNum==3){
display=title4;
}
if(randomSongNum==4){
display=title5;
}
if(randomSongNum==5){
display=title6;
}
if(randomSongNum==6){
display=title7;
}
if(randomSongNum==7){
display=title8;
}
if(randomSongNum==8){
display=title9;
}
if(randomSongNum==9){
display=title10;
}


Thanks in advance!

Killing Me....problem With Switch/case
I have a switch set up for the direction i want an MC to take, using a variable valued between 0 and 3...and for some reason, whatever movement formula i have in case 0 and 2 do not execute, even though trace statements do...I don't get it.

b

How To Use Switch/case To Goto Certain Frames
I have a vcr-like forward button that I want to use to jump to certain frames depending on where the _currentframe is (i've tried to do it using if's and else's...not much luck).

Basically, when the 'forward' button is pressed, I want to:

- gotoAndPlay (100) if _root._currentframe is between 1 and 99.
- gotoAndPlay (200) if _root._currentframe is between 100 and 199.
- gotoAndPlay (300) if _root._currentframe is between 200 and 299.
etc.

I know this should be pretty easy, the problem is I've never really used switch/case and am not really sure what to do.

Any help would be appreciated!

Action In Switch/ Case Always Executed?
Hey everyone,

I've been trying to make a game of blackjack in AS3 to get used to the functions and syntax, as I have always used AS2. However, I ran into a problem. I've been trying to get the ace to have a value of 11 when the score is less than or equal to 21 and a value of 1 when higher. This is my code in a nutshell:

PHP Code:




switch(drawCard1){
     case 1:
     value1 = 1;
     break
// etc.

    case 51:
    value1 = 11;
    playerace1 = true;
    break
}







Then, after each drawCard, I want to check the score:


PHP Code:




if((playerace1=true) && (value1+value2+value3+value4+value5>21)){
            value1-=10;
            playerace1=false;
        }
        
                if((playerace2=true) && (value1+value2+value3+value4+value5>21)){
            value2-=10;
            playerace2=false;
        }
        
        
                if((playerace3=true) && (value1+value2+value3+value4+value5>21)){
            value3-=10;
            playerace3=false;
        }
        
                if    ((value1+value2+value3+value4+value5)>21){
                    addChild(alphaT);
                    alphaT.gotoAndPlay("LOSE");
                }
    }








However, the problem I have now is that the score is decreased by 10 every time it goes over 21, whether the playerace's are true or not. Does anyone know how to prevent this or think of a better solution? Please let me know =)

~Patrick

[CS3] Combo Box/switch Case Problem
Hi. I'm trying to use the value from a combo box in a switch case statement but it isn't working. Can anybody spot a problem with the following test code please:


Code:

var switchValue:int = 0;
switchValue = int(cmbColour.selectedItem.data);
switch(switchValue) {
case 1:
trace("test1");
break;
case 2:
trace("test2");
break;
default:
trace("test3");
}

Multiple Switch/case Clause?
hi. i am hoping this is a silly question, and that the answer is obvious, and i am stupid etc... but is there any way to do multiple case clauses in action script? eg.

switch(x) {
case 1,2,3,4,5:
...
break;
case 6:
...
break;
}

i can't figure the syntax

cheers,
cris...

Copyright © 2005-08 www.BigResource.com, All rights reserved