Share Posted August 18, 2011 Is it possible to load an mp3 file and then turn it into a class? I can do this with an embed mp3 file: [Embed(source="/assets/sounds/explosion.mp3")] public var Explosion:Class; Then instantiate a sound object and control it: var explosionSFX:Sound = new Explosion(); var channel:SoundChannel = new SoundChannel(); var channel = explosionSFX.play(0, 1); Can I download an external mp3 file and then instantiate it? Something like this: var explosionSFX:Sound = new ExplosionDownloadedMP3(); var channel:SoundChannel = new SoundChannel(); var channel = explosionSFX.play(0, 1); Thanks! Link to comment Share on other sites More sharing options...
Share Posted August 18, 2011 have you read the MP3Loader docs? have you tried using it? It makes loading and controlling sounds very easy. once the sound is loaded you can do what you want with it. Link to comment Share on other sites More sharing options...
Author Share Posted August 19, 2011 Hi Carl, I read the doc, but I don't see where I can instantiate the mp3 file. It looks like this isn't possible in flash? Link to comment Share on other sites More sharing options...
Share Posted August 19, 2011 Sure it is. Think of MP3Loader like an instance of the MP3 (it's not really, but it kinda acts like it). What's your goal anyway? Is there some reason that the MP3Loader's properties/methods/functionality isn't what you need? It can pretty much do everything you mentioned in your code plus lots more. I'm confused about what you're struggling with. Just load your MP3 and then control it however you please with playSound(), pauseSound(), gotoSoundTime(), etc. Change the volume with the volume property, blah, blah, blah. If your goal is to get the SoundChannel associated with the Sound's play() command, just use the MP3Loader's channel property. Repeat as many times as you want by using the "repeat" special property. Everything should be there for you. Link to comment Share on other sites More sharing options...
Author Share Posted August 20, 2011 Thanks for your response. I want to be able to load an external mp3 file, then instiate it, over and over and over again, and not have to download it every time I need another instance. Currently the only way I know how to do this with an external mp3 file is by wrapping the mp3 file inside a swf, I load the swf then access the mp3 via its linkage/Class name. This way I can instantiate the sound quickly and as often as I like. I don't want to have to make a url request every time I want another version of the sound. I understand the URL request will be cached (the content), but that's not what I want. It's still to slow and I have to set up event listeners, it adds too many steps and slows down making a lot of the same sounds at once. I make games, they have lots of sounds, explosions, lasers, ect. Sometimes I need one sound to be instantiate 20 times in a for loop. It would be much easier and efficient if I could just download the mp3 file once, then instantiate it like a Class. In a similar manner as embedding it (see my example above). Thanks! Link to comment Share on other sites More sharing options...
Author Share Posted August 20, 2011 If this is possible, can you please give me an example? What I'm looking for is: - Download an mp3 file once. - Instantiate that mp3 file several times with out downloading it again. pseudo code: downloadedMP3 = mp3 file downloaded as a Class var mp3_1 = new downloadedMP3(); var mp3_2 = new downloadedMP3(); var mp3_3 = new downloadedMP3(); Link to comment Share on other sites More sharing options...
Share Posted August 22, 2011 Sure, you can play the sound as many times as you want. If you want to access the raw Sound object so that you can play() it and get different SoundChannel instances each time (so that the same sound could play multiple times simultaneously), just use the MP3Loader's "content" property (which is a Sound object). var loader:MP3Loader = new MP3Loader("sound.mp3", {onComplete:doStuff}); loader.load(); function doStuff(event:LoaderEvent):void { var sound:Sound = loader.content; var channel:SoundChannel = sound.play(0, 1); } Link to comment Share on other sites More sharing options...
Author Share Posted August 22, 2011 Thanks! Link to comment Share on other sites More sharing options...
Share Posted August 24, 2011 hmmm... I was just needing this information too... I put this script in my scene and get an error: 1046: Type was not found or was not a compile-time constant: LoaderEvent. Link to comment Share on other sites More sharing options...
Share Posted August 24, 2011 add this to your imports up top import com.greensock.events.LoaderEvent; Link to comment Share on other sites More sharing options...
Share Posted August 24, 2011 now I'm getting 2 errors: 1046: Type was not found or was not a compile-time constant: MP3Loader. 1180: Call to a possibly undefined method MP3Loader. and here's what I have up top: import com.greensock.*;import com.greensock.easing.*; import com.greensock.plugins.*; import com.greensock.OverwriteManager; import com.greensock.events.LoaderEvent; TweenPlugin.activate([VolumePlugin, MotionBlurPlugin, TintPlugin, BlurFilterPlugin]); import flash.media.Sound; import flash.media.SoundChannel; Link to comment Share on other sites More sharing options...
Share Posted August 24, 2011 that's because you are not importing the necessary Loader classes. import com.greensock.loading.* please read the documentation and sample code for mp3Loader here: http://www.greensock.com/as/docs/tween/ ... oader.html Link to comment Share on other sites More sharing options...
Share Posted August 24, 2011 perfect. That last url did the trick. I was looking under sound or something like that... thanks!! Dave Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now