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
It also seems as though you can’t initialise with a Class – even though it’s not assigned to a var for example:
public class SuperHero extends Sprite
{
public function SuperHero(abilities:Class=XrayVision)
{
}
}
Hello, I came across your blog and I thought you may be able to help with my issue.
Operating system: Widows Vista
Architecture: 64-bit
Browser: Internet Explorer 8
Player version: WIN 10,1,53,64
Url: http://www.urbancitylifetv.com
Files located in webroot: slideshowpro.swf and param.xml
Second website url: http://www.tunerlifestyletv.com (works fine with the same exact setup?)
Flash content on my website worked previously installing the latest version of Flash. After upgrading to the latest version of Adobe Flash I get the message (notice the double slash after the url):
Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://www.urbancitylifetv.com//slideshowpro.swf cannot load data from http://www.urbancitylifetv.com//param.xml.
at net.slideshowpro.sspstandalone::XMLParser/loadParamXML()
at net.slideshowpro.sspstandalone::XMLParser/initListeners()
at net.slideshowpro.sspstandalone::XMLParser/init()
at net.slideshowpro.sspstandalone::XMLParser()
at net.slideshowpro.sspstandalone::SSPLoader/loadParamXML()
at net.slideshowpro.sspstandalone::SSPLoader/init()
at net.slideshowpro.sspstandalone::SSPLoader()
First crossdomain tried:
Result: Did not work
Second crossdomain tried:
Result: Did not work
Global Security settings adjusted appropriately
Result: Did not work
I need help on resolving this issue. If there is no solution, can I install a previous version?
Ok, I understand the error and the reasoning behind it (most of the time). My question is whats the best way to get around it? I run into plenty of situations where I would like a work around to this. A good example would be something like a default target, or target path. Should I just set the value to “null” and then nest an “if (null)”,”else”? or is there a better way?
This won’t fix all cases. There is a known bug in Flash where you try to initialize a parameter with a true constant imported from another file but you get this error. It’s intermittant. When I initialize with constants, I’ll many times get this error. A second recompilation (without changing anything) will work fine 90% of the time**. It appears that there is a problem with flash importing names (in at least Flash CS4).
how to you use [arrays] as Initializer ??
Pingback: curtismorley.com » ActionScript Error 1184: Incompatible default value of type int where String is expected.