Class Not Found Exception When Importing a Class: Haxe (With OpenFL + Flixel libraries)

1.2k views Asked by At

I've been starting to fiddle around with HaxeFlixel recently and when trying to make a real simple game, I come across this error:

source/PlayState.hx:10: characters 7-16 : Class not found : GameLogic

Now this isn't my first foray into programming games or anything, but I have no clue why this error is popping up. For starters, GameLogic isn't even a class, it's a package. The error comes up when I try to import my basic Player class from my GameLogic package.

My Basic Player Class:

 package GameLogic;

 import flixel.FlxSprite;
 import flixel.util.FlxColor;

 class Player extends FlxSprite {

     public function new(X:Float=0, Y:Float=0) {
         super(X, Y);
         makeGraphic(32, 32, FlxColor.WHITE);
     }

 }

Where the exception is thrown:

     import GameLogic.Player;

 class PlayState extends FlxState{

     private var p:Player;

     override public function create():Void{
         p = new Player(20, 20);
         add(p);
         super.create();
     }

My [relevant] directory Structure:

  | src
  | | GameLogic
  | | | Player.hx
  | | PlayState.hx
1

There are 1 answers

0
JensG On BEST ANSWER

As the Haxe docs states:

Each part of the path in package names must begin with a lower case letter and, like all types, type names in packages must begin with an upper case letter. Hence My.Pack is an invalid package, as is my.Pack. Similarly, my.pack.e would not be a valid type name or import

you have to name your package gameLogic with a lowercase G to be recognized as proper package name. The relevant parts in the up-to-date docs read slightly more complicated, but in essence mean the same with regard to this question:

Define: Module

All Haxe code is organized in modules, which are addressed using paths. In essence, each .hx file represents a module which may contain several types. A type may be private, in which case only its containing module can access it.

The distinction of a module and its containing type of the same name is blurry by design. In fact, addressing haxe.ds.StringMap can be considered shorthand for haxe.ds.StringMap.StringMap. The latter version consists of four parts:

  1. the package haxe.ds
  2. the module name StringMap
  3. the type name StringMap
  4. the type parameter Int

The algorithm for name resolution is outlined here in more detail.