Sunday, June 17, 2012

[Action Script] How make a shuffle playlist June,2012

Hello, I have a flash site and MP3 player in there. I want to make it play shuffle.

The playlist.as is here:

HTML Code: package com.Ub.Music
{
        import caurina.transitions.properties.ColorShortcuts;
        import caurina.transitions.Tweener;
        import com.Ub.utils.ScrollBar;
        import com.Ub.Music.playlist.Track;
        import flash.display.MovieClip;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        /**
        * ...
        * @author Umbra
        */
        public class Playlist extends MusicCore
        {
                /*
                * The Playlist class displays and controls playlist panel in MusicModule
                */
               
                private var songArray:Array;
                private var songList:XMLList;
               
                private var trackContainer:Sprite;
                private var contMask:Sprite;
                private var scrollbar:ScrollBar;
                private var colorOut:uint = 0xffffff;
                private var colorOver:uint = 0xff9966;
               
                public static const TRACK_CLICKED:String = "trackClicked";
               
               
                public function Playlist()
                {
                        super();
                       
                       
                }
       
                override protected function init(e:Event):void
                {
                        ColorShortcuts.init();
                        removeEventListener(Event.ADDED_TO_STAGE, init);
                        trackContainer = new Sprite();
                       
                        this.addChild(trackContainer);
                       
                        makeMaskAndScroll();
                       
                        colorOut = _xml.Settings.@playlistTextColor;
                        colorOver = _xml.Settings.@playlistTextColorOver;
                       
                       
                       
                       
                }
                /*CUSTOM FUNCTION CALLED WHEN PLAYLIST IN ON*/
                override public function PLAYLIST_ON():void {
                        this._reveal();
                        updatePlaylist();
                       
                }
               
                override protected function _reveal():void
                {
                        this.alpha = 0
                        visible = true;
                        Tweener.addTween(this, {delay:1, time:1, alpha:1 } );
                }
               
                private function updatePlaylist()
                {
                        clearPlaylist();

                                        songList =  _xml.Album[_currentAlbum].song;
                                        songArray = new Array();
                                        var tfHeight:Number=0;
                                        for (var i:int = 0; i < songList.length(); i++)
                                        {
                                                var track = new Track(songList[i].@title, i);
                                                track.x = 15;
                                                track.y = track.height * i + 8;
                                                trackContainer.addChild(track);
                                                tfHeight +=  track.height;

                                               
                                                track._selected = false;
                                                track._discolorTrack();
                                                track.addEventListener(MouseEvent.CLICK, onTrackClick);
                                               
                                               
                                                songArray.push(track);
                                               
                                                track._showTitles();
                                        }
                                        trackContainer.height = tfHeight
                                        if ( scrollbar) scrollbar.init();
                                       
                                        (songArray[_currentSong] as Track)._selected = true;
                                        (songArray[_currentSong] as Track)._colorTrack();
                       
                }
               
                private function onTrackClick(e:MouseEvent):void
                {
                        //PREV TRACK
                        Tweener.addTween(songArray[currentSong], {_color:colorOut,time:0.3 } );
                        (songArray[_currentSong] as Track)._selected = false;
                       
                        //NEXT TRACK
                        _currentSong = (e.currentTarget as Track)._id
                        this.dispatchEvent(new Event(TRACK_CLICKED));
                       
                        Tweener.addTween(songArray[currentSong], { _color:colorOver, time:0.3 } );
                        (songArray[_currentSong] as Track)._selected = true;
                       
                       
                }
               
       
               
                private function makeMaskAndScroll():void
                {
                        var bgSpr:Sprite = new Sprite();
                        bgSpr.graphics.beginFill(0x000000,0.8);
                        bgSpr.graphics.drawRoundRectComplex(2, 2, 196, 196, 4, 4, 4, 4);
                        bgSpr.graphics.endFill();
                        this.addChildAt(bgSpr,0);
                        contMask = new Sprite();
                        contMask.graphics.beginFill(0x00ff00);
                        contMask.graphics.drawRect(15, 10, 180, 185);
                        contMask.graphics.endFill();
                        this.addChild(contMask);
                       
                        trackContainer.mask = contMask;
                       
                        scrollbar = new ScrollBar();
                        scrollbar.contentMask = contMask;
                        scrollbar.content = trackContainer;
                        scrollbar.x = 6;
                        scrollbar.y = 10;
                       
                        this.addChild(scrollbar);
                        scrollbar.init();
                }
               
               
                private function clearPlaylist():void
                {
                        for (var i:int =  trackContainer.numChildren-1; i >= 0; i--)
                        {
                                trackContainer.removeChildAt(i)
                        }
                }
               
               
               
               
        }

}Any idea? Thanks in advance. I really need it. :)
How make a shuffle playlist

Related Post



0 comments: