在Haxe导入本地课程

时间:2015-07-15 19:39:14

标签: class haxe openfl

我在Haxe开始了我的第一个认真项目,但是我遇到了一些障碍。

问题是,如果我尝试在除Main.hx之外的文件中编写类,则不会编译它。我尝试过使用导入,但似乎没有用。

我使用vim作为我的ide以及一些不错的插件(Youcompleteme,syntastic和vaxe),唯一的haxelib是openfl。

以下是使用命令openfl create project时创建的样板文件:

project.xml中

<?xml version="1.0" encoding="utf-8"?>
<project>

    <meta title="ProjetSession" package="com.sample.projetsession" version="1.0.0" company="Company Name" />
    <app main="Main" path="Export" file="ProjetSession" />

    <source path="Source" />

    <haxelib name="openfl" />

    <assets path="Assets" rename="assets" exclude="openfl.svg" />
    <icon path="Assets/openfl.svg" />

</project>

ProjetSession.hxproj

<?xml version="1.0" encoding="utf-8"?>
<project version="2">
  <!-- Output SWF options -->
  <output>
    <movie outputType="CustomBuild" />
    <movie input="" />
    <movie path="project.xml" />
    <movie fps="30" />
    <movie width="800" />
    <movie height="600" />
    <movie version="1" />
    <movie minorVersion="0" />
    <movie platform="Lime" />
    <movie background="#FFFFFF" />
    <movie preferredSDK=";3;" />
  </output>
  <!-- Other classes to be compiled into your SWF -->
  <classpaths>
    <class path="D:\Development\Haxe\openfl" />
    <class path="d:\Development\Haxe\lime" />
    <class path="Source" />
    <class path="Export\html5\haxe" />
  </classpaths>
  <!-- Build options -->
  <build>
    <option directives="openfl=3.0.0-beta&#xA;lime=2.1.3&#xA;tools=2.1.3&#xA;no-compilation&#xA;openfl-html5&#xA;canvas&#xA;lime-html5&#xA;html5&#xA;web&#xA;html5" />
    <option flashStrict="False" />
    <option noInlineOnDebug="False" />
    <option mainClass="ApplicationMain" />
    <option enabledebug="False" />
    <option additional="--remap flash:openfl&#xA;--macro allowPackage(&quot;flash&quot;)" />
  </build>
  <!-- haxelib libraries -->
  <haxelib>
    <!-- example: <library name="..." /> -->
  </haxelib>
  <!-- Class files to compile (other referenced classes will automatically be included) -->
  <compileTargets>
    <!-- example: <compile path="..." /> -->
  </compileTargets>
  <!-- Paths to exclude from the Project Explorer tree -->
  <hiddenPaths>
    <hidden path="obj" />
  </hiddenPaths>
  <!-- Executed before build -->
  <preBuildCommand>"$(CompilerPath)/haxelib" run lime build "$(OutputFile)" $(TargetBuild) -$(BuildConfig) -Dfdb</preBuildCommand>
  <!-- Executed after build -->
  <postBuildCommand alwaysRun="False" />
  <!-- Other project options -->
  <options>
    <option showHiddenPaths="False" />
    <option testMovie="Custom" />
    <option testMovieCommand="" />
  </options>
  <!-- Plugin storage -->
  <storage />
</project>

hml文件由vaxe自动生成。

1 个答案:

答案 0 :(得分:2)

定义一个类并导入它,在输出中编译该类是不够的。你需要的是实际上&#34;使用&#34;它。这可以通过在main函数中引用您的课程来完成。要做到这一点,只需直接使用该类或使用直接或间接引用该类的任何其他代码。 这是一种语言的一大优势,它不会使用不需要的代码重载应用程序的输出。这也意味着您可以放心使用第三方库,因为您知道只有您使用的库的位将嵌入到您的输出中。