# Loading bitmap font during runtime instead of during preload.

**URL:** <https://phaser.discourse.group/t/loading-bitmap-font-during-runtime-instead-of-during-preload/12038>\
**Category:** Phaser 3\
**Created:** [July 18, 2022, 6:28pm UTC](https://phaser.discourse.group/t/loading-bitmap-font-during-runtime-instead-of-during-preload/12038 "2022-07-18T18:28:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![creatif](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@creatif](https://phaser.discourse.group/u/creatif)\
**Post date:** [July 18, 2022, 6:28pm UTC](https://phaser.discourse.group/t/loading-bitmap-font-during-runtime-instead-of-during-preload/12038/1 "2022-07-18T18:28:31Z")

</div>

Hi,

I’m able to load images, sounds etc. during runtime but when trying to load bitmap font with the loader during runtime I’ve hit some issues. Been searching around and found no examples loading it that way but reading the documentation it seems that I should be able to do it. I’ve tried fonts from the phaser examples library so that should not be the problem.

This is essentially the code

```javascript
                scene.load.bitmapFont("textName", "urlToImage", "urlToXml");
                    scene.load.once("complete", () => {
                         let text = scene.add.bitmapText(300, 300, "textName", "abc", 70);
                    });

```

Error I get:

Uncaught TypeError: String.fromCharCode is not a function  
at ParseXMLBitmapFont (phaser.js:50654:29)  
at BitmapFontFile.addToCache…etc

Seems like something goes bad during loading and therefore everything else after goes bad.  
Would appreciate any help on this issue since I’m kind of stuck right now.

Cheers!  
/C

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [July 18, 2022, 6:38pm UTC](https://phaser.discourse.group/t/loading-bitmap-font-during-runtime-instead-of-during-preload/12038/2 "2022-07-18T18:38:28Z")

</div>

👋

> [@creatif](#):
>
> Uncaught TypeError: String.fromCharCode is not a function

This is an odd error because `String.fromCharCode()` is a built-in function.

If it reached `ParseXMLBitmapFont()` then something has loaded.

Maybe break in the debugger and take a look.

---

<div class="post-metadata">

**Author:** ![creatif](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@creatif](https://phaser.discourse.group/u/creatif)\
**Post date:** [July 18, 2022, 7:13pm UTC](https://phaser.discourse.group/t/loading-bitmap-font-during-runtime-instead-of-during-preload/12038/3 "2022-07-18T19:13:59Z")

</div>

Hi samme, thanks for your answer. Yes, I can actually see that stuff has been loaded from the xml-file. As I said earlier it doesn’t seem to matter which font I try. It always breaks on this line:

```javascript
var letter = String.fromCharCode(charCode);

```

Seems like the String object here is equal to an empty string (“”) and therefore the fromCharCode method doesn’t exist. The question is, should it be possible to load the font at a later time than preload or is this a bug in the loading of bitmapFont?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [July 18, 2022, 8:15pm UTC](https://phaser.discourse.group/t/loading-bitmap-font-during-runtime-instead-of-during-preload/12038/4 "2022-07-18T20:15:06Z")

</div>

It should be possible, and this doesn’t seem like a Phaser bug.

Is there anything in your code modifying `String`?

---

<div class="post-metadata">

**Author:** ![creatif](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@creatif](https://phaser.discourse.group/u/creatif)\
**Post date:** [July 19, 2022, 11:49am UTC](https://phaser.discourse.group/t/loading-bitmap-font-during-runtime-instead-of-during-preload/12038/5 "2022-07-19T11:49:03Z")

</div>

Good to know that it should be possible, I have searched through my project to see if any references to String can be found but found nothing. I will try some more breakpoints later and see if I can figure out what String is containing and when it changes to an empty string.
