// ActionScript Document /* This script establishes the behavior of the rollControl Movie clip. this script/object requires an array to be populated with song URLS by an other object this script/object requires a song index to be set by another object the path to populate this beast will be: _root.colgo_N.rctl_M.rgo_1.sa _root.colgo_N.rctl_M.rgo_1.si where N is the column number, and M is the row number. these aren't actually x,y coordinates or anything, just a naming convention i am using. cols increment from left to right starting at 1 rows increment from top to bottom starting at 1 */ stop(); // stop the movie from running away!! // ------------------------------------------------------------declare variables var myvol :Number; var song : Sound = new Sound (); var sa : Array = new Array(); // make new array sa (song array) var si : Number; // song index var playCount : Number; // var keyCount : Number; // //------------------------------------------------------------initialize variables playhead = 0; // init play head possition to the start of the song songPlaying = false; // init song playing state to false so that the play button can start playing playCount = 0; // playCount will be used to load the sound on first play request keyCount = 0; // keyCount will be used to load the sound and si on first play request myvol = 25; song.setVolume(myvol); // default to 25% of full volume (hopefully we will adjust this later... // actually this volume intialiaztion has no meaning when the _root level script sets at start up // it sets this volume too... //---------------------------------------------------------------------------set si and sa //------------------------------------------------------- PROCESS XML var xml : XML = new XML(); xml.ignoreWhite = true; xml.load ("hits.xml"); // your local file songs.xml xml.onLoad = function(){ trace("xml loaded________"); // first label, sum of sublabels under first label of xml text var nodes : Array = this.firstChild.childNodes; // debugging update trace("XMLfilehas this many nodes____: " +nodes.length); // loop from zero to sum of sublabels for (var i = 0; i < nodes.length; i++){ // store the ULR strings in the song array sa.push(nodes[i].attributes.url); // debugging some more... trace("yo is this working... "+ nodes[i].attributes.url + " "); }//end sublables loop // set this sa to be the sa at the _root level too _root.sa = sa; // call si increment function in toplevel script. and get that si value _root.si_inc(); si= _root.si; }//end onload function // -------------------------------------------------------------end XML /* //THIS FUNCTION Commented below MUST BE AVAILABLE IN THE _root LEVEL SCRIPT OR FRAME... // 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; } // sa.length is local here, send sa.length value to root or live with a set length // 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 */ //-------------------------------------------------------------------------------playState function rollPlay():Void{ rgo_1.gotoAndPlay(2); // play the rgo clip starting at frame 2 (show me that state!!) songPlay(); // call the songPlay function var bugVol = song.getVolume(); trace(" i pressed a button" + " " + si + " at vol " + bugVol); // debugging stuff }//end rollPlay //----------------------------------------------------------------------------StopState function rollStop():Void{ rgo_1.gotoAndStop(1); // stop that shit trace(" the sound ended " + si); // debugging stuff }//end rollStop //---------------------------------------------------------------------------songPlay //---------------------------------------------------------play function function songPlay():Void{ if ( playCount == 0 ){ // call si increment function in toplevel script. and get that si value //_root.si_inc(); //si = _root.si; myvol = song.getVolume(); // get previous volume setting song.loadSound(sa[si], true); //LoadSongFromIndex song.setVolume(myvol); // set volume setting after song is loaded. song.start(0, 0); // play from begining playCount = 1; }//end if playCount else{ // dont load the sound each time, just the first time... myvol = song.getVolume(); // get previous volume setting song.setVolume(myvol); // set volume setting after song is loaded. song.start(0, 0); // play from begining }// end else }// end playSong //---------------------------------------------------------------------------------UI_EVENTS // make it go on roll over or press... rgo_1.onPress = rollPlay; rgo_1.onRollOver = rollPlay; // call stopState when sound ends song.onSoundComplete= rollStop; //--------------------------------------------------------------------key triggered fun // declare object for key listening: var keyListener:Object = new Object(); // set up keys board to play in flash... Key.addListener(keyListener); // do something when the key is pressed keyListener.onKeyDown = function() { // get the ascii value of any key pressed. gokey = Key.getAscii() // do something with that key value var gogo = gokey % sa.length; if( gogo == si){ rollPlay(); }// end if gokey };