Problem with es6 project


#1

Doing yo openfl and selecting es6 creates a project that throws :
uncaught exception: Error: Error #3783: A Stage object cannot be added as the child of another object.

tested on latest firefox.

es5 generated proj seems ok though.


#2

Was happening to me too, I added

import Lib from "openfl/Lib";

to the imports.


#3

That was weird, I just added that import line and it still throws the same.


#4

I removed the line, and now keeps working. So I have no idea what’s going on.
The only thing I did was running a couple of samples (AddingAnimation and UsingSWF assets), then tried what I mentioned, and saw it working.


#5

I just noticed I can use jquery in the middle of it all.
Kind of just feeling around what can be done.
Looking for an onResize equivalent…
Better go browse the samples.
Thanks.


#6

Hey guys,

I realized that the wildcard OpenFL version number in our samples means that NPM can sometimes install something old from cache ("openfl": "*")

If you have trouble, try running npm install openfl or npm install --save-dev openfl from the sample directory, to be sure you are using the latest version

Let me give ES6 another try real quick, but I’m pretty sure this might be the issue

EDIT: OH, I figured it out :blush:

Reinstall generator-openfl

npm install -g generator-openfl

The ES6 template was broken:

import Sprite from "openfl/display/Stage";
import Stage from "openfl/display/Stage";

It should be “openfl/display/Sprite” :blush:

Thanks guys


#7

Thanks for the fix.
So basically npm can be used to add possible imports into the app, I just randomly tried jquery and it worked…
plus es6 doesn’t seem so foreign to me.


#8

On the spectrum, I would say it is like this:

Haxe -> TypeScript -> ES6 -> ES5

Haxe requires extern classes (or untyped) to use external libraries, but has added features over JavaScript, type checking, rarely requires this and other bonuses.

TypeScript is very very similar to ES6 JavaScript, is sometimes harder to integrate with JS code than ES6 or ES5, but gets good code completion and type checking, and has definitions available for most popular libraries. It does require this a lot (as EcmaScript does) and doesn’t add Map, abstract, Int, Float and other Haxe features.

ES6 JavaScript is a lot like TypeScript, but without types. I suppose that’s sort of the idea of the name TypeScript :wink:

ES5 is JavaScript we all know and love (or hate?) … it hasn’t changed in a long time, and scope is sometimes a problem, but mostly is a benefit because it does not require as much post-processing to run on older browsers, otherwise ES6/TypeScript/Haxe seems better for workflow