Class not found Exception on class import: Haxe (with OpenFL + Flixel libraries)

I've been starting to come across HaxeFlixel a lot lately and when I try to make a real simple game I run into this error:

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

      

Now this is not my first foray into PC games or whatever, but I don't know why this error appears. For starters, GameLogic is not even a class, but a package. The error occurs when I try to import the main Player class from my GameLogic package.

My main 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);
     }

 }

      

If an 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 [corresponding] directory Structure:

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

      

+3


source to share


1 answer


As the Haxe docs states:

Each path portion in package names must begin with a lowercase letter and, like all types, type names in packages must begin with an uppercase letter. Hence My.Pack is an invalid package, just like my.Pack. Likewise, my.pack.e will not be a valid type name, or will import

you must name your package in gameLogic

lowercase G

to be recognized as a valid package name. The relevant parts in the updated docs read a little more complex, but essentially mean the same in regards to this question:



Define: Module

All Haxe code is organized in modules, which are viewed using a path. Basically, each .hx file is a module that can contain several kinds. A type can be private, in which case only its containing access to it.

The distinction between a module and its type with the same name is blurry in design. In fact, referring to haxe.ds.StringMap can be considered shorthand for haxe.ds.StringMap.StringMap. The latest version has four parts:

  • haxe.ds package
  • the name of the StringMap module
  • the name of the StringMap type
  • parameter of type Int

Following is the name resolution algorithm here .

+3


source







All Articles