ActionScript Error 1047: Parameter initializer unknown or is not a compile-time constant.ActionScript Error 1047
Description:
Let’s break down ActionScript Error 1047 into it’s various parts.
- Parameter = The variable inside the parenthesis of a function
- Initializer = An initial value set on the parameter inside the parenthesis
- Compile-time Constant = Something Flash knows the value of without evaluating
So long story short – you are trying to assign a value to a parameter that has to be evaluated. Still don’t know what I mean? Check the code examples.
This is actually a really great feature of AS3. Say for example you have an event listener that calls a function. You also want to call this same function without the event. Unless you pass a value in you will get AS3 Error 1136. AS3 allows you to set the Event parameter to null and therefore accept a call to that function without passing in a parameter. function myUtilFunc( e:Event = null);
You can initialize and function with any Compile time constant for example a string like “Happy”, a constant like null or an int like 5 but you can not throw in anything that needs to be evaluated like a variable, math operation, an in-line array like [a,b,c] or date.
Flex / Flash Error #1047 Fix:
Remove any variable data and use only constants in the initializer such as Strings, Numbers, Null, etc…
Bad Code:
var init:String = “Happy”
function bob(someValue:String = init){
trace(someValue);
}
Good Code:
function bob(someValue:String = “Happy”){
trace(someValue);
}
or
function multiFunction(e:Event = null){
//doSomething;
}
Related Errors:
This should help you resolve Flex / Flash Error #1047
Thanks and as always Happy Flashing
Curtis J. Morley