Way to store generated image (FlxSprite) in static variable for later use?



  • I'm trying to store a FlxSprite object representing an achievement icon in a list of achievements stored as a static class variable. However, whenever I try to access the FlxSprite later from a different class, my code stops executing from that point and I get an error when running it in the Flash Player debugger. The error is: "ArgumentError: Error #2015: Invalid BitmapData."

    The code is here: https://github.com/CoreyBowes/CaveOfAdventure.git My problem is in AchievementsState.hx, line 67:
    testIcon.loadGraphicFromSprite(FancyDraw.getHeartIcon(40, 40));

    What I'd like to know is, is there a way to store a FlxSprite in a static variable array so that it can be accessed later? If not, is there some other way to store an image?


  • administrators

    There's two things you need to watch out for:

    • On state switches, destroy() is automatically called on display list members. So if those sprites have been add()ed, you'd need to remove() them before a switch to avoid that.
    • Additionally, state switches dispose all FlxGraphic instances. This can be controlled via the persist property (sprite.graphic.persist = true).


  • That's good to know, thanks. But I checked those, and I'm still having the same problem. I never add()ed that sprite before, so that's not it. For the persist property I added the following line after line 31 in Achievements.hx:

    currentAchievement._icon.graphic.persist = true;

    But that didn't seem to fix it. I'm still getting the same error.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.