Copy link to clipboard
Copied
In the following code I get an error. How to solve this?
Line 30 | 1013: The private attribute may be used only on class property definitions. |
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Caesar extends MovieClip
{
var velocity:Number;
public function Caesar()
{
addEventListener("enterFrame"), move;
}
public function move(e:Event)
{
this.x = mouseX;
this.y = mouseY;
if (caesar.hitTestObject(MainClip.instance.enemyList))
{
trace ("caesar geraakt");
removeSelf();
MainClip.instance.finishedMainClip();
}
}
}
private function removeSelf():void
{
removeEventListener(Event.ENTER_FRAME, move);
if (stage.contains(this))
{
this.parent.removeChild(this);
}
}
}
Check your indents... Your removeSelf function is outside of the class definition... that closing brace before it should be after it.
Copy link to clipboard
Copied
Check your indents... Your removeSelf function is outside of the class definition... that closing brace before it should be after it.
Copy link to clipboard
Copied
Then I get the following errors:
Line 12 | 1136: Incorrect number of arguments. Expected 2. |
Line 20 | 1120: Access of undefined property caesar. |
Line 20 | 1120: Access of undefined property i. |
Copy link to clipboard
Copied
Those are not a result of fixing the first, they are just more errors found after fixing the first.
If you look at line 12 and don't see the problem, spend more time looking at it and how to add an event listener.
As for the other two... the errors are telling you your class does not know what caesar and i are. If you do not define them for the class then they will be undefined.
Copy link to clipboard
Copied
You have an extra curly bracket before removeSelf() method and missing bracket at the end. The class should look like this:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Caesar extends MovieClip
{
private var velocity:Number;
public function Caesar()
{
addEventListener("enterFrame"), move;
}
public function move(e:Event)
{
this.x = mouseX;
this.y = mouseY;
if (caesar.hitTestObject(MainClip.instance.enemyList))
{
trace("caesar geraakt");
removeSelf();
MainClip.instance.finishedMainClip();
}
}
private function removeSelf():void
{
removeEventListener(Event.ENTER_FRAME, move);
if (stage.contains(this))
{
this.parent.removeChild(this);
}
}
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now