10.15.08

ActionScript Error 1047: Parameter initializer unknown or is not a compile-time constant.

Posted in Adobe, Error, Error, errors, Flash, Flash 10, Flex at 6:25 am by Curtis J. Morley

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.

  1. Parameter = The variable inside the parenthesis of a function
  2. Initializer = An initial value set on the parameter inside the parenthesis
  3. 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:

AS3 Error 1184

This should help you resolve Flex / Flash Error #1047

Thanks and as always Happy Flashing

Curtis J. Morley

6 Comments »

  1. curtismorley.com » ActionScript Error 1184: Incompatible default value of type int where String is expected. said,

    October 23, 2008 at 3:07 pm

    […] AS3 Error 1047 […]

  2. flash programming said,

    June 12, 2009 at 11:51 pm

    how to you use [arrays] as Initializer ??

  3. Alexander Collins said,

    October 23, 2009 at 5:22 pm

    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).

  4. matthew said,

    January 18, 2010 at 3:39 pm

    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?

  5. Dexter said,

    June 24, 2010 at 3:28 pm

    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?

  6. Frank said,

    February 8, 2013 at 3:19 am

    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)
    {
    }
    }

Leave a Comment