Jump to content
Search Community

Inefficient to use same MP3Loaders in multiple .as files?

UbiAssassin test
Moderator Tag

Recommended Posts

Hello again,

 

I hope that this question is not completely daft, but I have 3 sounds that I load in MP3Loaders currently. I am finding that many of my website's .as files need to access these same sounds. At first I just added vars to each .as script using MP3Loaders to load the same sounds. I am not disposing of the loaders from the original .as files that already loaded these sounds however. Can I just tell that sound to play in an .as file that is called well after the sound has been loaded and not disposed of in a previous .as file? Or do I have to just keep cloning the MP3 Loader logic into each new .as file that needs to access the sounds?

 

I assume that I can just grab the already loaded content into a var in my new .as file and then use it as needed instead of creating new loader instances everywhere. I am trying to be efficient but I am also learning everything for the first time, so I am not aware of a lot of things. I know about getLoader,but I am not 100% sure how it works. I have tried to access the private var MP3Loaders from the other .as files with getLoader, but I am not sure how to do this currently. Any help would be appreciated so that I can keep my overhead down as much as possible and just use what is already loaded instead of calling multiple loads for the same content.

 

Or does a loader just skip any overhead if the content it is calling is already present and loaded?

 

Here is an example of one of the MP3Loaders that I call early in my movie:

 

private var musButtonClick:MP3Loader = new MP3Loader("http://levelforge.com/MP3/button-11.mp3", {autoPlay: false, volume: 1});

 

I would love to just have acess to this in another .as file. Like a global variable in games, that can be called regardless of where you are in your script.

Link to comment
Share on other sites

I would recommend loading your assets only once even if you intend to control them through multiple classes.

 

any class that imports com.greensock.loading.* has access to loaders being loaded by LoaderMax in other classes.

LoaderMax gives you a centralized access point to all your loaded assets.

 

 

for instance if your document class has

 

var sound:MP3Loader = new MP3Loader("chicken.mp3", {name:"chicken", onComplete:completeHandler});
		sound.load();

 

 

any other custom class that you instantiate in that app can use:

 

var chickenSound:MP3Loader = LoaderMax.getLoader("chicken");
chickenSound.playSound();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...