--------------------------------------------------------------------------------------------------------------
SWITCH CASE BREAK AS2
Applying the switch/case conditional logic in Flash
--------------------------------------------------------------------------------------------------------------
CODE AS2
--------------------------------------------------------------------------------------------------------------
car_mc.onRelease = boat_mc.onRelease = airplane_mc.onRelease = island_mc.onRelease = function() {
var myName:String = this._name;
var clicked:String = myName.substr(0, -3);
write(clicked);
};
function write(clicked:String):Void {
switch (clicked) {
case "car" :
info_txt.text = "The "+clicked+" is a terrestrial vehicle.";
break;
case "boat" :
info_txt.text = "The "+clicked+" is a sea vehicle.";
break;
case "airplane" :
info_txt.text = "The "+clicked+" is an aerial vehicle.";
break;
default :
info_txt.text = "You haven't clicked on a vehicle.";
}
}
--------------------------------------------------------------------------------------------------------------
OR USE THIS CODE
BUTTON FIRST LETTER SHOULD BE SAME TO CASE
HERE BUTTON NAME LENGTH HAS 4 LETTERS SO
USE -3 Num1.substr(0,-3);
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
A123.onPress = B123.onPress = function(){
var Num1:String = this._name;
var Num2:String = Num1.substr(0,-3);
NameTraceFunction(Num2);
}
function NameTraceFunction(AS2:String){
switch (AS2) {
case "A" :
Txt1.text = "The "+AS2+" FOR APPLE";
break;
case "B" :
Txt1.text = "The "+AS2+" FOR BALL";
break;
}
}
--------------------------------------------------------------------------------------------------------------
OR USE THIS CODE WITH ARRAY
----------------------------------------------------------------------------------------------------------------
//PART 1
Txt1.text = "CLICK MOVIE CLIP SYMBOL"
var MovieArray:Array = new Array(MOVIE1,MOVIE2);
//PART 2
for(
var i :Number = 0;
i < MovieArray.length;
i = i+1
)
{
MovieArrayFunction(MovieArray[i]);
}
//PART 3
function MovieArrayFunction(MovieArray){
MovieArray.onPress = function (){
switch(MovieArray){
case MOVIE1:
trace("MOVIE1");
Txt1.text = "MOVIE:1"
break ;
case MOVIE2:
trace("MOVIE:2");
Txt1.text = "MOVIE:2"
break ;
}
}
}
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
AS3 CODE
READ MORE:
http://edutechwiki.unige.ch/en/ActionScript_3_event_handling_tutorial
https://www.youtube.com/watch?v=IrafWKU3Z6U
--------------------------------------------------------------------------------------------------------------------
//AS3 SWITCH CASE STATMENT
//IT WORKS WITH TRACE LABEL
//USE BUTTON COMPONENT BUTTON
//GIVE INSTANCE NAME btn1; btn2
//CHANGE BUTTON LABEL A; B
//BUTTON LABEL SHOULD BE EQUAL TO CASE NAME
//SUCH AS BUTTON LABEL A SO USED case "A" :
//USE SAME FUNCTION NAME
// MAKE TEXT BOX WITH INSTANCE NAME Txt1
//https://www.youtube.com/watch?v=IrafWKU3Z6U
//http://edutechwiki.unige.ch/en/ActionScript_3_event_handling_tutorial
btn1.addEventListener(MouseEvent.CLICK, Fn1);
btn2.addEventListener(MouseEvent.CLICK, Fn1);
function Fn1(event:MouseEvent):void {
switch (event.currentTarget.label){
//BUTTON LABEL SHOULD BE EQUAL TO CASE NAME
//SUCH AS BUTTON LABEL A SO USED case "A" :
case "A" :
Txt1.text = "APPLE" ;
break;
case "B" :
Txt1.text = "BALL";
break;
}
}
--------------------------------------------------------------------------------------------------------------
OTHER CODES AND EXAMPLES
SWITCH CASE BREAK AS2 AS3 - YouTube
https://www.youtube.com/watch?v=3FuheCHZDKI
28 mins ago - Uploaded by SAVE MONEY
https://www.youtube.com/watch?v=atbQBMKmYQg http://flashcollege.blogspot.coUSE CASE FUNCTION IN AS3 WITH BUTTON - YouTube
https://www.youtube.com/watch?v=atbQBMKmYQg
2 Feb 2012 - Uploaded by SAVE MONEY
USE CASE FUNCTION IN AS3 WITH BUTTON. Zafarullah Qamar ... switch (event------------------------------------------------------------------------------------------------------------------------------------ OR USE AS3 CODE http://flashcollege.blogspot.co.uk/2016/05/switch-case-as2-as3.html https://www.youtube.com/watch?v=atbQBMKmYQg ------------------------------------------------------------------------------------------------------------------------------------ import flash.events.MouseEvent; function clickHandler(event:MouseEvent):void{ // Do something on click... switch(event.currentTarget.name){ case "my_btn1": // do something... Break; case "my_btn2": // do something... Break; case "my_btn3": // do something... Break; } } my_btn1.addEventListener(MouseEvent.CLICK, clickHandler); my_btn2.addEventListener(MouseEvent.CLICK, clickHandler); my_btn3.addEventListener(MouseEvent.CLICK, clickHandler); ------------------------------------------------------------------------------------------------------------------------- OR USE THIS CODE WITH COLOR PICKER http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7fac.html -------------------------------------------------------------------------------------------------------------------------- //AS3 CODE aCp.visible = false; aButton.addEventListener(MouseEvent.CLICK, clickHandler); function clickHandler(event:MouseEvent):void { switch(event.currentTarget.label) { case "Show": aCp.visible = true; aButton.label = "Disable"; break; case "Disable": aCp.enabled = false; aButton.label = "Enable"; break; case "Enable": aCp.enabled = true; aButton.label = "Hide"; break; case "Hide": aCp.visible = false; aButton.label = "Show"; break; } }
--------------------------------------------------------------------------------------------------------------------------
SWITCH CASE BREAK WITH RANDOM NUMBERS
https://www.kirupa.com/developer/actionscript/switchcase.htm
--------------------------------------------------------------------------------------------------------------------------
OR USE THIS CODE
VARIABLE NAME SHOULD BE SAME IN SWITCH BOX var Num1 = switch(Num1)
--------------------------------------------------------------------------------------------------------------------------
switch(Num1){ default: Txt1.text = "START RANDOM NUMBER WITH BUTTON" }
Bn1.onPress=function(){ var Num1:Number = Math.floor(Math.random() * 11); switch(Num1){ case 0: trace ("ZERO"); Txt1.text = "ZERO" break ; case 1: trace ("ONE"); Txt1.text = "ONE" break ; case 2: trace ("TWO"); Txt1.text = "TWO" break ; case 3: trace ("THREE"); Txt1.text = "THREE" break ; case 4: trace ("FOUR"); Txt1.text = "FOUR" break ; case 5: trace ("FIVE"); Txt1.text = "FIVE" break ; case 6: trace ("SIX"); Txt1.text = "SIX" break ; case 7: Txt1.text = "SEVEN" trace ("SIX"); break ; case 8: Txt1.text = "EIGHT" trace ("EIGHT"); break ; case 9: trace ("NINE"); Txt1.text = "NINE" break ; case 10: trace ("TEN"); Txt1.text = "TEN" break ; } }
--------------------------------------------------------------------------------------------------------------
EmoticonEmoticon