01.03.09

AS3 Error #1126: Function does not have a body.

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

ActionScript Error 1126: Function does not have a body.

ActionScript Error 1126 Description:

I got this error from one of my UVU students code.  And as promised in honor of her I am thusly naming AS3 Error 1126 the Erin Johnson Error.  This error is given, in this case, because a semicolon is used instead of a colon after the parenthesis.  A semicolon in the ActionScript language is equivalent to a period in the English Language which means that if Flash sees the semicolon it says to the compiler finish this line of code and move on. The colon on hte other hand is used to say what Type something is or in the examples below what "Type" of data will be returned when the function is called. In the example below we don't want to return a type so we use :void (notice the colon). This should help solve AS3 Error 1126.

 

Flex / Flash Error #1126 Fix:
Replace the semicolon with a colon.

Bad Code 1:

function someFunc(event:MouseEvent);void
{
doSomething();
}

Good Code 1:

function someFunc(event:MouseEvent):void
{
doSomething();
}

Related Errors:

ActionScript Error 1084: Syntax error: expecting colon before leftparen. This error is a psuedo error in this case because once AS3 Error 1126 is reslved this error will also disappear.

This should help you resolve Flex / Flash Error #1126

Thanks and as always Happy Flashing

Curtis J. Morley

6 Comments »

  1. phihochzwei said,

    January 15, 2009 at 3:35 pm

    Hi Curtis,

    would it be okay for you, if we translate your error list texts into german and use it on our user group? Because I think they are very helpful, but unfortunately only for those who speak english 🙁

    Kind regards,

    Jens

  2. Erin said,

    January 15, 2009 at 10:39 pm

    Yay! My shift key bows humbly.

  3. Christopher J. Rock said,

    February 9, 2009 at 12:55 pm

    Not to be picky, but you’ve got colons and semicolons reversed there. It’s the semicolon that as3 likes and the colon it don’t.

    By the way, you’re sites come in plenty handy on my projects. Thanks!

  4. Christopher J. Rock said,

    February 23, 2009 at 6:53 pm

    Oh, I just saw I was thinking of a different error. I thought this was the semicolon at the end of a line.

    Just saw the example. If that was there before, I didn’t notice it.

  5. DelGee said,

    September 28, 2010 at 8:35 am

    below is my code. so when i click on the object, it displays a message – that part doesnt work.

    package
    {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    public class U1A3_GreetingsMethods extends MovieClip
    {
    private var _origXScale:Number;
    private var _origYScale:Number;
    public function U1A3_GreetingsMethods()
    {
    _origXScale = this.scaleX;
    _origYScale = this.scaleY;
    this.addEventListener(MouseEvent.ROLL_OVER, grow);
    this.addEventListener(MouseEvent.ROLL_OUT, shrink);
    this.addEventListener(MouseEvent.MOUSE_DOWN, showMessage);
    }
    private function grow(event:MouseEvent):void
    {
    this.scaleX *= 1.5;
    this.scaleY *= 1.5;
    }
    private function shrink(event:MouseEvent):void
    {
    this.scaleX = _origXScale;
    this.scaleY = _origYScale;
    }

    ////i dont know what to do to make it so when i click down on it the message appears/////
    public function showMessage();
    {
    var myMessage:TextField=new TextField();
    myMessage.text=”Bonjour! Ca va?”;
    addChild(myMessage);

    }

    ////////////

    }
    }

  6. Trait said,

    February 5, 2012 at 6:50 am

    depending on your level of as3 knowledge its possible for this error to occur for a different reason…

    a3.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
    function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
    var loader:SWFLoader = new SWFLoader(“bfbdcarouselv1.swf”, {container:this, alpha:0, onComplete:completeHandler});
    …and so on…

    the same error is given for this code for line 2 and a colon was used. I’m a beginner and while trying to splice bits of code together forgot to put a left bracket around the VAR

    a3.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
    function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
    {
    var loader:SWFLoader = new SWFLoader(“bfbdcarouselv1.swf”, {container:this, alpha:0, onComplete:completeHandler});
    …and so on..

    That code returned no error.
    Although the solution was not what you mentioned your simple example pointed out the fact that I had missed something.

    Thanks 🙂

Leave a Comment