Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com
  2. {
  3. import flash.display.Sprite;
  4. import flash.display.Stage
  5. import flash.events.Event;
  6. import flash.media.Sound;
  7. import flash.media.SoundChannel;
  8. import flash.media.SoundTransform;
  9. import flash.net.URLRequest;
  10. import flash.display.Loader;
  11. import flash.events.IOErrorEvent;
  12. import flash.events.Event;
  13.  
  14.     public class SoundManager extends Sprite    {
  15.        
  16.         public var sound1:Sound = new Sound();
  17.         public var sound2:Sound = new Sound();
  18.         public var sound3:Sound = new Sound();
  19.         public var sound4:Sound = new Sound();
  20.        
  21.         public var url1:URLRequest = new URLRequest("bin/sfx/glass.wav")
  22.         public var url2:URLRequest = new URLRequest("bin/sfx/glass.wav")
  23.         public var url3:URLRequest = new URLRequest("bin/sfx/glass.wav")
  24.         public var url4:URLRequest = new URLRequest("bin/sfx/glass.wav")
  25.        
  26.         public var soundArray:Array = new Array(sound1, sound2, sound3, sound4);
  27.         public var urlArray:Array = new Array(url1, url2, url3, url4);
  28.        
  29.         public var trans:SoundTransform
  30.         public var soundChannel:SoundChannel
  31.        
  32.         public function SoundManager(stage:Stage) {
  33.             stage.addChild(this)
  34.         }
  35.  
  36.         public function Play(sound:String):void {
  37.            
  38.             soundChannel = new SoundChannel;
  39.             trans = new SoundTransform(1, 0)
  40.            
  41.            
  42.             switch(sound) {
  43.                 case "pang":
  44.                 soundChannel = sound1.play(0,0);
  45.                 soundChannel.soundTransform = trans;
  46.                 trace(sound1.length)
  47.  
  48.                 break;
  49.  
  50.             }
  51.  
  52.         }
  53.         public function loadSounds() {
  54.             for (var i:Number = soundArray.length - 1; i >= 0; i--) {
  55.                     soundArray[i].load(urlArray[i])
  56.                     soundArray[i].addEventListener(IOErrorEvent.IO_ERROR, error)
  57.                     soundArray[i].addEventListener(Event.COMPLETE, loaded)
  58.             }
  59.            
  60.         }
  61.         public function error(e:IOErrorEvent):void {
  62.             trace("fail")
  63.             loadSounds();
  64.            
  65.         }
  66.         public function loaded(e:Event):void {
  67.             trace("loaded")
  68.             trace(e.target.length)
  69.         }
  70.  
  71.     }// end Class
  72.  
  73. }// end Package
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement