Hi all,
I am developing a flash game currently and was hoping you could please help me with some issues I am experiencing having.
The game I’m making uses actionscript class files so no code is placed directly on the main timeline in the .fla file. The game features a series of screens such as the home screen, instructions screen, page selection screen etc. and each screen is a movieclip instance which is added to the stage via my document class ‘Main.as’.
Each screen used in the game has its own actionscript class which controls all the actions featured on that specific screen.
I currently want to add sounds and background music to the game but am trying to avoid having to place music and sounds on each individual screen instance.
I was just wondering - is it possible to create a separate class which stores all the music and sounds for the game in a class file called ‘sounds.as’ which I can call from any other screen class within the game or either the document class ‘Main’ when I need it?
For example, when the game starts it loads the home screen page and the idea is to have a sound button placed on this screen which toggles the background music on and off when the user clicks it; so when the game starts the background music is playing but the user can press the sound button to turn off the music from any screen within the program.
Just for more clarity, specifically what I’m asking is how can I refer to a particular sound stored in a separate actionscript class file from within a different actionscript file? Say for instance my Home screen class file.
In case it helps here is the actionscript class file for my sounds; I’m not sure I have coded it correctly loool:
package {
import flash.media.SoundChannel;
import flash.events.Event;
public class SoundController{
public var bgmMusic:BackgroundMusic; //variable for BGM
public var bgmSoundChannel:SoundChannel;//sound controller for bgm
public function SoundController() {
bgmMusic = new BackgroundMusic();//create new instance of Background music sound and store in variable
}
public function StartBGMMusic(e:Event):void {
bgmMusic = new BackgroundMusic();
bgmSoundChannel = bgmMusic.play();
}
}
}
Any help is very much appreciated,
Thanks in advance :thumb: