Ok, We Are Back On PHAS3R Development - Need Help With Error In Browser Console

Hi,

Trying to load images using a function.
When we run in Internet browser, it crashes and shows below error in browser console.
We are having difficulty with this constantly.
Please look at below JS source code and the error:
Thanks!

Jesse Lee

//--------------------------------------------------------------------------------------------------------------
function LoadSprite (spriteIndex, filePath, spriteDepth, spriteAlpha)
{
    Sprites[spriteIndex] = this.load.image('Sprites[spriteIndex]', filePath);
//                                   ^-- ERROR: "Uncaught TypeError: Cannot read properties of undefined (reading 'image')"?
    Sprites[spriteIndex] = this.add.image(-99999, -99999, 'Sprites[spriteIndex]');
    Sprites[spriteIndex].setDepth(spriteDepth);
    DrawSprite(Sprites[spriteIndex], 320, 180, 1.0, 1.0, 0, 255, 255, 255, spriteAlpha);

}

//--------------------------------------------------------------------------------------------------------------
function LoadAllSpritesAndInitialize ()
{
    for (index = 0; index < SpritesMax; index++)
    {
        if (index === 0)
        {
            LoadSprite(index, 'data/images/backgrounds/BG_Screen_Fading.png', 999, 0);
        }

    }

}

the problem is that the function LoadSprite is not part of the scene, so this.load does not exist. One solution is, just pass the scene as parameter to the function:

function LoadSprite (scene, spriteIndex, filePath, spriteDepth, spriteAlpha){
      Sprites[spriteIndex] = scene.load.image('Sprites[spriteIndex]', filePath);
      ...
}
....

Ok, thanks - that fixed the error…