New to BabylonJS, can't get GUI.js to work

HI,
Just joined, been experimenting with Babylon.js for a month or so now. I tried to copy some code from the playground ( https://playground.babylonjs.com/#AY28VL#4 ) to my machine and run it but the GUI.js file doesn’t seem to be loading correctly.

Here’s the code where it blows up:

    var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
    var colorArray = ["white", "blue", "green", "black", "red"];

    // Activate the clipboard events listener
    advancedTexture.registerClipboardEvents();

With the error:
“Uncaught TypeError: advancedTexture.registerClipboardEvents is not a function”

Do I have to use npm and install BABYLON.GUI.js to use the GUI library?
Do I have to install webpack too?

What I tried was

which works for babylon.max.js but not the GUI…

(Been trying to learn npm and import/export but haven’t got there yet.)

thanks in advance

oops,
what I meant to say was:

What it tried was:



hmmm?

what I tried to do was include the files in a script tag (which won’t display here?)
src=“babylon.max.js”
src=“babylon.gui.js”

Hey and welcome Larry!

Can you make sure that you are referecing GUI and Babylon.js from the same url?
like:

<script src="https://preview.babylonjs.com/babylon.js">
<script src="https://preview.babylonjs.com/gui/babylon.gui.js">

Deltakosh,

thanks, that does work but fails when I change “//preview…” to “//cdn…”
for example:
"src=‘https://preview.babylonjs.com/gui/babylon.gui.js’ "
to
"src=‘https://cdn.babylonjs.com/gui/babylon.gui.js’ "

Also, when I download these files to my local wwwroot directory the preview files work but the cdn files fail.
Error:
ClipboardText.html:97 Uncaught TypeError: advancedTexture.registerClipboardEvents is not a function

The variable “advancedTexture” is a valid instantiated object and I can see all it’s properties, but “registerClipboardEvents” does not exist in the babylon.gui.js file as loaded into the browser. (I’m using Chrome)

Does that suggest an error in the UniversalModuleDefinition ???

The code is a direct copy from the playground example:
https://playground.babylonjs.com/#AY28VL#4
(errors on line 29)

thanks

You have to take everything either from preview or cdn but you cannot do a mix

Yes, I took both from either CDN or PREVIEW

thanks

Oh, I case my above reply wasn’t clear, it still failed when I took them both from CDN.

OK I’m stupid :slight_smile:
Clipboard access is only on 4.0 (so only preview :))

4.0 will be released tomorrow :slight_smile:

Great!

thanks a lot!