Code:
maincontent_mc._alpha = 0;
maincontent_mc.target_mc._y = 0;
resetBody();
// Roll over color for all buttons
var rollOverColor:String = "0xd56090";
// Set main body to invisible so it fades in
maincontent_mc._alpha = 0;
// Same thing with the news list
newslist_mc._alpha = 0;
// Reset main body
resetBody();
// Reset news list
resetList();
// Create XML
var kunderXML:XML = new XML();
// Ignore whitespaces, should use in almost every case
kunderXML.ignoreWhite = true;
// Load XML
kunderXML.onLoad = function(success) {
maincontent_mc._alpha = 0;
maincontent_mc.target_mc._y = 0;
// Fade it in
fadeIn(maincontent_mc,7,0);
// Create a stylesheet for main body
txtCSS = new TextField.StyleSheet();
// Load our CSS file
txtCSS.load("news.css");
// Apply the stylesheet to the text field
maincontent_mc.target_mc.body_txt.styleSheet = txtCSS;
// Enable HTML for text field
maincontent_mc.target_mc.body_txt.html = true;
// Set the text field to auto size
maincontent_mc.target_mc.body_txt.autoSize = "left";
// Holder var for XML
newsNode = kunderXML.firstChild;
// If successfull...
if (success) {
// Find total # of years
totalyears = newsNode.childNodes.length;
// Create array to hold years
var years:Array = new Array();
// For every year....
for (i=0; i<totalyears; i++) {
// Add the year into the years array
years.push(newsNode.childNodes[i].attributes.name);
// Find the total # of news items for each year
var totalnews:Number = newsNode.childNodes[i].childNodes.length;
// Set yearitem to a XML menu
yearitem = yearlist_mc.attachMovie("year_mc", "yearclip"+i, i);
// Position the year menu
yearitem._x = 40*i;
yearitem._y = 0;
yearitem.i = i;
// Set the text field to equal the year name
yearitem.name_txt.text = years[i];
// Insert a var for total tracks in each year nav
yearitem.mynews = totalnews;
// When the year menu is rolled over, change color
yearitem.onRollOver = function() {
// Show rolled over state
var yearColor = new Color(this);
yearColor.setRGB(rollOverColor);
};
// On click a year...
yearitem.onRelease = function() {
// Set global far for total news items for selected year
_global.mynews = this.mynews;
// Clear list
resetList();
// For all total years...
for (i=0; i<totalyears; i++) {
// Enable all yearitems for clicking
yearlist_mc["yearclip"+i].enabled = true;
// Return them all to their original color
var yearColor = new Color(yearlist_mc["yearclip"+i]);
yearColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0});
}
// List news for the selected year
for (i=0; i<this.mynews; i++) {
// Var for attaching a news item clip
newsitem = newslist_mc.target_mc.attachMovie("newslink_mc", "trackclip"+i, i+1000);
// Position news list
newsitem._x = 0;
newsitem._y = 21*i;
// Set the text fields to the xml values for each news item
newsitem.date_txt.text = newsNode.childNodes[this.i].childNodes[i].childNodes[0].firstChild.nodeValue;
newsitem.title_txt.text = newsNode.childNodes[this.i].childNodes[i].childNodes[1].firstChild.nodeValue;
newsitem.main = newsNode.childNodes[this.i].childNodes[i].childNodes[2].firstChild.nodeValue;
// Show the rolled over state
newsitem.onRollOver = function() {
var newsColor = new Color(this);
newsColor.setRGB(rollOverColor);
};
// Show the original state
newsitem.onRollOut = newsitem.onReleaseOutside=function () {
var newsColor = new Color(this);
newsColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0});
};
// Click a news item
newsitem.onRelease = function() {
// Reset main body
resetBody();
// Set title field
maincontent_mc.target_mc.title_txt.text = this.title_txt.text;
// Set date field
maincontent_mc.target_mc.date_txt.text = this.date_txt.text;
// Set the body field
maincontent_mc.target_mc.body_txt.htmlText = this.main;
// Redefine scrolling info
maincontent_mc.scrollList();
// Enable all news items for clicking
for (i=0; i<_global.mynews; i++) {
newslist_mc.target_mc["trackclip"+i].enabled = true;
// And return them to their normal color
var newsColor = new Color(newslist_mc.target_mc["trackclip"+i]);
newsColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0});
}
// Set the selected news item to new color
var newsColor = new Color(this);
newsColor.setRGB(rollOverColor);
// Disable current news item for clicking
this.enabled = false;
};
}
// Set the selected year item to new color
var newsColor = new Color(this);
newsColor.setRGB(rollOverColor);
// Disable selected year item for clicking
this.enabled = false;
// Update news list for scrolling
newslist_mc.scrollList();
};
// Show the original state
yearitem.onRollOut = yearitem.onReleaseOutside=function () {
var yearColor = new Color(this);
yearColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0});
};
}
// Everything from this point forward initialized latest news info to display (not relying on user input)
// Initially set var for total news items for latest year
_global.mynews = newsNode.childNodes[0].childNodes.length;
for (i=0; i<_global.mynews; i++) {
// Var for attaching a news item
newsitem = newslist_mc.target_mc.attachMovie("newslink_mc", "trackclip"+i, i+1000);
// Position news list
newsitem._x = 0;
newsitem._y = 21*i;
// Set the text field to equal the XML values of latest news items
newsitem.date_txt.text = newsNode.childNodes[0].childNodes[i].childNodes[0].firstChild.nodeValue;
newsitem.title_txt.text = newsNode.childNodes[0].childNodes[i].childNodes[1].firstChild.nodeValue;
newsitem.main = newsNode.childNodes[0].childNodes[i].childNodes[2].firstChild.nodeValue;
newsitem.onRollOver = function() {
var newsColor = new Color(this);
newsColor.setRGB(rollOverColor);
};
// Show the original state
newsitem.onRollOut = newsitem.onReleaseOutside=function () {
var newsColor = new Color(this);
newsColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0});
};
newsitem.onRelease = function() {
// Reset text fields
resetBody();
// Set main body to newest news item
maincontent_mc.target_mc.title_txt.text = this.title_txt.text;
maincontent_mc.target_mc.date_txt.text = this.date_txt.text;
maincontent_mc.target_mc.body_txt.htmlText = this.main;
// Redefine scrolling vars
maincontent_mc.scrollList();
// Enable all news items
for (i=0; i<_global.mynews; i++) {
newslist_mc.target_mc["trackclip"+i].enabled = true;
// Reset colors to original state
var newsColor = new Color(newslist_mc.target_mc["trackclip"+i]);
newsColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0});
}
// Disable current
var newsColor = new Color(this);
newsColor.setRGB(rollOverColor);
this.enabled = false;
};
}
// Disable current year because it's already loaded
yearlist_mc.yearclip0.enabled = false;
// Set current year to new color
var yearColor = new Color(yearlist_mc.yearclip0);
yearColor.setRGB(rollOverColor);
// Set current news item to new color and disable
newslist_mc.target_mc.trackclip0.enabled = false;
var newsColor = new Color(newslist_mc.target_mc.trackclip0);
newsColor.setRGB(rollOverColor);
// Update main body with newest news item
maincontent_mc.target_mc.date_txt.text = newsNode.childNodes[0].childNodes[0].childNodes[0].firstChild.nodeValue;
maincontent_mc.target_mc.title_txt.text = newsNode.childNodes[0].childNodes[0].childNodes[1].firstChild.nodeValue;
maincontent_mc.target_mc.body_txt.text = newsNode.childNodes[0].childNodes[0].childNodes[2].firstChild.nodeValue;
maincontent_mc.scrollList();
// Update scroll vars
newslist_mc.scrollList();
} else {
trace("Cannot load XML");
}
};
// Load XML
kunderXML.load("http://blomquist.edited.se/rss_modify1.php?rss=http://blomquist.edited.se/index.php?option=com_content&view=category&id=40&Itemid=71&format=feed&type=rss");
// Function for fading in clips
function fadeIn(clip, speed, val) {
clip.onEnterFrame = function() {
clip._alpha += speed;
if (clip._alpha>=100) {
clip._alpha = 100;
delete clip.onEnterFrame;
}
};
}
// Reset all main body fields
function resetBody() {
maincontent_mc._alpha = 0;
maincontent_mc.target_mc._y = 0;
// Fade it in
fadeIn(maincontent_mc,6,100);
}
// Reset news item list
function resetList() {
newslist_mc._alpha = 0;
newslist_mc.target_mc._y = 0;
// Fade it in
fadeIn(newslist_mc,6,100);
// Remove old clips
for (i=0; i<999; i++) {
removeMovieClip(newslist_mc.target_mc["trackclip"+i]);
}
}
I am guessing that since it's a xml feed, the xml file is not possible to take measure from, so the preloader doesn't really know how big the file is. Is there any good workaround?
Bookmarks