actionscript-3,switch-statement,case,parentheses , AS3 switch/case difference with or without parenthesis


AS3 switch/case difference with or without parenthesis

Question:

Tag: actionscript-3,switch-statement,case,parentheses

In AS3 it is possible to write code without parenthesis, like such

switch(letter)
{
    case "A":
        // some code
        break;
    case "B":
        // some more code
        break;
}

or with the parenthesis, like this

switch(continent)
{
    case "A":
    {
        // some code
        break;
    }
    case "B":
    {
        // some more code
        break;
    }
}

What is the difference, and why use one over another?


Answer:

There is no difference. This would also be valid:

switch
{
    case "A":
    {
        {
            // some code
            break;
        }
    }
}

You can add a { } block wherever you like.


Related:


AS3: Fast hovering doesn't execute rollOut


actionscript-3,flash,button
I'm having a serious problem that is getting me nervous: I've made a button _btn that includes ROLLOVER and ROLLOUT animations with coding (an nested movieclip instance called barra that increases to half alpha when you hover over and decreases when you hover out). [Here it should go a descriptive...

Edit Manager activePoint “Y” Position ActionScript3


actionscript-3,flash,text
I'm working with TextFlow and EditManager in AS3 (flashx.textLayout) I want to know how get ActivePosition pointer "Y" position, I know I can get activePosition from EditManager but it's returns character position. I want to count if activePosition out of screen, then scroll down (text is larger and its out...

AS3 : How to compare 2 array containing objects using 1 for loop only?


arrays,actionscript-3,flash
I have 2 array having objects of different length var arr : Array = [{name : "aa", id : "0"}, {name : "bb", id : "1"}, {name : "cc", id : "2"}]; var arrTemp : Array = [{name : "ee", id : "0"}, {name : "hh", id : "1"}, {name...

Why isn't this php math code working


php,actionscript-3
Hey guy's so am trying to convert this as3 code to php but its not working correctly i need it like the as3 one generating thanks! PHP: print(floor(rand() * 1000) + 3000); Result:28240000 AS3: var intCID = Math.floor(Math.random() * 1000) + 3000; var strSessionId = String(intCID); trace(strSessionId); Result:3330...

Inequalities inside a switch statement [duplicate]


javascript,switch-statement
This question already has an answer here: Javascript conditional switch statement 5 answers I just started learning about the switch command in JavaScript, and was wondering if the cases could be constructed so as to include inequalities (<, >, <= and >=), instead of equality (==). Also, can one...

converting XML data into an array of objects AS3


actionscript-3
I'm using Flash AS4 and Ive created and array that holds xml data which works fine with the following loop for(var i:int = 0; i < uNavXML.length(); i++){ navArray.push(uNavXML..navRef.text()[i]); The XML data is actually the names of movie clips that I have on stage: xmlLIST :<uNav> <unavNavID>1</unavNavID> <navRef>navBtns.nav01</navRef> </uNav> <uNav>...

ActionScript: Specification of the is operator


actionscript-3
I am having trouble googling for the expected behavior of the is operator in AS3. What I need to know is what should happen if the left side is null. I know it is possible to test, and get empirical results, but I need to know what the specification says,...

type conversion if flex


java,actionscript-3,flex
I am using Flerry as Java-Flex bridge for my Flex Desktop Application. How to convert List in Java to ArrayCollection in Flex Flex Code:- [Bindable]public var screenList:ArrayCollection; <flerry:NativeObject id="windowControllerObj" source="ls.window.EnumAllWindowNames" singleton="true" fault="windowControllerObj_faultHandler(event)"> <flerry:NativeMethod id="getWindowNames" name="getAllWindowNames" result="windowControllerObj_resultHandler(event)" fault="getWindowNames_faultHandler(event)"/>...

SCORM API wrapper and Flash in full screen


javascript,actionscript-3,flash,scorm2004,scorm1.2
I lately posted this and unfortunately I couldn't figure it out why. Furthermore I haven't any solution for that. Today I realised I can switch between NORMAL and FULL_SCREEN without SCORM parts of the content (connect/disconnect, get/set, etc.). But when I check both Flash wrapper and Mike Rustici's edited API...

Simple VBA Select Case statement not working, Why not?


vba,switch-statement,case
Simple Select Case statement is not working as expected. Message should show this as falling into the "too long" bucket but it comes up as "too short" Lenn = 20 Select Case Lenn Case 7 msg = "You've entered " & Lenn & " digits, this is ok" Case 11...

Problems with control flow structures using strings


java,if-statement,switch-statement,control
Below is method that asks for a medium that is either air, water, or steel. If what is entered isn't one of these, the programs ends. If it is a valid medium, it asks for a distance it will travel and calculates the time through each medium. The problem I...

Using Switch for Simple Unity3D Patrol Movement


c#,unity3d,switch-statement
I'm using a switch statement to create two movement types on an enemy: Forward, and Backwards. The enemy has three patrol points. When he begins, I want him moving from the first patrol point and adding 1 to the current point when he hits his second patrol point (empty 3D...

Can't parse XML AS3 in flash with namespaces [SOLVED]


xml,actionscript-3,flash,e4x
I don't understand why I can't parse these datas : <places yahoo:start="0" yahoo:count="1" yahoo:total="1" xmlns="http://where.yahooapis.com/v1/schema.rng" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"> <place yahoo:uri="http://where.yahooapis.com/v1/place/23424819" aaa:lang="en-US" xmlns:aaa="http://www.w3.org/XML/1998/namespace"> <woeid>23424819</woeid> <placeTypeName code="12">Pays</placeTypeName> <name>France</name> <country type="Pays" code="FR"...

how to fix error 1009 in as3


actionscript-3,timer,typeerror
hi i have been searhing the net for hours and have not found a solution to my problem and i have no idea how to fix it as i am only new to flash so if you know anything that might help me just comment below please all help is...

Dynamic Text doesn't show up through code


actionscript-3
if I make a dynamic text on the stage, name it something like "output" And I write in the enterframe. output.text = "Something"; It doesn't even show up in the stage, and the text box is blank....

C++ Why does this work


c++,visual-studio,visual-c++,switch-statement
I am using Microsoft Visual studio 2013 I currently have this switch statement: switch (option) { case 1: getline(cin, newname); cout << "What would you like your new username to be?\nName: "; getline(cin, newname); name = newname; cout << "\nYour username is now '" << name << "' with your...

PHP Loose comparison and null on Switch


php,null,switch-statement,comparison,case
Today I saw a strange bug on my code. I have a switch with comparison on case and if my variable equals null or '' it will always comes in the first case. My code : $sHost = filter_input(INPUT_SERVER, 'HTTP_HOST'); switch($sHost){ // Local case strpos($sHost, "dev.localhost") !== false: $this->_sEnv =...

Why final Byte as a case in switch statement doesn't compile?


java,switch-statement,constants
byte a = 125; final byte b = 2; final Byte c = 3; switch (a) { case b: // works fine break; case c: // Constant Expression required break; } Since cis a final variable, isn't it a compile time constant and hence a valid case label?...

Returning an integer to determine which switch statement to show


c++,exception-handling,switch-statement,user-feedback
I'm creating a board game (stratego) in c++ and was wondering if it considered a poor practice to return an integer from a class method in order to determine which case in a switch statement to show to the user. Example: In stratego, you can't attack board pieces that are...

Adobe Flash CS6 AS3: KeyUp Handler triggers immediately after KeyDown Handler


actionscript-3,flash
So in my code I was attempting to make it where you had two players, each player had their own key down and key up handlers, clearly labelled in my attached code, and in their I handle the movement, player one has WSAD and player two uses the Left, Right,...

why the following code gives the first mobile no. irrespective of name


c,string,switch-statement,comparison
Please explain why the following code gives the first mobile no. irrespective of entered name: #include<stdio.h> #include<conio.h> int mobileno(char[]); int main(){ char input[20]; gets(input); printf("%s",input); int x; x = mobileno(input); printf("%d",x); switch(x){ case 0:printf("7255222319");break; case 1:printf("9404521113");break; case 2:printf("9326513553");break; case 3:printf("9845621611");break; case 4:printf("4556312390");break; case 5:printf("9245178190");break; case 6:printf("9214188214");break; case...

How to know fast if another computer is accesible in AS3 (Adobe Air)


file,actionscript-3,air,lan
I'm using FileStream to read files in two computers that are connected in a Local Area Network (LAN). I have no problem to read the files when the others computers are connected. I'm checking if the directory exists before writing the file I'm checking if the directory AND the file...

Binary operator '~=' cannot be applied to two UmRet operands


swift,switch-statement
I'm working on integrating an IDTech swiper into my app and I've gotten pretty far along, added the library, registered notifications, unregistered them, and now I'm working on a function that connects the reader. I can't seem to figure out what I'm doing wrong here when I'm attempting to switch...

AS3 can't find the load method on a Loader


actionscript-3,flash,flex
I'm trying to load an image from the internet with AS3 following this tutorial. When I try to compile the application I get the following error: Call a possibly undefined method load through a reference with static type Loader. my_loader.load(where, loaderContext); ^ Here is the code I'm using: package {...

Java - duplicate case label


java,intellij-idea,switch-statement
I found some time ago a function to replace polish characters in text with "normal" version of this character. I used this in some projects earlier without problems, but now, when i just copied it, this doesn't want to work. But when I try to compile old projects in the...

AS3 LocalConnection: function is not firing


actionscript-3,flash,air
I'm building an AIR app that sends text string to a swf-file. When I export the sender and reciever apps to swf and run them in Flash players, everything works well. But when publishing the sender app to AIR things don't work anymore. I think the connection works, because there...

How to convert preg_replace from PHP to AS3?


php,actionscript-3
I'm doing a fan Transformice map editor, but I've a question, "How can I do a preg_replace in Flash AS3?"... This is something like <? $mapXml = "<C><P /><Z><S><S L="304" H="65" X="175" Y="355" T="6" P="0,0,0.3,0.2,0,0,0,0" /></S><D /><O /></Z></C>"; $mapXmlDisplay = preg_replace('<S L="(.*)" H="(.*), etc..."', 'someThing', $mapXml); ?> It's possible? Thanks...

Fisher-Yates Shuffle Algorithm error


arrays,algorithm,actionscript-3,for-loop
so I'm currently making a quiz game with Actionscript 3.0, and I wanna shuffle the questions with this Fisher-Yates Shuffle Algorithm: This is my code: var questions:Array = [1,2,3,4,5,6,7,8,9,10]; function ShuffleArray(input:Array) { for (var i:int=input.length-1; i>=0; i--) { var randomIndex:int = Math.floor(Math.random() * (i+1)); var itemAtIndex:int = input[randomIndex]; input[randomIndex] =...

How to remove all Objects in For Loop?


actionscript-3,for-loop,flash-cs6
Hey Everyone So I know this has to be really Simple I am over complicating it and can't figure out how to do it. So I have these stars moving in the background in my startScreen and I want to remove them when the Game starts. Here is How I...

Including library in AIR Native Extension causes the error, “The extension context does not have a method with the name…” for all methods


c++,c,actionscript-3,dll,air
I am working on an AIR Native Extension (ANE) for Windows desktop. The point of this extension is to be able to call out to a third-party C library, which consists of two .h files defining the method signatures/typedefs, and a .lib file. Before including the third party library in...

Building a digital signage platform in HTML5


jquery,html5,actionscript-3
I need some feedback! So if any help, Thank you! I'm a developer for a digital signage company. We built a platform in Flash (ActionScript 3) and it has been running really smooth for a few years now. We've been talking about trying to move to HTML5, JQUERY and PHP...

AS3 - Score counter


actionscript-3
I am making a simple math game with four frames. In the first frame you can choose the math operation you want to practice. In the second frame you are presented with a randomly generated math question. If you enter the correct answer, the application outputs "correct answer", and skips...

Ending While loop with blank line(Enter key) inside SwitchCase


java,while-loop,switch-statement,blank-line
*amended input scan I'm trying to end a while loop with enter key/blank line Test codes below works fine. Scanner scan = new Scanner(System.in); String line; while ( (line=scan.nextLine()).length() > 0) { System.out.println(line); } However, when I integrate it within my main program(while loop placed within int switch case within...

Remove click after going to another scene in AS3?


actionscript-3,flash
After switching to my 2nd scene, the keyboard event does not work until I left-click the screen. How to avoid that left click so that I can trigger my keyboard event directly right after moving to my 2nd scene? More details you may need: 1st Scene btnStart.addEventListener(MouseEvent.CLICK, initGame); function initGame(e:MouseEvent)...

How can hitTestObject work for many objects?


actionscript-3,hittest
I have a game where player moves forward over (semi)random tiles. I want a hittest for when the player hits a certain tile. However when the char hits one of the spawned in floor2's nothing happens. I think this is because there are multiple 'floor2' movieclips on the stage ?...

How can i get a function to use any movie clip?


function,actionscript-3,flash-cs6
I'm a little lost in understanding this kind of function, i get the feeling this has been asked a thousand times but cannot find an explanation of what the code is doing. Basically i just want a movie clip with instance name box to do something, then reuse the function...

Actionscript 3 Search for string in array, propblem


arrays,actionscript-3,flash,actionscript
I have a problem with searching for strings in an array. I want to search for one word and if it exists, I want to trace the position of the string in the array. I believe it should be something like this: if (myArray contains "11111111") { trace("*position*") } else...

Golang switch between structs


struct,go,interface,switch-statement
I'm new to golang and I'm trying to create a function that, based on the struct it's used on, will return a formatted string using Sprintf type Name struct { Title string First string Last string } type Location struct { Street string City string State string Zip string }...

Javascript switch statements for form input


javascript,forms,input,switch-statement
Trying to learn some basic JS principles to create a delivery cost calculator based on user input forms and JS switch statements to return a price. (I know this would be easier and more practical with a server database but I would prefer to stick to JS for now) This...

action script 3 whole number as a division output


actionscript-3
hello, I want to get whole number after division. x = 3/2; //results x = 1 and not 1.5 how to do this in as3??...

Is there a class in AS3 that tells you the type of the URL protocol?


actionscript-3,flex,flex4
Is there a class in AS3 or Flex that tells you the type of protocol a URI or URL is part of? I was sure there was a class that broke a URL into various parts and grouped it into usable data. For example, if the URL is, "mailTo" it...

How make with AS3 downloading MP3 files in the background mode and plays it?


actionscript-3,flash
I need help with AS3 make downloading MP3 files in the background mode. Man goes to my site and it will automatically load MP3 file on his computer and plays it. I read these examples here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html but do not know how to do it? Prompt what code and how...

Bypass cases within a switch statement


java,switch-statement,case
I'm attempting to prevent additional cases within my switch statements from printing automatically when located below an initially satisfied case. Here is the code I'm building. I read previously that fallthrough is inevitable in switch statements(?) but I'm assuming there must be a way around this. System.out.println("\nQ1) What is the...

Activerecord Rails 4 perform something like a join that still returns rows that don't have the association


actionscript-3,ruby-on-rails-4,join,left-join
If after reading my question you have a suggestion for a better title, please add a comment. I was having trouble succinctly saying what I wanted. I have a situation like this. class Artist < ActiveRecord::Base has_many :album_artists has_many :albums, :through => :album_artists end class Album < ActiveRecord::Base has_many :album_artists...

AS3 Dynamic variable naming


actionscript-3,flash,variables,dynamic
Is dynamic variable naming like this possible in ActionScript 3? for (var xz=0;xz<10;xz++){ var this['name' + xz]:Number = xz; } ...

A movie clip above a simple button makes it unresponsive


actionscript-3,user-interface,flash
I have designed a menu in Flash CC which consists of several cloned buttons and an MC containing the text that is supposed to stay above the buttons. Each time a user switches the menu's page, AS commands the clip to switch to appropriate frames, therefore changing the text above...

Error #1502: A script has executed for longer than the default time period of 15 seconds


actionscript-3,flash
this is my first time using AS3 so I apologise if the cause of this problem is painfully obvious. I'm making chess and I've got a class for each piece on the board. When it's player 1's turn, all the black pieces should wait to be clicked, but when I...

AS3 - removeChild thinks it's working, but isn't removing anything (no error)


arrays,actionscript-3,removechild
This is similar to a question I asked a couple of weeks ago, but different code and previous solution is not working. In a nutshell, I'm creating an array of tiles, the size of which can be selected via a dropdown menu. I want the previous grid to be removed...

Flash CS6 / AS3: Drag and Resize a rectangle movieclip


actionscript-3,flash,resizable
Not sure if this is possible but going to ask: is there a way of being able to resize a symbol (in this case, a movie clip) in an swf file by clicking and dragging it with your cursor? One of the things I need to do is have a...

ActionScript: How to listen for an event from a different XML


actionscript-3,events,flash-builder,mxml
I have a popup screen in which the player enters their name and clicks OK. When OK is clicked I want the player's name to be passed to the main XML. How can I do this? Here is the function in the main XML that handles the popup: private function...