switch inside another switch actionscript 3 - actionscript-3

i have this lines of code that are very long and i want to know if this codes can be converted from this
if(BtnInteracted == "New"){
if(sample_1.SaveSlotNumber == "1"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "2"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "3"){
if(){
}
else{
}
}
}
else if (BtnInteracted == "Con"){
if(sample_1.SaveSlotNumber == "1"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "2"){
if(){
}
else{
}
}
else if(sample_1.SaveSlotNumber == "3"){
if(){
}
else{
}
}
}
to this.
switch(BtnInteracted){
case "New": switch (sample_1.SaveSlotNumber){
case "1": //if() else() statement;
case "2": //if() else() statement;
case "3": //if() else() statement;
} break;
case "Con": switch (sample_1.SaveSlotNumber){
case "1": //if() else() statement;
case "2": //if() else() statement;
case "3": //if() else() statement;
} break;
}
is it even possible to make this code or my original is my only option?
thanks for any reply!

You have to be careful with the break statements, but it will work. You can nest switches, but personally I dont't think inner switches are more readable; I prefer pass stuff to functions:
switch(BtnInteracted)
{
case "New":
{
startFrom(sample_1.SaveSlotNumber);
break;
}
case "Con":
{
continueFrom(sample_1.SaveSlotNumber);
break;
}
}
And then use a new switch in the button
function startFrom(index:int):void
{
trace("start from ", index);
switch(index)
{
case 1:
{
// do something
break;
}
case 2:
{
// do something
break;
}
}
}
function continueFrom(index:int):void
{
trace("continue from", index);
switch(index)
{
case 1:
{
// do something
break;
}
case 2:
{
// do something
break;
}
}
}
In lots of cases you'll need the function multiple times with other input so you dont have you repeat yourself and it keeps clear what happens with a specific case.

Related

MySQL datatypes vs JDBC types

How to find relationship between MySQL datatypes and JDBC types? For example, MySQL TEXT type corresponds to JDBC LONGVARCHAR. Where can we find any official documentation?
MysqlDefs.java
// Maps the given MySQL type to the correct JDBC type.
static int mysqlToJavaType(String mysqlType) {
if (mysqlType.equalsIgnoreCase("BIT")) {
return mysqlToJavaType(FIELD_TYPE_BIT);
} else if (mysqlType.equalsIgnoreCase("TINYINT")) {
return mysqlToJavaType(FIELD_TYPE_TINY);
} else if (mysqlType.equalsIgnoreCase("SMALLINT")) {
return mysqlToJavaType(FIELD_TYPE_SHORT);
} else if (mysqlType.equalsIgnoreCase("MEDIUMINT")) {
return mysqlToJavaType(FIELD_TYPE_INT24);
} else if (mysqlType.equalsIgnoreCase("INT") || mysqlType.equalsIgnoreCase("INTEGER")) {
return mysqlToJavaType(FIELD_TYPE_LONG);
} else if (mysqlType.equalsIgnoreCase("BIGINT")) {
return mysqlToJavaType(FIELD_TYPE_LONGLONG);
} else if (mysqlType.equalsIgnoreCase("INT24")) {
return mysqlToJavaType(FIELD_TYPE_INT24);
} else if (mysqlType.equalsIgnoreCase("REAL")) {
return mysqlToJavaType(FIELD_TYPE_DOUBLE);
} else if (mysqlType.equalsIgnoreCase("FLOAT")) {
return mysqlToJavaType(FIELD_TYPE_FLOAT);
} else if (mysqlType.equalsIgnoreCase("DECIMAL")) {
return mysqlToJavaType(FIELD_TYPE_DECIMAL);
} else if (mysqlType.equalsIgnoreCase("NUMERIC")) {
return mysqlToJavaType(FIELD_TYPE_DECIMAL);
} else if (mysqlType.equalsIgnoreCase("DOUBLE")) {
return mysqlToJavaType(FIELD_TYPE_DOUBLE);
} else if (mysqlType.equalsIgnoreCase("CHAR")) {
return mysqlToJavaType(FIELD_TYPE_STRING);
} else if (mysqlType.equalsIgnoreCase("VARCHAR")) {
return mysqlToJavaType(FIELD_TYPE_VAR_STRING);
} else if (mysqlType.equalsIgnoreCase("DATE")) {
return mysqlToJavaType(FIELD_TYPE_DATE);
} else if (mysqlType.equalsIgnoreCase("TIME")) {
return mysqlToJavaType(FIELD_TYPE_TIME);
} else if (mysqlType.equalsIgnoreCase("YEAR")) {
return mysqlToJavaType(FIELD_TYPE_YEAR);
} else if (mysqlType.equalsIgnoreCase("TIMESTAMP")) {
return mysqlToJavaType(FIELD_TYPE_TIMESTAMP);
} else if (mysqlType.equalsIgnoreCase("DATETIME")) {
return mysqlToJavaType(FIELD_TYPE_DATETIME);
} else if (mysqlType.equalsIgnoreCase("TINYBLOB")) {
return java.sql.Types.BINARY;
} else if (mysqlType.equalsIgnoreCase("BLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("MEDIUMBLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("LONGBLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("TINYTEXT")) {
return java.sql.Types.VARCHAR;
} else if (mysqlType.equalsIgnoreCase("TEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("MEDIUMTEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("LONGTEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("ENUM")) {
return mysqlToJavaType(FIELD_TYPE_ENUM);
} else if (mysqlType.equalsIgnoreCase("SET")) {
return mysqlToJavaType(FIELD_TYPE_SET);
} else if (mysqlType.equalsIgnoreCase("GEOMETRY")) {
return mysqlToJavaType(FIELD_TYPE_GEOMETRY);
} else if (mysqlType.equalsIgnoreCase("BINARY")) {
return Types.BINARY; // no concrete type on the wire
} else if (mysqlType.equalsIgnoreCase("VARBINARY")) {
return Types.VARBINARY; // no concrete type on the wire
} else if (mysqlType.equalsIgnoreCase("BIT")) {
return mysqlToJavaType(FIELD_TYPE_BIT);
} else if (mysqlType.equalsIgnoreCase("JSON")) {
return mysqlToJavaType(FIELD_TYPE_JSON);
}
// Punt
return java.sql.Types.OTHER;
}

AS3 - Making a True/False Quiz with ComboBoxes

So I've been working on a larger project for a while and am having a little confusion with a quiz I am intergrating into it.
I would like to use ComboBoxes to create a true/false quiz. I will be using a switch structure to track the answer of the end-user. I already now how to use a switch structure for ComboBoxes, however, I am unsure as to how I can:
1.) determine if all labels in the ComboBoxes are correct, and;
2.) how I can make my structure evn work. I am having troubles right now.
Please see code below. You will see that it is a logical error. I am unsure of what the issue is, so your help is appreciated again!
Thanks!
-Zero;
import fl.controls.ComboBox;
import flash.events.MouseEvent;
F21next_btn.visible=false;
firstTF_cb.addItem({label: "True"});
firstTF_cb.addItem({label: "False"});
secondTF_cb.addItem({label: "True"});
secondTF_cb.addItem({label: "False"});
thirdTF_cb.addItem({label: "True"});
thirdTF_cb.addItem({label: "False"});
fourthTF_cb.addItem({label: "True"});
fourthTF_cb.addItem({label: "False"});
fifthTF_cb.addItem({label: "True"});
fifthTF_cb.addItem({label: "False"});
F21check_btn.addEventListener(MouseEvent.CLICK, F21checkAnswers);
F21next_btn.addEventListener(MouseEvent.CLICK, F21goToFrameTwentytwo);
var firstCB:ComboBox;
var secondCB:ComboBox;
var thirdCB:ComboBox;
var fourthCB:ComboBox;
var fifthCB:ComboBox;
firstCB=firstTF_cb;
secondCB=secondTF_cb;
thirdCB=thirdTF_cb;
fourthCB=fourthTF_cb;
fifthCB=fifthTF_cb;
function F21goToFrameTwentytwo(event:MouseEvent):void{
gotoAndStop(22);
}
//HOW DO U CHECK IF A COMBO BOX ITEM IS TRUE/FALSE AND SELECTED
function F21checkAnswers(event:MouseEvent):void
{
switch(firstCB)
{
case "True":
{
firstQ_txt.textColor=0x00FF00;
break;
}
case "False":
{
firstQ_txt.textColor=0xFF0000;
break;
}
}
switch(secondCB)
{
case "True":
{
secondQ_txt.textColor=0x00FF00;
break;
}
case "False":
{
secondQ_txt.textColor=0xFF0000;
break;
}
}
switch(thirdCB)
{
case "True":
{
thirdQ_txt.textColor=0x00FF00;
break;
}
case "False":
{
thirdQ_txt.textColor=0x00FF00;
break;
}
}
switch(fourthCB)
{
case "True":
{
fourthQ_txt.textColor=0x00FF00;
break;
}
case "False":
{
fourthQ_txt.textColor=0xFF0000;
break;
}
}
switch(fifthCB)
{
case "True":
{
fifthQ_txt.textColor=0x00FF00;
break;
}
case "False":
{
fifthQ_txt.textColor=0xFF0000;
break;
}
}
}
The selectedLabel property of ComboBox gives the currently selected string of the combo box.
switch(firstCB.selectedLabel)
{
case "True":
{
firstQ_txt.textColor = 0x00FF00;
break;
}
case "False":
{
firstQ_txt.textColor = 0xFF0000;
break;
}
}

Compare answer from user and possible answer in array

My input text field has two possible answers which are "luah" or "hal" but my code is not working :
stop();
//var jawapan1=Array;
txt_zuhal.addEventListener(KeyboardEvent.KEY_DOWN,handler);
function handler(event:KeyboardEvent)
{
//jawapan1=("luah", "hal");
// if the key is ENTER
if(event.charCode == 13)
{
if(txt_zuhal.text == 'luah'||'hal')
{
trace("1.correct");
}
else
{
trace("1.Sorry, Wrong answer");
}
}
}
private function handler(event:KeyboardEvent):void
{
//jawapan1=("luah", "hal");
// if the key is ENTER
if(event.charCode == 13)
{
if(txt_zuhal.text == "luah" || txt_zuhal.text == "hal")
{
trace("1.correct");
}
else
{
trace("1.Sorry, Wrong answer");
}
}
}

For each loop not looping through everything

I have a loop that runs in an onEnter function (bad i know). I only want it to run once but it doesnt loop through every object. I think it doesnt have time before the next frame runs. Any ideas on how to make it loop all the way?
private function onEnter(e: Event) {
if (deleteThis == true) {
if (timer == 0 || 1) {
if (checkExplosion == false) {
gotoAndStop(2)
if (Main.bloonList.length > 0) {
for each(Main.bloon in Main.bloonList) {
if (Main.areaOfCollision(Main.bloon, this, 0)) {
if (Main.bloon.currentFrame != 5) {
Main.money++;
Main.bloon.nextFrame();
Main.bloon.gotShot();
} else {
Main.money++;
Main.bloon.deleteBloon();
}
}
}
}
checkExplosion=true
}
}
}
}
Edit - deleteBloon();
public function deleteBloon()
{
this.parent.removeChild(this);
}
Firstly, this:
if (timer == 0 || 1)
Should be this:
if (timer == 0 || timer == 1)
Then you may need to change the code a little bit. Something like this could work. I do suspect your issue may actually lie in the deleteBloon function, though. Without seeing it I can't be sure, but there is nothing (technically) wrong with your for loop.
private function onEnter(e: Event) {
if (deleteThis == true) {
if (timer == 0 || timer == 1) {
if (checkExplosion == false) {
gotoAndStop(2);
if (Main.bloonList.length > 0) {
// This isn't optimised as I wasn't sure what Main.bloon could be
for each(var bloon:Main.bloon in Main.bloonList) {
if (Main.areaOfCollision(bloon, this, 0)) {
if (bloon.parent && bloon.currentFrame != 5) {
bloon.nextFrame();
bloon.gotShot();
} /*else {
// Make sure that deleteBloon is deleteing the correct array index. This is likely where the issue is.
bloon.deleteBloon();
}*/
Main.money++;
}
}
}
checkExplosion = true;
}
}
}
}
This would be in bloon:
import flash.utils.setTimeout;
function gotShot():void{
// second parameter is time in milliseconds before executing
setTimeout(deleteBloon, 250);
}

Syntax error 1073

I'm getting this compiling error but am not quite sure how to fix it -
1073: Syntax error: expecting a catch or a finally clause.
function __setProp___id98__Dage_APOP_Content_0()
{
if (__setPropDict[__id98_] == undefined || !(int(__setPropDict[__id98_]) >= 1 && int(__setPropDict[__id98_]) <= 5))
{
__setPropDict[__id98_] = currentFrame;
try
{
__id98_["componentInspectorSetting"] = true;
}
catch (e:Error)
{
try
{
}
__id98_["componentInspectorSetting"] = false;
}
catch (e:Error)
{
}
}
return;
} // end
Your catch block has been misplaced. This code is also very redundant, possibly generated from a decompiler?
function __setProp___id98__Dage_APOP_Content_0() {
if (__setPropDict[__id98_] == undefined|| !(int(__setPropDict[__id98_]) >= 1 && int(__setPropDict[__id98_]) <= 5)) {
__setPropDict[__id98_] = currentFrame;
try {
__id98_["componentInspectorSetting"] = true;
} catch (e:Error) {
try {
__id98_["componentInspectorSetting"] = false;
} catch(e:Error) {}
}
}
}