11.19.07

Flex 2 / Flash CS3 ActionScript Error #1013

Posted in Error, errors, Flash, Flex at 9:28 pm by Curtis J. Morley

ActionScript Error #1013: The private attribute may be used only on class property definitions.

Description:
This ActionScript Error justs means that you have used the access control modifier 'private' in the wrong spot. There are four access control modifiers - public, private, internal, and protected. Each of these specify how the method or variable is accessed. Each access control modifier has it's own error but they all mean the same thing. Access control modifiers need to be used in the right place. The 'internal' and 'public' can only be used inside a 'package' and 'private' and 'protected' can only be used on classes. AS3 error 1013 can also be caused if you misplace a method identifier like ':void'

Fix:
Make sure to only use the 'private' access control modifier to define a method or variable within the class itself and not within a method(function).

Bad Code 1:

package{
	public class MySize {
		public function Connection():void{
			private var size:uint = 40;
			trace(size);
		}
	}
}

Good Code 1:

package{
	public class MySize {
		private var size:uint = 40;
		public function Connection():void{
			trace(size);
		}
	}
}

or

package{
	public class MySize {
		public function Connection():void{
			var size:uint = 40;
			trace(size);
		}
	}
}

Bad Code 2:

package{
	public class MySize {
		public function Connection():void{
			someFunction():void;
		}

 	private function someFunction():void{
			var size:uint = 40;
			trace(size);
		}
	}
}

Good Code 2:

package{
	public class MySize {
		public function Connection():void{
			someFunction();
		}

 	private function someFunction():void{
			var size:uint = 40;
			trace(size);
		}
	}
}

Related ActionScript Errors - AS3 Error 1114, AS3 Error 1115 , AS3 Error 1150

This ActionScript Error is a quick one. I hope this helps you solve it.

As always Happy Flashing

13 Comments »

  1. curtismorley.com » Flex 2 / Flash CS3 ActionScript Error #1150 said,

    November 21, 2007 at 5:20 am

    […] ActionScript Errors – AS3 Error 1013, AS3 Error 1114, AS3 Error […]

  2. curtismorley.com » Flex 2 / Flash CS3 ActionScript Error #1115 said,

    November 21, 2007 at 5:29 am

    […] ActionScript Errors – AS3 Error 1013, AS3 Error 1114, AS3 Error 1115 , AS3 Error 1150 This ActionScript Error is a quick one. I hope […]

  3. curtismorley.com » Flex 2 / Flash CS3 ActionScript Error #1114 said,

    November 21, 2007 at 5:30 am

    […] ActionScript Errors – AS3 Error 1013, AS3 Error 1115 , AS3 Error […]

  4. Gary said,

    December 12, 2007 at 8:29 pm

    My code looks very similar to yours but i still cant seem to find the error
    here is a sample of the code

    private function dispatchColorPicked(mouseEvent:MouseEvent):void
    {

    can you help me out

  5. Curtis J. Morley said,

    December 18, 2007 at 5:35 pm

    Gary,

    Sorry the comment field sometimes chops off the code. Could you try including the rest of the code especially the package, constructor and curly braces. Check to make sure that you don’t have any rogue braces that are misplaced and that this function is nested inside the Class.

    Let me know how it works for you and as always Happy Flashing.

    Curtis

  6. curtismorley.com » Flex / Flash ActionScript Error #1095 said,

    January 18, 2008 at 4:01 pm

    […] ActionScript Errors – AS3 Error 1094, AS3 Error […]

  7. web design blog said,

    August 20, 2008 at 2:27 pm

    In my case the problem was an if statement…

    it was something like

    if (a != b) ;
    trace(a-b);
    }

    just a syntax error after the conditional… hope it helps

  8. Student said,

    March 6, 2009 at 3:10 am

    Thanks a lot! Kepp on!

  9. AIFL said,

    August 4, 2009 at 2:11 pm

    I have the same error, but can’t seem to figure it out. Here is my code.

    package {
    import flash.display.Sprite;
    import flash.ui.Mouse;
    import flash.events.MouseEvent;
    import flash.events.Event;

    public class MouseTrailer extends Sprite {
    var lightBall:LightBall;

    public function MouseTrailer():void {
    Mouse.hide();
    stage.addEventListener(MouseEvent.MOUSE_MOVE, startTrailer);
    }

    private function startTrailer(e:MouseEvent):void {

    /* Create a new LightBall object */

    lightBall = new LightBall();

    /* Position */

    lightBall.x = mouseX + Math.random() * lightBall.width;
    lightBall.y = mouseY – Math.random() * lightBall.height;

    /* Add to Stage */

    addChild(lightBall);

    /* Add Listener to Animate function */

    lightBall.addEventListener(Event.ENTER_FRAME, animate);

    private function animate(e:Event):void {

    /* Alpha */

    e.target.alpha -= 0.05;

    /* If lightBall is no longer visible, remove it */

    if (e.target.alpha <= 0) {
    e.target.removeEventListener(Event.ENTER_FRAME, animate);

    removeChild(e.target as Sprite);
    }
    /* Scale */

    e.target.scaleX -= 0.1;
    e.target.scaleY -= 0.1;

    /* Y Position */

    e.target.y += 3;
    }
    }
    }
    }

  10. Raakhee said,

    September 8, 2009 at 7:14 pm

    Hi,

    here is my code…and its giving me error :1013 private attribute may used only class property definitions:

    on line25: private function animate(e:Event):void

    Please help!!

    code:
    package
    {
    import flash.display.Sprite;
    import flash.ui.Mouse;
    import flash.events.MouseEvent;
    import flash.events.Event;

    public class MouseTrailer extends Sprite
    {
    var lightBall:LightBall;

    public function MouseTrailer():void {
    Mouse.hide();
    stage.addEventListener(MouseEvent.MOUSE_MOVE, startTrailer);
    }
    private function startTrailer(e:MouseEvent):void {
    lightBall = new LightBall();
    lightBall.x = mouseX + Math.random() * lightBall.width;
    lightBall.y = mouseY + Math.random() * lightBall.height;

    addChild(lightBall);

    lightBall.addEventListener(Event.ENTER_FRAME, animate);

    private function animate(e:Event):void
    {
    e.target.alpha -= 0.05;
    //if lightBall is no longer visible, remove it
    if (e.target.alpha <=0)
    {
    e.target.removeEventListener(Event.ENTER_FRAME, animate);
    removeChild(e.target as Sprite);
    }
    e.target.scaleX -= 0.1;
    e.target.scaleY -= 0.1;
    e.target.y +=3;
    }
    }
    }
    }

  11. Raakhee said,

    September 8, 2009 at 7:19 pm

    wow…

    That is the same code as AIFL above me… 🙂 well probably from the same tutorial site..nevertheless the error is coming to all who use it..so there is something wrong somewhere in that code…Can someone please help correcting it.

    I am an absolute new learner so cant figure out where it is going wrong.. 🙁

    Cheers!

  12. misterbluedot said,

    October 25, 2009 at 1:25 pm

    “private function startTrailer(e:MouseEvent): void” needs a closing brace }

    When you get this error, the very first thing you should check for is typos.

  13. Wittywords said,

    January 14, 2011 at 6:54 pm

    hey!!
    i seem to get the error message 1084 sytax error: expecting identifier before lessthan. can u pls. tell mi how to rectify it!!
    thank you

Leave a Comment