10.13.08

AS3 Compiler Error# 1021: Duplicate function definition.

Posted in Adobe, Error, Error, errors, Flash, Flash 10, Flex at 10:47 pm by Curtis J. Morley

AS3 Compiler Error# 1021: Duplicate function definition..

AS3 Error 1023 Description:

This ActionScript error is the most terse error that AS3 has provided us.  It is nothing like AS3 Warning 1090 It popped up, rearing it's ugly head like a teenager on Halloween. In most cases this error has more to do with AS3 Error 1021 than it does with an incompatible override.  Sometimes it realy does mean that you have an override that is incompatible but many times it just means that you have a function that is named the same as

Flex / Flash Error #1021 Fix:

Do exactly what the message says use an event listener instead of the onRelease event that was common in AS2.

Bad Code 1:

function bob () {
}

function bob () {
}

Good Code 1:

function bob () {
}

function jim () {
}

Bad Code 2:

var myArray:Array = [1,2,3];

function myArray () {
}

Good Code 2:

var myArray:Array = [1,2,3];

function myArrayFunction () {
}

Related Errors:

AS3 Error 3596
AS3
Compiler Error 1023
AS3 Error 1023 (Different error same number.  This one has nothing to do with error 1021)

This should help you resolve Flex / Flash Warning #1021

Thanks and as always Happy Flashing

Curtis J. Morley

7 Comments »

  1. curtismorley.com » Flex / Flash Compiler Error #1023: Incompatible override. said,

    October 22, 2008 at 11:28 pm

    […] rearing it’s ugly head like a teenager on Halloween. In most cases this error has more to do with AS3 Error 1021 than it does with an “Incompatible override”.   The first example below demonstrates this […]

  2. curtismorley.com » ActionScript Error 1047: Parameter initializer unknown or is not a compile-time constant. said,

    October 23, 2008 at 3:05 pm

    […] AS3 Error 1184 […]

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

    October 23, 2008 at 4:05 pm

    […] AS3 Error 1047 […]

  4. Taylor said,

    November 25, 2008 at 1:25 am

    I started getting this message when writing custom classes. I couldn’t find where I had duplicated the definition. Apparently this error applies to the getter/setter functions as well:

    private var _prop:Ojbect;
    public var prop:Object // <– This is where the first definition is. C/C++ prototyping conventions are messing with my head!

    public function get prop():Object {

    }

  5. Jeannie said,

    December 18, 2008 at 7:35 pm

    The same happens for me (can’t find a duplicate function. Line 1 of the AS3 below is where it points the error to:

    var gradTypeA:String = GradientType.LINEAR;
    var matrix:Matrix = new Matrix();
    //method added to the Matrix class
    //deg2rad(90) is the degreee-to-radian conversion
    matrix.createGradientBox(1014, 590, deg2rad(90), 0, 0);
    var colors:Array = [0xFF0000, 0x000000];
    var alphas:Array = [1, 1];
    //2nd number determins diameter of inner light
    var ratios:Array = [0, 255];
    var canvas = new Sprite();
    //matrix added to the fill creation
    canvas.graphics.beginGradientFill(gradTypeA, colors, alphas, ratios, matrix);
    canvas.graphics.drawRect(0, 0, 1014, 590);
    canvas.x = 4;
    canvas.y = 178;
    //canvas.x = canvas.y = 100;
    addChild(canvas);

    function deg2rad(deg:Number):Number {
    return deg * (Math.PI/180);
    }

    I don’t have any errors until I add my custom classes when bringing in an XML gallery. I haven’t used gradTypeA anywhere else. I am wondering if you came up with any solution? I would be most grateful if you felt free to share it.

  6. srawr42 said,

    March 26, 2009 at 2:06 am

    Hello,

    I am attempting to make an image map with various external links
    I am using the code below. It works fine when I have only one button on a page, however when I attempt to link more than one button it gives me this error.

    button.addEventListener(MouseEvent.CLICK, callLink);

    function callLink (event: MouseEvent) :void {
    var url:String = (“http://www.google.com”);
    var request:URLRequest = new URLRequest (url);
    try { navigateToURL (request, “_blank”);
    } catch (e:Error) {
    trace (“Error occurred!”);
    }
    }

    I can’t seem to figure out what it is I need to change.
    I named all my buttons and changed the name in the script, but to no avail.

    Any help would be more appreciated.

  7. Sherry Street said,

    March 14, 2011 at 1:39 pm

    I have searched high and low – can’t find a reason for the errors I am receiving:
    1023: Incompatible override and 1021:duplicate function definition

    The errors begin with line 16 – the second function line and repeat for every function line. Here is my code:

    stop();

    var welcome_req:URLRequest = new URLRequest(“welcome.swf”);
    var brochure_req:URLRequest = new URLRequest(brochure.pdf”);
    var slideshow_req:URLRequest = new URLRequest(“slideshow.swf”);
    var contact_req:URLRequest = new URLRequest(“contact.swf”);
    var video_req:URLRequest = new URLRequest(“video.swf”);
    var flight_req:URLRequest = new URLRequest(“flight.swf”);
    var safety_req:URLRequest = new URLRequest(“safety.swf”);

    function welcome(event:MouseEvent):void
    {
    navigateToURL(welcome_req, “_self”);
    }

    function brochure(event:MouseEvent):void
    {
    navigateToURL(brochure_req, “_self”);
    }

    function slideshow(event:MouseEvent):void
    {
    navigateToURL(slideshow_req, “_self”);
    }

    function contact(event:MouseEvent):void
    {
    navigateToURL(contact_req, “_self”);
    }

    function video(event:MouseEvent):void
    {
    navigateToURL(video_req, “_self”);
    }

    function flight(event:MouseEvent):void
    {
    navigateToURL(flight_req, “_self”);
    }

    function safety(event:MouseEvent):void
    {
    navigateToURL(safety_req, “_self”);
    }

    welcome_btn.addEventListener(MouseEvent.CLICK, welcome);
    brochure_btn.addEventListener(MouseEvent.CLICK, brochure);
    slideshow_btn.addEventListener(MouseEvent.CLICK, slideshow);
    contact_btn.addEventListener(MouseEvent.CLICK, contact);
    video_btn.addEventListener(MouseEvent.CLICK, video);
    flight_btn.addEventListener(MouseEvent.CLICK, flight);
    safety_btn.addEventListener(MouseEvent.CLICK, safety);

    Any help would be appreciated!

Leave a Comment