Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
how to access properties in another module in JavaScript?

I have one module called LoadingBar:

   ...
      export default class LoadingBar
      {
        constructor()
     {
    ...


    const overlayGeometry = new THREE.PlaneGeometry(2, 2, 1, 1)
    const overlayMaterial = new THREE.ShaderMaterial
             ({
                 //wireframe: true,
                 transparent: true,
                 uniforms:
                 {
                     uAlpha: {value: 0.5}
                 },
             vertexShader: `
              void main()
              {
                  gl_Position = vec4(position, 1.0);
              }
              `,
              fragmentShader: `
              uniform float uAlpha;

              void main()
              {
                  gl_FragColor = vec4(0.0, 0.0, 0.0, uAlpha);
              }
              `
              })

    const overlay = new THREE.Mesh(overlayGeometry, overlayMaterial)
    this.scene.add(overlay)

 }

 }

and another called Resources:

import LoadingBar from '../World/LoadingBar.js'
export default class Resources extends EventEmitter
{
    constructor(sources)
    {
        super()

    this.sources = sources
    
  ...

    this.LoadingBar = new LoadingBar()
    
}

setLoaders()
{
    const loadingManager = new THREE.LoadingManager(
        // Loaded
() =>
{
   
    ***gsap.to(overlayMaterial.uniforms.uAlpha, { duration: 3, value: 1 })***

},

// Progress
() =>
{
    console.log('progress')
}
    )
    this.gltfLoader = new GLTFLoader(loadingManager)
    this.loaders = {}
    this.loaders.gltfLoader = new GLTFLoader()
    this.loaders.textureLoader = new THREE.TextureLoader()
    this.loaders.cubeTextureLoader = new THREE.CubeTextureLoader(loadingManager)
}

Despite importing it I get an error saying overlay material is not defined I cant see why it cant access the loading Bar module? I have deleted as much unnecessary code as I think I possibly can without making it impossible to answer I PUT ASTERIKS where on the line that gives the error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The variable overlayMaterial is only available locally inside the class LoadingBar. If you want it to be available elsewhere, you will have to define it outside of the LoadingBar class (it does not like you are, it is not clear from your example...), and export it separately:

export const overlayMaterial = [your code here]

You can then import in your other module: import {overlayMaterial} from "../World/LoadingBar.js"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!