Annoying weird error came out of nowhere [SOLVED]


(John Andersson) #1

I was trying to fix the way my game handles music, and I must have f’d something up.

Now when I try to run the game, I get this error from the gameworld:

GameWorld.as(1969): col: 10 Error: The static attribute may be used only on definitions inside a class.

which is

public static function stopMusic():void
	{
		Music.1.stop();
		Music.2.stop();
	}

What the hell man? That static function worked just fine until I did something wrong?

Here is a simplified gameworld.as.

package game
{
public class GameWorld extends World
{

	private var _map_ground:Tilemap;
	public var collisionData:Grid;
	public var jumpareaData:Grid;
	public var levelchangeData:Grid;
	public var cinematicAreaData:Grid;
	private var _rawMapData:Class;
	private var _tileset:Class;

	public function GameWorld(tileset:Class)
	{
		_tileset = tileset
		
		p1viewport = new BitmapData(480, 135);
		p2viewport = new BitmapData(480, 135);
	}
	
	override public function begin():void
	{
		super.begin();
		add(lighting);
		//HUD
		add(hud);
		FP.world.add(new Music);
	}
	
	override public function update():void
	{
	
		super.update();
	}
	
	public function setNewMap(map:Class, tileset:Class):void 
	{
		_rawMapData = map;
		loadLevel(_rawMapData, _tileset);
	}
	
	public function loadLevel(levelNumber:Class, tileset:Class):void
	{

		var tileSet:Class = tileset
		var mapXML:XML = FP.getXML(levelNumber);
		var mapWidth:uint = uint(mapXML.@width);
		var mapHeight:uint = uint(mapXML.@height);
		var tileX:uint = 0;
		var tileY:uint = 0;
		
		//BG
		if (currentLevel != 6 )
		{
			Draw bg stuff here	
		}

		collisionData = new Grid(mapWidth * 16, mapHeight * 16, 16, 16);
		jumpareaData = new Grid(mapWidth * 16, mapHeight * 16, 16, 16);
		levelchangeData = new Grid(mapWidth * 16, mapHeight * 16, 16, 16);
		cinematicAreaData = new Grid(mapWidth * 16, mapHeight * 16, 16, 16);
		

		_map_ground = new Tilemap(tileSet, mapWidth * 16, mapHeight * 16, 16, 16);
		
		for each (var layer:XML in mapXML.layer)
		{
			var XMLlayers:String = layer.attribute("name");
			switch (XMLlayers)
			{
					

				case "Ground": 
					tileX = 0;
					tileY = 0;
					for each (tile in layer.data.tile)
					{ 
						if (tileX >= mapWidth)
						{
							tileX = 0;                      
							tileY++;
						}
						
							if (tile.@gid != GID_Leaves )
							{
							
									collisionData.setTile(tileX, tileY, true);
									_map_ground.setTile(tileX, tileY, uint(tile.@gid - 1));
							}
				

						tileX ++;
					}
					break;
			}
		}
	
		addGraphic(_map_ground, -2);
		
		updateCollision();
	}
	
	public function updateCollision():void
	{
		var collision_:Collision = FP.world.getInstance("collision");
		if (collision_ == null)
			FP.world.add(new Collision(0, 0, null, collisionData))
		else
		{
			FP.world.remove(collision_)
			trace("updating collision")
		}
		
		var jumparea_:JumpArea = FP.world.getInstance("jumparea");
		if (jumparea_ == null) FP.world.add(new JumpArea(0, 0, null, jumpareaData))
		else
		{
			FP.world.remove(jumparea_)
			trace("updating jump areas")
		}
		
		var levelchange_:Levelchange = FP.world.getInstance("lvlchange");
		if (levelchange_ == null)
		{
			var newLvlChange:Levelchange = new Levelchange(0, 0, null, levelchangeData)
			FP.world.add(newLvlChange)
		}
		else
		{
			FP.world.remove(levelchange_)
			trace("updating level change areas")
		}		
		
		var cinematic_:CinematicArea = FP.world.getInstance("cmtcarea");
		if (cinematic_ == null)
		{
			var newCinematicArea:CinematicArea = new CinematicArea(0, 0, null, cinematicAreaData)
			FP.world.add(newCinematicArea)
		}
		else
		{
			FP.world.remove(levelchange_)
			trace("updating cinematic areas")
		}
	}
	
	public static function stopMusic():void
	{
		Music.1.stop();
		Music.2.stop();
		Music.3.stop();
		Music.4.stop();
		Music.5.stop();
		Music.6.stop();
		Music.7.stop();
		Music.8.stop();
	}
}

}


(Zachary Lewis) #2

Variable names can’t start with a digit. Try changing Music.1 to something like Music.song1.


(John Andersson) #3

I changed the name to something random, it doesn’t start with a digit


(Martí Angelats i Ribera) #4

You have to make a class called Music inside a file called Music.as and declare the static variables and set them.

package
{
	public class Music
	{
		public static var music1:Sfx = new Sfx(/*args*/);
		music1.property = value;
		
		public static var music2:Sfx = new Sfx(/*args*/);
		music2.property = value;
		music2.function();
		
		//etc.
	}
}

I think you get the idea.


(John Andersson) #5

An extra bracket caused this error.

:laughing: