<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
    xmlns:coverflow="com.dougmccune.containers.*" xmlns:controls="com.benstucki.controls.*"
    backgroundColor="0x000000"
     
    nativeDragDrop="nativeDragDropHandler(event)" 
    nativeDragEnter="nativeDragEnterHandler(event)" 
    
    viewSourceURL="srcview/index.html">
    
    <mx:Script>
        <![CDATA[
            import com.dougmccune.MP3CoverChild;
            
            private function nativeDragEnterHandler(event:NativeDragEvent):void {
                if(event.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)) {
                    NativeDragManager.acceptDragDrop(this);
                }
            }
            
            private function nativeDragDropHandler(event:NativeDragEvent):void {
                var files:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
                
                for each(var file:File in files) {
                    
                    if(file.extension.toLowerCase().indexOf(".mp3") == file.extension.length - 4) {
                        var mp3Component:MP3CoverChild = new MP3CoverChild();
                        mp3Component.file = file;
                        
                        mp3Component.width = mp3Component.height = 200;
                        coverflow.addChild(mp3Component);
                    }    
                }
                
                coverflow.selectedIndex = Math.floor(coverflow.numChildren/2);
                playMP3();
            }
            
            [Bindable]
            private var soundChannel:SoundChannel;
            
            private function playMP3():void {
                if(soundChannel) {
                    soundChannel.stop();
                }
                
                var sound:Sound = new Sound(new URLRequest(MP3CoverChild(coverflow.selectedChild).file.url));
                soundChannel = sound.play();
            }
        ]]>
    </mx:Script>
    
    <mx:VBox width="100%" height="100%" verticalAlign="middle" horizontalAlign="center"
        visible="{soundChannel==null}">
        <mx:VBox borderStyle="solid" borderColor="#cccccc" cornerRadius="10"
            backgroundColor="0xffffff" backgroundAlpha=".3" color="0xefefef" fontWeight="bold"
            verticalAlign="middle" horizontalAlign="center"
            width="200" height="200" fontSize="16">
            <mx:Label text="Drop some MP3s" />
        </mx:VBox>
    </mx:VBox>
    
    <coverflow:CoverFlowContainer id="coverflow"  reflectionEnabled="true" change="playMP3()" width="100%" height="100%" />
    
    <controls:Oscilloscope bottom="0" width="100%" height="100" 
        fillColor="{getStyle('themeColor')}" alpha=".7" visible="{soundChannel!=null}" />
        
    <mx:VBox width="100%" height="100%" verticalAlign="bottom" horizontalAlign="center" fontWeight="bold" >
        <mx:Text color="0xffffff" textAlign="center"
            htmlText="{MP3CoverChild(coverflow.selectedChild).artist}&lt;br /&gt;{MP3CoverChild(coverflow.selectedChild).title}" />
    </mx:VBox>
    
</mx:WindowedApplication>