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

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 thoughts on “AS3 Error #1126: Function does not have a body.

  1. 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 🙂

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

    }

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

    }
    }

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

  4. 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!

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

Comments are closed.