This site requires JavaScript, please enable it in your browser!
Greenfoot back
Anoniem
Anoniem wrote ...

2014/2/8

Stop music loop

Anoniem Anoniem

2014/2/8

#
Iam want to stop a music loop from playing after a click on a back button
danpost danpost

2014/2/8

#
Do you have a field that holds the GreenfootSound object that is playing? If not, you cannot stop it without unloading the scenario.
Anoniem Anoniem

2014/2/9

#
yes i do have a field the code looks likes this now GreenfootSound backgroundMusic = new GreenfootSound("Controlecentrum.mp3"); backgroundMusic.playLoop();
Anoniem Anoniem

2014/2/9

#
i am trying to stop the music from a another class backbutton by clicking on the button
danpost danpost

2014/2/9

#
Anoniem wrote...
yes i do have a field the code looks likes this now GreenfootSound backgroundMusic = new GreenfootSound("Controlecentrum.mp3"); backgroundMusic.playLoop();
I will presume that these lines are in a method of your World subclass. If those two lines are back-to-back inside a method, then that is a local field and is not good enough. You need to move the first line outside the method to make it a 'global' field (an instance field -- one that belongs to the object that creates it; not one that belongs to the method, where it is discarded after the method is done executing). After you move the first line to outside the method, you should be able to use:
1
backgroundMusic.stop();
on the world object. What I mean by 'on the world object' is this: if you are trying to stop it from an Actor subclass, you would need something like this:
1
((MyWorld)getWorld()).backgroundMusic.stop();
Substitute 'MyWorld' with the class name of your World subclass that the backgroundMusic field is in.
You need to login to post a reply.