Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. musicbtn.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);
  2.  
  3. var fl_SC:SoundChannel;
  4.  
  5. var fl_ToPlay:Boolean = true;
  6.  
  7. function fl_ClickToPlayStopSound(evt:MouseEvent):void
  8.  
  9. {
  10. if (fl_ToPlay)
  11.  
  12. {
  13. var s:Sound = new Sound(new URLRequest("sound/music1.mp3"));
  14. fl_SC = s.play();
  15. }
  16. else
  17. {
  18. fl_SC.stop();
  19. }
  20. fl_ToPlay = !fl_ToPlay; }
  21.  
  22. var s:Sound = new Sound();
  23. s.addEventListener(Event.COMPLETE, completeHandler); // not entirely sure this is the correct event, but it should be. I haven't played with the Sound class in a while
  24. s.load(new URLRequest("sound/music1.mp3"));
  25.  
  26. function completeHandler(e:Event):void {
  27. var fs:FileStream = new FileStream();
  28. var f:File = File.applicationStorageDirectory.resolvePath("music1.mp3"); // selects file in the sandboxed dir for your app
  29.  
  30. var bytes = new ByteArray();
  31. s.extract(bytes, 4096); // load file into ByteArray. Unsure length argument is correct, may need tweaking
  32.  
  33. fs.open(f, FileMode.WRITE); // opens stream to file, sets mode to WRITE which will create and truncate the file
  34. fs.writeBytes(bytes); // write ByteArray to file
  35. fs.close(); // closes link to file. ALWAYS make sure you do this. Failing to do so can have consequences
  36. }
  37.  
  38. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  39.  
  40. var soundfile:File = File.applicationStorageDirectory.resolvePath("music1.mp3");
  41. var fstream:FileStream = new FileStream();
  42. fstream.open(soundfile, FileMode.WRITE);
  43. fstream.writeBytes(ba, 0, ba.length);
  44. fstream.close();
  45.  
  46. ByteArray ba;
  47. sound.extract(ba, 4096);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement