Call a method from outside the method's parent class/package?

  • Still pretty new so I'm not sure if what I'm asking is possible but I think it should be. I have a package (I think? the one ending in .hx) with a class, call it 'package1' and 'class1'. Within class1, I have method1. I want to call method1 from inside a different package, package2. Can I? How?

    Here's what I have so far, but I get a "Class x has no field y" error.

    In package1:

    class class1 extends FlxState
    	public function method1():Void
    		//do something

    In package2:

    class class2 extends FlxState
    	var x: class1 = new class1();

  • Except for the typical usage of FlxState objects being with FlxG.switchState(), it looks all right to me syntax-wise. Did you import package1 at the top of your package2 file?

  • administrators

    .hx files are not packages, they're modules. Also, you're not allowed to start type names with a lowercase letter in Haxe, you should be getting an error like Type name should start with an uppercase letter.

  • @Gama11 True say on both counts, thanks for the correction. I suppose bambi replaced the real names of the classes with generic ones, otherwise that would be the error received.

Log in to reply