# Scope outside of font loader function

**URL:** <https://discourse.threejs.org/t/scope-outside-of-font-loader-function/26531>\
**Category:** Questions\
**Tags:** javascript\
**Created:** [May 22, 2021, 7:49pm UTC](https://discourse.threejs.org/t/scope-outside-of-font-loader-function/26531 "2021-05-22T19:49:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kendy205](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kendy205/32/18417_2.png) [@Kendy205](https://discourse.threejs.org/u/Kendy205)\
**Post date:** [May 22, 2021, 7:49pm UTC](https://discourse.threejs.org/t/scope-outside-of-font-loader-function/26531/1 "2021-05-22T19:49:24Z")

</div>

Hello I want to access text object outside of loader function

The code looks like this

> ```
> var mainText;
> const loader = new THREE.FontLoader();
> loader.load( 'Inconsolata_Regular.json', function (font) {
> const color = 0xffffff;
> const matLite = new THREE.MeshBasicMaterial( {color: color,transparent: true,side: THREE.DoubleSide} );
> 
> const message = "My Text";
> 
> const shapes = font.generateShapes( message, 10 );
> const geometry = new THREE.ShapeGeometry(shapes);
> geometry.computeBoundingBox();
> const xMid = - 0.5 * ( geometry.boundingBox.max.x - geometry.boundingBox.min.x );
> geometry.translate( xMid, 0, 0 );
> var mainText = new THREE.Mesh(geometry, matLite);
> scene.add(mainText)
> shapes.push.apply( shapes, holeShapes );
> } );
> 
> ```

and i want to access mainText in moveCamera function bu that doesnt work. Nothing seems to exit this loader function i have tried defining text variable that i assigned some string in the function and then console.loggging that variable but that didnt work either and I have no idea why.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [May 23, 2021, 9:32am UTC](https://discourse.threejs.org/t/scope-outside-of-font-loader-function/26531/2 "2021-05-23T09:32:02Z")

</div>

> [@Kendy205](#):
>
> ` var mainText = new THREE.Mesh(geometry, matLite);`

Write the line like so:

```js
mainText = new THREE.Mesh(geometry, matLite);

```

Otherwise the `mainText` variable defined outside of the `onLoad()` callback will be `undefined`.
