A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] automatic slider is off by 20 pixels

  1. #1
    Member
    Join Date
    Dec 2007
    Posts
    71

    resolved [RESOLVED] automatic slider is off by 20 pixels

    Hi,

    I have a flash player that has a automatic player (with slider and controls),

    I am not sure why the slider head is off by a lot of space, but as the slider goes to the right, there is a gap in the back with the top slider's skin overlapping the underside of the slider... it just looks very bad.

    the darker grey should not be left behind the slider head after it has passed

    I have included both the AS code and the screenshot (please see attached screenshot SWFbug.png).

    What is causing this?

    Thank you for any help you can provide,
    A

    AS code======


    Code:
    
    /* mp3 Player
     * 
     *   mp3Player.swf?opt=val&opt=val&...
     *		stream=Y|N		- if "Y" song will autostart, default to "Y"
     *		id=xxxx			- xxx = hook id
     *		hideclock=Y|N	- if "Y" hide clock, default to "N"
     *      text=string		- text to be displayed on the bottom line
     */
    
    var xmlBaseURL = "http://webmp3.mmr247.net/Playlist/"
    
    
    import flash.external.ExternalInterface;
    //import flash.events.IOErrorEvent;
    import flash.events.*;
    import flash.net.URLRequest;
    
    var isPlaying:Boolean = false;
    var isPlaylist:Boolean = false;
    var showPos:Boolean = true;
    var autoStarted:Boolean = false;
    var isLoaded:Boolean = false;
    var isLoading:Boolean = false;
    var curPos:int = 0;
    var xmlCount:int = 0;
    var xmlMax:int = 0;
    var progress:int = 0;
    var song:SoundChannel;
    
    loadbarWidth = BlueBar.width;
    
    // Process incoming URL
    
    urlStr = loaderInfo.loaderURL;
    urlStr = unescape(urlStr.substr(1 + urlStr.indexOf("?")));
    //urlStr = "id=1753099&text=Title+-%20Artist";	// Comment this line for production
    //urlStr = "filename=tcbeaton";	// Comment this line for production
    
    var TNVP:URLVariables = new URLVariables(urlStr);
    
    if (TNVP.stream==undefined) {
    	TNVP.stream = "Y";
    }
    if (TNVP.hideclock==undefined) {
    	TNVP.hideclock = "N";
    }
    
    prevButton.visible = false;
    nextButton.visible = false;
    playButton.addEventListener(MouseEvent.CLICK,playBtn);
    pauseButton.addEventListener(MouseEvent.CLICK,pauseBtn);
    stopButton.addEventListener(MouseEvent.CLICK,stopBtn);
    
    //if (TNVP.id!=undefined) {
    //	if (TNVP.text!=undefined) {
    //		titleArtist.text = TNVP.text;
    //	}
    //	loadHook(TNVP.id);
    //} else 
    if (TNVP.filename!=undefined) {
    	var xmlLoader:URLLoader = new URLLoader();
    	var xmlData:XML = new XML();
    	xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    	xmlURL = TNVP.filename
    	//xmlURL = TNVP.filename + ".asx?rand=" +  Math.random();
    	//xmlLoader.load(new URLRequest(xmlBaseURL + xmlURL));
    	xmlLoader.load(new URLRequest(xmlURL));
    	isPlaylist = true;
    } else {
    	titleArtist.text = "ERROR";
    }
    
    // =======================================================================
    
    function LoadXML(e:Event):void {
    	prevButton.visible = true;
    	nextButton.visible = true;
    	prevButton.addEventListener(MouseEvent.CLICK,prevBtn);
    	nextButton.addEventListener(MouseEvent.CLICK,nextBtn);
    	xmlData = new XML(e.target.data);
    	var xmlEntry:XMLList = xmlData.ENTRY;
    	xmlMax = xmlEntry.length() - 1;
    	loadXMLSong();
    }
    
    function loadXMLSong() {
    	if (isPlaying) {
    		stopHook();
    		autoStarted = false;
    	}
    	titleArtist.text = xmlData.ENTRY.TITLE.text()[xmlCount] + " - " +xmlData.ENTRY.AUTHOR.text()[xmlCount];
    	var xmlID = xmlData.ENTRY.REF[xmlCount].attribute("HREF");
    	loadPlaylistEntry(xmlID);
    	//var xmlArray:Array = xmlID.split("/");
    	//xmlID = xmlArray[xmlArray.length - 1];
    	//xmlArray = xmlID.split(".");
    	//xmlID = xmlArray[0];
    	//loadHook(xmlID);
    }
    
    function prevBtn(event:MouseEvent):void {
    	if (xmlCount > 0) {
    		xmlCount--;
    		loadXMLSong();
    	}
    }
    
    function nextBtn(event:MouseEvent):void {
    	if (xmlCount < xmlMax) {
    		xmlCount++;
    		loadXMLSong();
    	}
    }
    
    function loadPlaylistEntry(entryURL){
    	if (isLoading) {
    		songHook.removeEventListener(ProgressEvent.PROGRESS,loadProgress);
    		songHook.removeEventListener(Event.COMPLETE,loadComplete);
    	}
    	songHook = new Sound(new URLRequest(entryURL));
    	isLoaded = false;
    	isLoading = true;
    	songHook.addEventListener(ProgressEvent.PROGRESS,loadProgress);
    	songHook.addEventListener(Event.COMPLETE,loadComplete);
    }
    
    
    function loadHook(hookID) {
    	if (isLoading) {
    		songHook.removeEventListener(ProgressEvent.PROGRESS,loadProgress);
    		songHook.removeEventListener(Event.COMPLETE,loadComplete);
    	}
    	songHook = new Sound(new URLRequest(baseURL + hookID + ".mp3?rand=" +  Math.random()));
    	//songHook = new Sound(new URLRequest(baseURL + hookID + ".mp3"));
    	titleArtist.text = baseURL + hookID + ".mp3";
    	isLoaded = false;
    	isLoading = true;
    	songHook.addEventListener(ProgressEvent.PROGRESS,loadProgress);
    	songHook.addEventListener(Event.COMPLETE,loadComplete);
    }
    
    function loadProgress(event:Event):void {
    	progress = Math.floor(event.bytesLoaded / event.bytesTotal * 100);
    	Loading.text = "LOADING " + progress + " %"
    	BlueBar.width = (loadbarWidth * (progress / 100));
    	if ((!autoStarted) && (!isPlaying) && (TNVP.stream == "Y") && (progress > 5)) {
    		autoStarted = true;
    		playHook();
    	}
    }
    
    function loadComplete(event:Event):void {
    	isLoaded = true;
    	isLoading = false;
    	if (TNVP.hideclock == "N") {
    		progressBar();
    	} else {
    		Loading.text = "LOADED";
    	}
    	locSlider.addEventListener(MouseEvent.MOUSE_DOWN,moveSlider);
    	songHook.removeEventListener(ProgressEvent.PROGRESS,loadProgress);
    	songHook.removeEventListener(Event.COMPLETE,loadComplete);
    }
    
    function moveSlider(event:MouseEvent) {
    	showPos = false;
    	locSlider.removeEventListener(MouseEvent.CLICK,moveSlider);
    	stage.addEventListener(MouseEvent.MOUSE_UP,stopSlider);
    	locSlider.addEventListener(Event.ENTER_FRAME,changeLoc);
    }
    
    function playCompleted(event:Event):void {
    	if (isPlaylist) {
    		stopHook();
    		if (xmlCount < xmlMax) {
    			xmlCount++;
    			loadXMLSong();
    			playHook();
    		}
    	}
    }
    
    function stopSlider(event:MouseEvent) {
    	if (isPlaying) {
    		pauseHook();
    	}
    	locSlider.removeEventListener(Event.ENTER_FRAME,changeLoc);
    	stage.removeEventListener(MouseEvent.MOUSE_UP,stopSlider);
    	curPos = songHook.length * ((locSlider.x - 15) / (BlueBar.width));
    	playHook();
    	showPos = true;
    }
    
    function changeLoc(event:Event) {
    	if ((mouseX <= (15 + BlueBar.width)) && (mouseX >= 15)) {
    		locSlider.x = mouseX;
    	}
    }
    
    function playBtn(event:MouseEvent) {
    	if (!isPlaying) {
    		playHook();
    	} else {
    		pauseHook();
    	}
    }
    
    function pauseBtn(event:MouseEvent) {
    	if (isPlaying) {
    		pauseHook();
    	} else {
    		playHook();
    	}
    }
    
    function stopBtn(event:MouseEvent) {
    	stopHook();
    }
    
    function playHook() {
    	song = songHook.play(curPos);
    	isPlaying = true;
    	playProgressInt = setInterval(progressBar,10);
    	song.addEventListener(Event.SOUND_COMPLETE,playCompleted);
    }
    
    function pauseHook() {
    	isPlaying = false;
    	curPos = song.position;
    	song.stop();
    }
    
    function stopHook() {
    	song.stop();
    	isPlaying = false;
    	curPos = 0;
    	cPos = 0;
    }
    
    function progressBar() {
    	totSec = songHook.length / 1000;
    	totMin = Math.floor(totSec / 60);
    	totSec = Math.floor(totSec % 60);
    	if (totSec < 10) {
    		totSec = "0" + totSec;
    	}
    	if (isPlaying) {
    		cPos = int(.5 + song.position / 1000);
    	}
    	var curMin = Math.floor(cPos / 60);
    	var curSec = Math.floor(cPos % 60);
    	if (curSec < 10) {
    		curSec = "0" + curSec;
    	}
    	if ((isLoaded) && (TNVP.hideclock == "N")) {
    		Loading.text = curMin + ":" + curSec + "  /  " + totMin + ":" + totSec;
    	}
    	
    	//RedBar.width = loadbarWidth * cPos / (songHook.length / 1000);
    	RedBar.width = (progress/100) * (loadbarWidth * cPos / (songHook.length / 1000));
    	if (showPos) {
    		locSlider.x = 15 + RedBar.width;
    	}
    }
    Attached Images Attached Images

  2. #2
    Member
    Join Date
    Dec 2007
    Posts
    71
    I solved it by adjusting all instances of 15 to 1... I guess that was causing the extra pixels

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center