Copy link to clipboard
Copied
When i was younger i programmed in fortran and pascal. I was ok at it. Now i am trying to learn to make games with flash. i started about threes weeks and have been reading the forums and flash help file but when i try to make my own class it either say i need a package or that the class cannot be nested. i'm sure it is some stupid little thing i need to my it work. here is my code:
class Enemy
{
// variable Declarations
var enemyHealth:int
var enemyName:String
var enemyDefence:int
var enemyAttack:int
var enemyDead:Boolean
// constructer
function enemy (enemyHealth:int,enemyName:String,enemyDefence:int,enemyAttack:int,enemyDead:Boolean)
{
this.enemyHealth = enemyHealth;
this.enemyName = enemyName;
this.enemyDefence = enemyDefence;
this.enemyAttack = enemyAttack;
this.enemyDead = enemyDead;
}
// get function to display in textboxes
public function getEnemyHp():int
{
return enemyHealth;
}
public function getEnemyName():String
{
return enemyName;
}
public function getEnemyDef():int
{
return enemyDefence;
}
public function getEnemyAtt():int
{
return enemyAttack;
}
public function getEnemyDead():int
{
return enemyDead;
}
}
This the only thing in the flash project, no graphics, no textboxes, nothing.
the compiler gives this error:
1131: Classes must not be nested.
if any one know of a previous post (so don't have re-explain )or can explain what i need to look for in the help files i would be very thankful.
Copy link to clipboard
Copied
Where are you trying to place this code. If you are making classes, then create them as separate .as files. If you are trying to code inside the fla file, then do not use class-based syntax (class, public, etc). If your are trying to code this as a class file it should look like...
package {
public class Enemy extends MovieClip {
// variable Declarations
var enemyHealth:int
var enemyName:String
var enemyDefence:int
var enemyAttack:int
var enemyDead:Boolean
// constructer
public function Enemy (enemyHealth:int,enemyName:String,enemyDefence:int,enemyAttack:int,en emyDead:Boolean){
this.enemyHealth = enemyHealth;
this.enemyName = enemyName;
this.enemyDefence = enemyDefence;
this.enemyAttack = enemyAttack;
this.enemyDead = enemyDead;
}
// get function to display in textboxes
public function getEnemyHp():int {
return enemyHealth;
}
public function getEnemyName():String {
return enemyName;
}
public function getEnemyDef():int {
return enemyDefence;
}
public function getEnemyAtt():int {
return enemyAttack;
}
public function getEnemyDead():int {
return enemyDead;
}
}
}
and you need to save the file using the file name: Enemy.as, and either store the file in the same folder as the fla file (easiest for now), or within your classpath (probably can wait to learn what/how)