未捕获的引用错误:Haxe js 项目中未定义 $hxClasses
我遇到了一个问题,我在 Haxe IRC 频道上讨论过,但无法找到解决方案。这似乎是编译器的一个错误。
这是 Haxe 代码:
package;
import js.Lib;
import js.three.Three;
import haxe.Timer;
class Main {
public var timer:Timer;
public var renderer:WebGLRenderer;
public var scene:Scene;
public var camera:PerspectiveCamera;
public function new() {
timer = new Timer(30);
var w = Lib.window.innerWidth;
var h = Lib.window.innerHeight;
scene = new Scene();
// create a red cube
var material = new MeshLambertMaterial({color:0xff0000});
var geometry = new CubeGeometry(50, 50, 50, 1, 1, 1, material, null);
var cube = new Mesh(geometry, new MeshFaceMaterial());
cube.position.set(0, 100, 0);
scene.add(cube);
// add some light
var pointLight = new PointLight(0xffffff, 1, 0);
pointLight.position.set(10, 50, 130);
scene.add(pointLight);
// and a camera
camera = new PerspectiveCamera(70, w/h, 1, 1000);
camera.position.z = 500;
scene.add(camera);
// setup renderer in the document
renderer = new WebGLRenderer(null);
renderer.setSize(w, h);
Lib.document.body.appendChild(renderer.domElement);
untyped Lib.window.onload = onLoad;
}
public function onLoad() {
timer.run = function(){
renderer.render(scene, camera, null, null);
}
}
public static function main() {
new Main();
}
}
解决方案是让编译器将以下内容添加到它创建的 JS 文件的开头。
var $_, $hxClasses = $hxClasses || {},
目前,JS 文件中的第一行看起来像这样
$estr = function() { return js.Boot.__string_rec(this,''); }
不确定需要做什么来解决这个问题,或者除了在编译后手动添加该行之外还有其他可能的解决方法吗?
I am having an issue that I discussed on the Haxe IRC channel but was unable to come up with a fix. It seems to be a bug with the compiler.
Here is the Haxe code:
package;
import js.Lib;
import js.three.Three;
import haxe.Timer;
class Main {
public var timer:Timer;
public var renderer:WebGLRenderer;
public var scene:Scene;
public var camera:PerspectiveCamera;
public function new() {
timer = new Timer(30);
var w = Lib.window.innerWidth;
var h = Lib.window.innerHeight;
scene = new Scene();
// create a red cube
var material = new MeshLambertMaterial({color:0xff0000});
var geometry = new CubeGeometry(50, 50, 50, 1, 1, 1, material, null);
var cube = new Mesh(geometry, new MeshFaceMaterial());
cube.position.set(0, 100, 0);
scene.add(cube);
// add some light
var pointLight = new PointLight(0xffffff, 1, 0);
pointLight.position.set(10, 50, 130);
scene.add(pointLight);
// and a camera
camera = new PerspectiveCamera(70, w/h, 1, 1000);
camera.position.z = 500;
scene.add(camera);
// setup renderer in the document
renderer = new WebGLRenderer(null);
renderer.setSize(w, h);
Lib.document.body.appendChild(renderer.domElement);
untyped Lib.window.onload = onLoad;
}
public function onLoad() {
timer.run = function(){
renderer.render(scene, camera, null, null);
}
}
public static function main() {
new Main();
}
}
The solution is to get the compiler to add the following to the beginning of the JS file that it creates.
var $_, $hxClasses = $hxClasses || {},
As it stands right now the first line in the JS file looks like this
$estr = function() { return js.Boot.__string_rec(this,''); }
Not sure what needs to be done to fix this or a possible work around other than adding in that line by hand after compilation ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现问题 - Three.js 中有 Date.hx 和 Timer.hx 文件(旧版本)删除它们并且它可以工作(在我的 win 安装上它位于 c:\Motion-Twin\haxe\lib\ Three,js\0 ,2,46\ 和 c:\Motion-Twin\haxe\lib\三,js\0,2,46\haxe)
Found the issue - three.js has Date.hx and Timer.hx files in it (older versions) delete them and it works (on my win install it's in c:\Motion-Twin\haxe\lib\three,js\0,2,46\ and c:\Motion-Twin\haxe\lib\three,js\0,2,46\haxe)