KunoNoOni

MySound

Jun 25th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Contents of MySound.as
  2.  
  3. package
  4. {
  5.     import flash.display.Sprite;
  6.     import flash.events.Event;
  7.     import flash.media.Sound;
  8.     import flash.media.SoundChannel;
  9.     import flash.media.SoundTransform;
  10.     import flash.net.URLRequest;
  11.    
  12.     public class MySound
  13.     {
  14.         private var theSound:Sound;
  15.         private var theChannel:SoundChannel;
  16.         private var theVolume:SoundTransform;
  17.        
  18.         public function MySound(Name:String,Volume:Number=1)
  19.         {
  20.             theSound = new Sound(new URLRequest(Name));  
  21.             theVolume = new SoundTransform(Volume, 0);
  22.             theChannel = theSound.play(0, 0, theVolume);
  23.             theChannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
  24.         }
  25.        
  26.         private function onPlaybackComplete(event:Event):void
  27.         {
  28.             theSound.close();
  29.         }
  30.     }
  31. }
  32.  
  33. Contents of Registry.as
  34.  
  35. package
  36. {
  37.     public class Registry
  38.     {
  39.         public static var _jump:String = 'jump.mp3';
  40.        
  41.        
  42.         public function Registry()
  43.         {
  44.         }
  45.     }
  46. }
  47.  
  48.  
  49. How I'm calling MySound
  50.  
  51. In the main .as file I have these two lines.
  52.  
  53. private var jumpSound:String = Registry._jump;
  54.  
  55. MySound(jumpSound);
  56.  
  57. When MySound fires... TypeError: Error #1034: Type Coercion failed: cannot convert "jump.mp3" to MySound.
Advertisement
Add Comment
Please, Sign In to add comment