Flash MX MP3 player, Pt.1

source: http://www.thegoldenmean.com

6 — General Logic

In contrast to the massive “functions” layer, the “logic” layer is pretty lightweight. It is mostly responsible for formatting and getting things going.

Style for ListBox

Select the first frame in the next to top layer (“logic”) and be sure the ActionScript editor is open. I’ll take you through this in stages. We begin with some preliminaries: declaring a global variable so that the _root timeline is accessible everywhere (even inside functions) and defining the styling for the listBox we placed on stage previously and named “songList_lb”. Here we go.

//persistent reference to _root 
_global.mainTL = this;

  /**********************
This portion is concerned with the main navigation: the ListBox component
 containing the titles. These are brought in from an external xml file and
 displayed in a ListBox
************************/
 //first, set styling for the ListBox
 lbStyle = new FStyleFormat;
 lbStyle.textAlign = "left"; 
lbStyle.textFont="Verdana";
 lbStyle.textSize = 10;
 lbStyle.textLeftMargin = 5; 
lbStyle.textColor = 0x333333;
 lbStyle.textSelected = 0xFFFF33;
 lbStyle.embedFonts = false; 
lbStyle.background = 0xD9D3D3;
 lbStyle.arrow = 0x333333;
 lbStyle.scrollTrack = 0xACA6A6;
 lbStyle.face = 0xC7C2C2;
 lbStyle.addListener(songList_lb);

//prevent resize
Stage.scaleMode = "noScale";   

It’s tedious but all pretty straightforward. Feel free to modify any of these styles to suit the needs of your own web page or Flash movie.

Define XML object and callback

Next we turn our attention to the xml file. We create a new instance of the XML object and define the callback function which runs when the onLoad event handler fires (recall we wrote this function on the previous page). It’s always good practice to establish the callback before loading the resource itself.

//second, set basic xml stuff 
songList_xml = new XML();
 songList_xml.ignoreWhite = true;
 songList_xml.onLoad = function(success){
     if(success){
          songListLoaded(); 
     } 
} 

Final Steps

The “logic” layer concludes by defining the change handler function for the listBox component and then, finally, loading the xml file into the Flash movie.

//Define change handler for listBox component
songList_lb.setChangeHandler("doPlay");

//Finally! Load the xml document.
songList_xml.load("songList.xml");

That concludes our “logic” layer, and by now the player has every feature it needs to choose and play music. One last refinement remains for the basic version of our player, and that is the volume control. Move to Page Seven to see how that is done.

go to page: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
divider ornament

--top--