1

you have always been of great help for me throughout the last few years. I could always find a solution to my programming problem. This time however I couldn't find a solution to this one. Although there are a few topics which discuss Loaders. Mine is a lot different.

The problem: In the first game screen I load a movie (a movie converted to .swf). And after I switch to the next state, it unloads and doesn't display any more. At the end of the game I execute my own made reset function (which has not much to do with the loader whatsoever, it just resets some static variables) and the game switches to the first state.

The Loader once again shows up. But now when I switch states, the Loader is still displaying.

Note: I am using the flixel library. Although I don't think it makes a big difference in this case (though I figure it problably does since I still have the problem :P).

I have only placed the important code. I have three buttons. Let's say I push. the third button. In the switch case I enter case 2.

The reset function is a flixel function: FlxG.resetGame() but I figure it doesn't really matter.

I hope this is enough information for someone to see the problem/solution. Thanks in advance.

Here's the code:

AMCInlog.as

private var my_loader:Loader;
private var my_player:Object;
    public function AMCInlog() 
    {
        imgBackground = new FlxSprite(0, 0, Resources.imgStartMenuBackground);
        add(imgBackground);

        my_loader = new Loader();
        my_loader.x = 40;
        my_loader.y = 156;          
        my_loader.scaleX = 1.2;
        my_loader.scaleY = 1.2;
        //loadUserData();
        moviePlayerSequence();
        //userData.clear();
        //createButtons();  
    }

    private function moviePlayerSequence():void {
        var request:URLRequest = new URLRequest("DGAME Movie.swf");
        my_loader.load(request);
        FlxG.stage.addChild(my_loader);
    }

    private function currentButtonFunction():void {
        switch(currentButton) {
            case 0:
                my_loader.unloadAndStop();
                FlxG.stage.removeChild(my_loader);
                FlxG.switchState(new AMCRegister());
                break;
            case 1:
                my_loader.unloadAndStop();
                FlxG.stage.removeChild(my_loader);
                FlxG.switchState(new AMCExistingAccountLogin());
                break;
            case 2:
                my_loader.unloadAndStop();
                FlxG.stage.removeChild(my_loader);
                FlxG.switchState(new AMCPreferences());
                break;
            default:
                break;
        }
    }   
Matti Groot
  • 41
  • 10

1 Answers1

0

You never reset your loader, hence it just holds onto what it loaded last time, either simply try and reset (or re-initiate actually) your loader like so (not the best method (will go into flash garbage-collection which has never been that awesome) but hey, it works)

my_loader = new Loader();

Or (since i dont see it) try using simply unload(); instead of unloadAndStop(); (since well, you dont need to stop it, if you unload it properly, its gone anyway)

Good luck!

suicidal.banana
  • 206
  • 1
  • 8
  • Thank you for your fast reply. When I switch to another state. And let's say I switch back to AMCInlog. Doesn't it already re-initiate my_loader (the codeline you posted is also in my constructer) ?. And I've also tried the my_loader.unload() function but it doesn't seem to make any difference. – Matti Groot Nov 15 '12 at 09:58
  • 1
    Afaik states dont 'garbage collect' since theres a high possibility that you will reuse states – suicidal.banana Nov 15 '12 at 14:24
  • Thanks for your help. It means a lot. I have solved the issue. I figured that I could also instantiate a new FlxObject which loads the movie. This way I am able to kill() the FlxObject. I don't think it is the best way to remove the old movie. But it seems to work fine. Again thank you for your help. – Matti Groot Nov 16 '12 at 11:21
  • Yeah, sometimes flash is just like that, im sure theres a better way but this (reset/kill) doesnt actually seem to hurt anything, and flash should garbage collect it on its own fine. Glad i could help :) – suicidal.banana Nov 19 '12 at 08:50