As3 Error Function Does Not Return A Value
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error 1170: Function does not return av value up vote -1 down vote favorite I'm new to flash and I'm making a game that's controlled with the mouse. But I'm getting this error : Error 1170: Function does not return a value. I'm trying to write a getter to return bulletType to the main.as public function get(_bulletT:String):String { for (var i = 0; i < _bulletT.length; i++) { if (_bulletT.charAt(i) == "star") { return "star"; "star"; } else { return "circle"; "circle"; } } What value is it asking for? php actionscript-3 share|improve this question edited Jan 20 '13 at 15:12 David Mear 2,1742621 asked Jan 20 '13 at 15:02 user1994811 11 Please try to explain exactly what you are trying to achieve, highlight the code with tags and format it correctly. My guess for this error is that your return statements might not be reachable if, for instance, _bulleT.length is <= 0. BTW, naming a function get(...) is a bad practice, unless you wanted it to be a getter, in which case, it should be get bulletType():String –Antoine Lassauzay Jan 20 '13 at 15:07 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote I recommend you format your codes in the future. Also, it is best not to write your code in one line since it gives no additional benefit. Your codes will be compiled into object
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 http://stackoverflow.com/questions/14425806/error-1170-function-does-not-return-av-value million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error Returning Value From Switch Case? up vote 3 down vote favorite after coding a custom event in AS3, i've come across a curious problem: override public function toString():String { switch (type) { case CHANGE: return formatToString("HistoryEvent", "type", http://stackoverflow.com/questions/4734616/error-returning-value-from-switch-case "action", "name", "data"); case ABILITY: return formatToString("HistoryEvent", "type", "undoable", "redoable"); } } the above code returns the following compile-time error: 1170: Function does not return a value. i can remedy the problem easily by adding return null; at the end of the function, but that's redundant and it annoys me that it seems to be the only solution. why is returning a value from a switch case not seen by the compiler? is this an issue specific to the AS3 compiler or am i actually attempting something here that is so completely dangerous and adverse that it shadows counterculturists the world over. actionscript-3 return switch-statement share|improve this question asked Jan 19 '11 at 11:21 TheDarkIn1978 8,576951123 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted It is possible that your switch doesn't match, and in that case the function can't return anything. That's why the compiler complains. Adding default: return null; to your switch statement so
function concepts This section discusses basic function definition and invocation techniques. Calling functionsYou call a function by using its identifier followed by the parentheses operator ( () ). You use the parentheses operator to enclose any function parameters http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f57.html you want to send to the function. For example, the trace() function, which is a top-level function in ActionScript 3.0, is used throughout this book: trace("Use trace to help debug your script"); If you are calling a function with no parameters, you must use an empty pair of parentheses. For example, you can use the Math.random() method, which takes no parameters, to generate a random number: var randomNum:Number = Math.random(); Defining your as3 error own functionsThere are two ways to define a function in ActionScript 3.0: you can use a function statement or a function expression. The technique you choose depends on whether you prefer a more static or dynamic programming style. Define your functions with function statements if you prefer static, or strict mode, programming. Define your functions with function expressions if you have a specific need to do so. Function expressions are more often used as3 error function in dynamic, or standard mode, programming. Function statementsFunction statements are the preferred technique for defining functions in strict mode. A function statement begins with the function keyword, followed by: The function name The parameters, in a comma-delimited list enclosed in parentheses The function body—that is, the ActionScript code to be executed when the function is invoked, enclosed in curly braces For example, the following code creates a function that defines a parameter and then invokes the function using the string “ hello" as the parameter value: function traceParameter(aParam:String) { trace(aParam); } traceParameter("hello"); // hello Function expressionsThe second way to declare a function is to use an assignment statement with a function expression, which is also sometimes called a function literal or an anonymous function. This is a more verbose method that is widely used in earlier versions of ActionScript. An assignment statement with a function expression begins with the var keyword, followed by: The function name The colon operator ( : ) The Function class to indicate the data type The assignment operator ( = ) The function keyword The parameters, in a comma-delimited list enclosed in parentheses The function body—that is, the ActionScript code to be executed when the function is invoked, enclosed in curly braces For example, the following code declares the traceParam