Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- musicbtn.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);
- var fl_SC:SoundChannel;
- var fl_ToPlay:Boolean = true;
- function fl_ClickToPlayStopSound(evt:MouseEvent):void
- {
- if (fl_ToPlay)
- {
- var s:Sound = new Sound(new URLRequest("sound/music1.mp3"));
- fl_SC = s.play();
- }
- else
- {
- fl_SC.stop();
- }
- fl_ToPlay = !fl_ToPlay; }
- var s:Sound = new Sound();
- 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
- s.load(new URLRequest("sound/music1.mp3"));
- function completeHandler(e:Event):void {
- var fs:FileStream = new FileStream();
- var f:File = File.applicationStorageDirectory.resolvePath("music1.mp3"); // selects file in the sandboxed dir for your app
- var bytes = new ByteArray();
- s.extract(bytes, 4096); // load file into ByteArray. Unsure length argument is correct, may need tweaking
- fs.open(f, FileMode.WRITE); // opens stream to file, sets mode to WRITE which will create and truncate the file
- fs.writeBytes(bytes); // write ByteArray to file
- fs.close(); // closes link to file. ALWAYS make sure you do this. Failing to do so can have consequences
- }
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- var soundfile:File = File.applicationStorageDirectory.resolvePath("music1.mp3");
- var fstream:FileStream = new FileStream();
- fstream.open(soundfile, FileMode.WRITE);
- fstream.writeBytes(ba, 0, ba.length);
- fstream.close();
- ByteArray ba;
- sound.extract(ba, 4096);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement