Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Contents of MySound.as
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundTransform;
- import flash.net.URLRequest;
- public class MySound
- {
- private var theSound:Sound;
- private var theChannel:SoundChannel;
- private var theVolume:SoundTransform;
- public function MySound(Name:String,Volume:Number=1)
- {
- theSound = new Sound(new URLRequest(Name));
- theVolume = new SoundTransform(Volume, 0);
- theChannel = theSound.play(0, 0, theVolume);
- theChannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
- }
- private function onPlaybackComplete(event:Event):void
- {
- theSound.close();
- }
- }
- }
- Contents of Registry.as
- package
- {
- public class Registry
- {
- public static var _jump:String = 'jump.mp3';
- public function Registry()
- {
- }
- }
- }
- How I'm calling MySound
- In the main .as file I have these two lines.
- private var jumpSound:String = Registry._jump;
- MySound(jumpSound);
- When MySound fires... TypeError: Error #1034: Type Coercion failed: cannot convert "jump.mp3" to MySound.
Advertisement
Add Comment
Please, Sign In to add comment