// ActionScript Document /* This script is just for the DJ interface. it presumes there are two movie clips ch1 and ch2 which are self contained mp3 players that except volume changes. */ // named objects needed in flash document:: //xfadeSlider_1 //xfadeSlot_1 //ch1 //ch2 stop(); // stop the movie from running away!! //-----------------------------------------------------------------------------Declare and Initialize variables //-----------------------------------------------------------declare var sa : Array = new Array(); // make new array sa (song array) var si : Number; // song index // numbers for xfade control var newVol_1 : Number; var newVol_2 : Number; var avrVol_1 : Number; var avrVol_2 : Number; var cv_1 : Number; var cv_2 : Number; var offset : Number; //---------------------------------------------------------- init. si = 0; newVol_1 = 100; newVol_2 = 0; avrVol_1 = 100; avrVol_2 = 0; cv_1 = 1; cv_2 = 1; offset = 2 ; // this value is also needed to put the volume controlls in the right range //-------------------------------------------------------------------------------------ROLL OVER Array Stuff //--------------------------------------------------------------------------------------------------set si // this function is called the first time a rollbank sound is started. // its designed to allow for an arbitrary number of rollbanks to call and refer to it... // the index it incremented until it hits the end of the song array // the index is then reset. so the rollbank does not need to know anythign about the song array... function si_inc():Void{ // make sure index is within the limits of song array if ( si == (sa.length -1)){ si = 0; } // note that sa is assigned remotely // if it still hasn't reached the limit, increment. else{ si = si + 1; } // debugging: show us that this function has been called. trace("you called... "+ si + " "); // let us know where you stand.... }//end si_inc //-----------------------------------------------------------------------------init when song sub clips are loaded function songsLoadedLetsGo() : Void{ //--------------------------------------------------update sound objects ch1.song_1.setVolume(90); ch2.song_1.setVolume(20); //---------------------------------------------------update interface ch1.tLabel2.text = (avrVol_1 - offset); ch2.tLabel2.text = (avrVol_2 - offset); //--------------------------------------------------start playback ch1.startSound_1(); ch2.startSound_1(); } //--------------------------------------------------------------------------------------------clickVol stuff // local vars var volinc_1 : Number; volinc_1 = 10; ch1_up.onPress = function(){ if (cv_1 >= 1){ cv_1 = 1;} else{ cv_1 = cv_1 + 1/10;} } ch1_dn.onPress = function(){ if (cv_1 <= 0){ cv_1 = 0;} else{ cv_1 = cv_1 - 1/10;} } ch2_up.onPress = function(){ if (cv_2 >= 1){ cv_2 = 1;} else{ cv_2 = cv_2 + 1/10;} } ch2_dn.onPress = function(){ if (cv_2 <= 0){ cv_2 = 0;} else{ cv_2 = cv_2 - 1/10;} } //--------------------------------------------------------------------------------------------Crazy Slider stuff /* this is my gnarly-hairy version of a cross fader in actionscript 2.0 The lowpassing of volume changes helps reduce clicks... */ //--------------------------------------------------------------------------Press Events myxfader_1.xfadeSlider_1.onPress=function(){ // start moving the slider object when mouse is pressed myxfader_1.xfadeSlider_1.startDrag(false,0,0,500,0); //-------------------------------do this stuff when mouse is active in this frame (and pressing) myxfader_1.xfadeSlider_1.onEnterFrame=function(){ // get slider position as a number value (the slider is 500px wide) // so we devide by 5 to get a range of 0-100. this has to be scaled // by 1.033 to help offset some of the lowpass math below // cv_ variables come from the click volume change newVol_1 = (cv_1 * 1.033 * (100 - (myxfader_1.xfadeSlider_1._x / 5))); newVol_2 = (cv_2 * 1.033 * ( (myxfader_1.xfadeSlider_1._x / 5))); // since the slider can move faster than the volume can be updated, and can cause clicks, // we are using a somewhat severe running average to smooth changes in volume enough so // that clicks are kept to a minimum. avrVol_1 = Math.round(((avrVol_1 * 3) + newVol_1) / 4 ) ; avrVol_2 = Math.round(((avrVol_2 * 3) + newVol_2) / 4 ) ; //--------------------------------------------------update sound objects ch1.song_1.setVolume(avrVol_1 - offset); ch2.song_1.setVolume(avrVol_2 - offset); //---------------------------------------------------update interface ch1.tLabel2.text = (avrVol_1 - offset); ch2.tLabel2.text = (avrVol_2 - offset); }//end on enter frame function }// end on press funtion //-------------------------------------------------------------------------Release Events myxfader_1.xfadeSlider_1.onRelease=stopDrag; myxfader_1.xfadeSlider_1.onReleaseOutside=stopDrag;