forked from: mp3 asset extraction

by ohisama forked from mp3 asset extraction (diff: 32)
♥0 | Line 88 | Modified 2013-01-31 12:01:37 | MIT License
play

ActionScript3 source code

/**
 * Copyright ohisama ( http://wonderfl.net/user/ohisama )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rir3
 */

// forked from wh0's mp3 asset extraction
package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.net.*;
    import flash.utils.*;
    import com.codeazur.as3swf.*;
    import com.codeazur.as3swf.tags.*;
    import com.codeazur.as3swf.data.consts.*;
    import com.bit101.components.*;
    public class FlashTest extends Sprite 
    {
        private var flow : Number = 21;
        private var it : InputText;
        private var pb1 : PushButton;
        private var pb2 : PushButton;
        public function FlashTest() 
        {
            loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, function(e : UncaughtErrorEvent) : void 
            { 
                trace(e.error); 
            });
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            it = new InputText(this, 0, 0);
            it.width = 379;
            it.height = 18;
            pb1 = new PushButton(this, 382, 0, 'url', urlClick);
            pb1.width = 40;
            pb1.height = 18;
            pb2 = new PushButton(this, 425, 0, 'file', fileClick);
            pb2.width = 40;
            pb2.height = 18;
        }
        private function disable() : void 
        {
            it.textField.filters = [new BlurFilter(16, 2)];
            it.enabled = false;
            pb1.enabled = false;
            pb2.enabled = false;
        }
        private function urlClick(e : MouseEvent) : void 
        {
            disable();
            var l : Loader = new Loader();
            l.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void 
            {
                parse(l.contentLoaderInfo.bytes);
                l.unloadAndStop();
            });
            l.load(new URLRequest(it.text));
        }        
        private function fileClick(e : MouseEvent) : void 
        {
            var fr : FileReference = new FileReference();
            fr.addEventListener(Event.SELECT, function(e : Event) : void 
            {
                fr.load();
            });
            fr.addEventListener(Event.COMPLETE, function(e : Event) : void 
            {
                parse(fr.data);
            });
            fr.browse([new FileFilter('Flash Movies (*.swf)', '*.swf')]);
        }        
        private function parse(ba : ByteArray) : void 
        {
            for each (var tag : ITag in new SWF(ba).tags) 
            {
                if (tag is TagDefineSound) addButton(tag as TagDefineSound);
            }
        }        
        private function addButton(tds : TagDefineSound) : void 
        {
            var name : String = tds.characterId.toString();
            var pb : PushButton = new PushButton(this, 0, flow, name, function(e:MouseEvent):void 
            {
                new FileReference().save(tds.soundData, name + '.mp3');
            });
            pb.width = 40;
            pb.height = 18;
            if (tds.soundFormat != SoundCompression.MP3) pb.enabled = false;
            new Label(this, 42, flow, tds.toString().substr(17));
            flow += 21;
        }        
    }
}