View Full Version : B2 in Flash Kinda of (Figure this one out)
PhishIn4Dmb
09-01-2004, 11:42 AM
Ok I have have been using the B2 bloger in my flash site for some time now and was just happy that I figured a way to get in intergraded. I have since moved on to other more inportant things but now I really need to fix it.
With this code it loads everything fine except for like a 4 line break at the top of the blog. Not only that but I cant pictures to come in.
So I did some tweeking and finaly got it to bring in pictures, but then it would not scroll. The major difference is I published the site in Flash 7 AS 2.0
So what do I need to do to get this fully AS 2.0 compatable? Also I cant get the archive links to come up either. Good luck cause I have asked all around and what I got is the best I can do with my skills, I was luck to find someone with some XML and PHP knowledge to help me to get to this poing. Here is the code Boys thanks.
You can see the live Blog at www.xsxtreme.com
Peace
// ---------------------------------------------------------------
// b2flash
// read b2 blog system (RSS 0.90+ & RSS 1.00)
// design: erational <http://www.erational.org>
// version: 0.50
// date: 2002.12.12
// ---------------------------------------------------------------
// notice: to display URL, please edit b2config.php with $rss_encoded_html = 1; (line 169)
// ---------------------------------------------------------------
// 1. load category (once)
// ---------------------------------------------------------------
//uft8
category = new Array();
categID = new Array();
rssCat = new XML();
rssCat.ignoreWhite = true;
rssCat.load("http://www.xsxtreme.com/b2/b2flashxml.php?action=cat");
rssCat.onLoad = startDisplayCategory;
function startDisplayCategory(success) {
var rssData = new XML();
var i = 0;
if (success == true) {
rssData = rssCat.firstChild.childNodes;
while (i<=rssData.length) {
if (rssData[i].nodeName.toLowerCase() == "category") {
category[i] = rssData[i].firstChild.nodeValue;
categID[i] = rssData[i].attributes.id;
}
i++;
}
// -> gen combobox
myComboBox.addItem("All", "");
// list all categories, can be removed
for (i=0; i<category.length; i++) {
myComboBox.addItem(category[i], categID[i]);
}
getRSS("");
// load default
}
}
// -> combobox behaviour
onChange = function () {
getRSS(myComboBox.getValue());
};
// ---------------------------------------------------------------
// 2. load feed
// ---------------------------------------------------------------
function getRSS(id) {
rss = new XML();
rss.ignoreWhite = true;
rss.load("http://www.xsxtreme.com/b2/b2rss.php?cat="+id);
txtLoad = "";
loadingBar._visible = true;
rss.onLoad = startDisplay;
}
function startDisplay(success) {
if (success == true) {
loadingBar._visible = false;
txtLoad = "Loaded: "+Math.floor(rss.getBytesLoaded()/1024)+" Kilobytes";
// init
rssData = new Array();
myLink = new Array();
myTitle = new Array();
myDesc = new Array();
nbItem = 0;
// let's go !
rssData = rss.firstChild.childNodes;
i = 0;
while (i<=rssData.length) {
if (rssData[i].nodeName.toLowerCase() == "channel") {
parseRSSChannel(rssData[i]);
}
if (rssData[i].nodeName.toLowerCase() == "item") {
parseRSSItem(rssData[i]);
}
i++;
}
}
displayNews();
}
// displays the next news
function displayNews() {
txtMainString = "";
if (myTitle.length<1) {
attachMovie("mc_error", "myWarning", 11000);
myWarning._x = 335;
myWarning._y = 210;
} else {
for (i=0; i<myTitle.length; i++) {
txtMainString += "<font color=\"#C0BAA5\"><U><b>"+myTitle[i]+"</b></U></font><br>";
desc = convertHTML(myDesc[i]);
txtMainString += "<font color=\"#C0BAA5\">"+desc+"</font><br>";
txtMainString += "<u><font color=\"#666666\"><a href=\""+myLink[i]+"\" target=\"_blank\" >"+myLink[i]+"</a></font></u><br>";
txtMainString += "<br>";
}
txtMain.htmlText = txtMainString;
txtMain.setTextFormat(classicFormat);
}
}
//-----------------------------------------------------------------
// xml parser function
//-----------------------------------------------------------------
// parse <channel> object
function parseRSSChannel(xmlObject) {
rssTemp = xmlObject.childNodes;
var ii = 0;
while (ii<=rssTemp.length) {
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
channelTitle = rssTemp[ii].firstChild.nodeValue;
} else {
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
channelLink = rssTemp[ii].firstChild.nodeValue;
} else {
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
channelDesc = rssTemp[ii].firstChild.nodeValue;
} else {
// RSS 0.92
if (rssTemp[ii].nodeName.toLowerCase() == "item") {
parseRSSItem(rssTemp[ii]);
}
}
}
}
ii++;
}
}
// parse <item> object
function parseRSSItem(xmlObject) {
var rssTemp = xmlObject.childNodes;
var ii = 0;
nbItem++;
while (ii<=rssTemp.length) {
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
myTitle[nbItem] = rssTemp[ii].firstChild.nodeValue;
} else {
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
myLink[nbItem] = rssTemp[ii].firstChild.nodeValue;
} else {
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
myDesc[nbItem] = rssTemp[ii].firstChild.nodeValue;
}
}
}
ii++;
}
}
// ---------------------------------------------------------------
// misc. function
// ---------------------------------------------------------------
// underline link in given string
function convertHTML(txt) {
var tab = new Array();
var str = "";
var str2 = "";
var i = 0;
tab = txt.split("<a ");
tabL = tab.length;
for (i=0; i<tabL; i++) {
if (tab[i].indexOf("href") != -1) {
str += "<font color=\"#3399CC\"><u><a ";
}
str += tab[i];
}
tab = str.split("</a>");
tabL = tab.length;
for (i=0; i<tabL; i++) {
str2 += tab[i]+"</a></u></font>";
}
return str2;
}
// ---------------------------------------------------------------
// init
// ---------------------------------------------------------------
// globals var
rssTemp = new XML();
rssTemp.ignoreWhite = true;
rssTempData = new Array();
// projector and player options
fscommand("showmenu", false);
fscommand("allowscale", false);
fscommand("fullscreen", true);
// ---------------------------------------------------------------
// init component and text format
// ---------------------------------------------------------------
// -> main text
_root.createTextField("txtMain", 1, 182, 127, 293, 550);
txtMain.wordWrap = true;
txtMain.html = true;
txtMain.border = true;
txtMain.font = "Garmond";
txtMain.background = false;
initialization = {_targetInstanceName:"txtMain", horizontal:false};
_root.attachMovie("FScrollBarSymbol", "scrollMain", 2, initialization);
scrollMain._x = txtMain._x+txtMain._width;
scrollMain._y = txtMain._y;
scrollMain.setSize(txtMain._height);
// format txt
classicFormat = new TextFormat();
classicFormat.size = 16;
classicFormat.font = "Papyrus";
//-> myList
myList.setStyleProperty("textFont", "Papyrus");
myList.setStyleProperty("textSize", "10");
//->myCombo
myComboBox.setStyleProperty("textFont", "Papyrus");
myComboBox.setStyleProperty("textSize", "10");
PhishIn4Dmb
09-01-2004, 05:11 PM
Any one any one?
madgett
09-01-2004, 08:46 PM
I'm taking a look now...
madgett
09-01-2004, 11:39 PM
Ok I got it to work, however I completely changed the format of your code...haha, well not too bad, you should be able to catch on to what I did. It might take awhile to see the changes.
One important note:
Don't dynamically create text fields that you are going to have dynamically populated with HTML...the formatting just doesn't carry over nice. So just drag a textArea component on the stage and set the HTML value to true...it works nicely. I didn't make this look beautiful and all nice and formatted...I figure you know how to do that.
First make a blank Flash Doc and make your actions layer and a components layer...drag one combobox instance and one text area instance onto the stage. Name the combobox instance myComboBox and name the textArea instance txtMain. Copy the code below onto frame one of the Actions layer you created.
// ---------------------------------------------------------------
// b2flash
// read b2 blog system (RSS 0.90+ & RSS 1.00)
// design: erational <http://www.erational.org>
// version: 0.50
// date: 2002.12.12
// ---------------------------------------------------------------
// notice: to display URL, please edit b2config.php with $rss_encoded_html = 1; (line 169)
// ---------------------------------------------------------------
// 1. load category (once)
// ---------------------------------------------------------------
//uft8
category = new Array();
categID = new Array();
rssCat = new XML();
rssCat.ignoreWhite = true;
rssCat.load("http://www.xsxtreme.com/b2/b2flashxml.php?action=cat");
rssCat.onLoad = startDisplayCategory;
function startDisplayCategory(success) {
var rssData = new XML();
var i = 0;
if (success == true) {
rssData = rssCat.firstChild.childNodes;
trace("This is rssData = "+rssData);
trace("*********************END rssData");
while (i<=rssData.length) {
if (rssData[i].nodeName.toLowerCase() == "category") {
category[i] = rssData[i].firstChild.nodeValue;
categID[i] = rssData[i].attributes.id;
// Performing Traces
trace("This is category[i] = "+category[i]);
trace("This is categID[i] = "+categID[i]);
}
i++;
}
// -> gen combobox
myComboBox.addItem("All", "");
// list all categories, can be removed
for (i=0; i<category.length; i++) {
myComboBox.addItem(category[i], categID[i]);
}
//getRSS(""); /**************COMMENT THIS OUT*************/
// load default
createText();
// ************************ADDED THIS *************************
}
}
// -> combobox behaviour /************Need to add a proper listener function for the combobox
var myComboListener:Object = new Object();
myComboListener.change = function() {
getRSS(myComboBox.getValue());
};
myComboBox.addEventListener("change", myComboListener);
// ---------------------------------------------------------------
// 2. load feed
// ---------------------------------------------------------------
function getRSS(id) {
rss = new XML();
rss.ignoreWhite = true;
rss.load("http://www.xsxtreme.com/b2/b2rss.php?cat="+id);
txtLoad = "";
loadingBar._visible = true;
rss.onLoad = startDisplay;
// Call the startDisplay function on XML object onLoad
}
function startDisplay(success) {
// XML onLoad function relating to rss (XML object)
if (success == true) {
loadingBar._visible = false;
txtLoad = "Loaded: "+Math.floor(rss.getBytesLoaded()/1024)+" Kilobytes";
// init
var rssData:Array = new Array();
// RSSChannel init
var myLink:Array = new Array();
var myTitle:Array = new Array();
var myDesc:Array = new Array();
// RSSItem init
var myBodyLink:Array = new Array();
var myBodyTitle:Array = new Array();
var myBodyDesc:Array = new Array();
nbItem = 0;
// let's go !
trace("This is rss.firstChild.firstChild.childNodes.length = "+rss.firstChild.firstChild.childNodes.length);
var rssNodes:Number = rss.firstChild.firstChild.childNodes.length;
var RSSChannelXML:Array;
for (var i = 0; i<rssNodes; ++i) {
rssData.push(rss.firstChild.firstChild.childNodes[i]);
trace("This is rssData = "+rssData[i]);
//trace("rssData.length = "+rssData.length);
// Tracing 1 right now, that's not the intention
if (rssData.length == 3) {
parseRSSChannel(rssData);
// three values to be displayed within the Channel part of the XML object
trace("RSSDATA !!!!!!!!!!!!!!!! = "+rssData);
}
if (rssData[i].nodeName == "item") {
parseRSSItem(rssData[i]);
}
}
}
}
// displays the next news ***********************The <br> are not working...something with Flash rendering the html, work around that by using textArea component
function displayNews(thisTitle:Array, thisLink:Array, thisDesc:Array) {
//txtMainString = ""; /*******************THIS WAS MADE GLOBAL (on this frame)******************/
if (thisTitle.length<1) {
attachMovie("mc_error", "myWarning", 11000);
myWarning._x = 335;
myWarning._y = 210;
} else {
for (i=0; i<thisTitle.length; i++) {
trace("myTitle.length ???????????????????????? "+thisTitle.length);
txtMainString += "<font color=\"#C0BAA5\"><U><b>"+thisTitle[i]+"</b></U></font>";
txtMainString += "<br />";
//desc = convertHTML(myDesc[i]);
//txtMainString += "<font color=\"#C0BAA5\">"+desc+"</font><br>";
txtMainString += "<font color=\"#C0BAA5\">"+thisDesc[i]+"</font><p>";
txtMainString += "<u><font color=\"#666666\"><a href=\""+thisLink[i]+"\" target=\"_blank\" >"+thisLink[i]+"</a></font></u><p>";
txtMainString += "<br />";
}
txtMain.text = txtMainString;
txtMain.setTextFormat(classicFormat);
}
}
function displayRSSChannel(thisTitle:String, thisLink:String, thisDesc:String) {
txtMainString = "";
txtMainString = "<font color=\"#C0BAA5\"><U><b>"+thisTitle+"</b></U></font>";
txtMainString += "<br />";
//desc = convertHTML(myDesc[i]);
//txtMainString += "<font color=\"#C0BAA5\">"+desc+"</font><br>";
txtMainString += "<font color=\"#C0BAA5\">"+thisDesc+"</font><p>";
txtMainString += "<u><font color=\"#666666\"><a href=\""+thisLink+"\" target=\"_blank\" >"+thisLink+"</a></font></u><p>";
txtMainString += "<br />";
txtMain.htmlText = txtMainString;
txtMain.setTextFormat(classicFormat);
}
//-----------------------------------------------------------------
// xml parser function
//-----------------------------------------------------------------
// parse <channel> object
function parseRSSChannel(xmlObject) {
rssTemp = xmlObject;
trace("THIS IS xmlObject.childNodes****************** "+rssTemp);
//******************THIS contains the data of each nodeName => this is what needs to populate the textfield
var ii = 0;
// init empty arrays (free's of old data), this function will display undefined values without this
myTitle = [];
myLink = [];
myDesc = [];
while (ii<=rssTemp.length) {
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
myTitle[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myTitle:Array = "+myTitle[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
myLink[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myLink:Array = "+myLink[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
myDesc[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myDesc:Array = "+myDesc[0]);
}
ii++;
}
trace("in parseRSSChannel = "+myTitle[0]+" "+myLink[0]+" "+myDesc[0]);
displayRSSChannel(myTitle[0], myLink[0], myDesc[0]);
}
// parse <item> object
function parseRSSItem(xmlObject) {
var rssTemp = xmlObject.childNodes;
var ii = 0;
nbItem++;
myBodyTitle = [];
myBodyLink = [];
myBodyDesc = [];
while (ii<rssTemp.length) {
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
myBodyTitle.push(rssTemp[ii].firstChild.nodeValue);
}
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
myBodyLink.push(rssTemp[ii].firstChild.nodeValue);
}
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
myBodyDesc.push(rssTemp[ii].firstChild.nodeValue);
}
ii++;
}
trace("This is myBodyTitle[0] = "+myBodyTitle[0]);
displayNews(myBodyTitle, myBodyLink, myBodyDesc);
}
// ---------------------------------------------------------------
// misc. function
// ---------------------------------------------------------------
// underline link in given string
/*function convertHTML(txt) {
var tab = new Array();
var str = "";
var str2 = "";
var i = 0;
tab = txt.split("<a ");
tabL = tab.length;
for (i=0; i<tabL; i++) {
if (tab[i].indexOf("href") != -1) {
str += "<font color=\"#3399CC\"><u><a ";
}
str += tab[i];
}
tab = str.split("</a>");
tabL = tab.length;
for (i=0; i<tabL; i++) {
str2 += tab[i]+"</a></u></font>";
}
return str2;
}*/
// ---------------------------------------------------------------
// init
// ---------------------------------------------------------------
// globals var
rssTemp = new XML();
rssTemp.ignoreWhite = true;
rssTempData = new Array();
// projector and player options
fscommand("showmenu", false);
fscommand("allowscale", false);
fscommand("fullscreen", true);
// ---------------------------------------------------------------
// init component and text format
// ---------------------------------------------------------------
// -> main text
function createText() {
// ****************ADDED FUNCTION HERE *********************
//_root.createTextField("txtMain", 1, 182, 127, 293, 550);
txtMain.wordWrap = true;
txtMain.vScrollPolicy = "on";
txtMain.html = true;
txtMain.border = true;
txtMain.font = "Garmond";
txtMain.background = false;
initialization = {_targetInstanceName:"txtMain", horizontal:false};
_root.attachMovie("FScrollBarSymbol", "scrollMain", 2, initialization);
scrollMain._x = txtMain._x+txtMain._width;
scrollMain._y = txtMain._y;
scrollMain.setSize(txtMain._height);
// format txt
classicFormat = new TextFormat();
classicFormat.size = 16;
classicFormat.font = "Papyrus";
//-> myList
myList.setStyleProperty("textFont", "Papyrus");
myList.setStyleProperty("textSize", "10");
//->myCombo
myComboBox.setStyleProperty("textFont", "Papyrus");
myComboBox.setStyleProperty("textSize", "10");
}
Rudy's News (in the combobox) doesn't display anything because it has no "item" tag in the XML. It needs to have at least a blank one in order for it to show...the others work because they have the "item" tags.
Hope this works for you.
PhishIn4Dmb
09-02-2004, 11:10 AM
Madgett:
Sweet, well it looks much better now, and all I have to do is Skin it. Thanks for the help, it is much more complete now than it was befor. I did check out the code and I saw the ovbious changes and more than welcomed the txtfield componnet as apposed to dynamicaley creating one. Though alot of the XML dident make much sense to me :( I defentley learned something.
One more question for you, is there a way to get it to display one of the blogs automaticley. It just pulls up a blank field untill you select one of the catogories??
Thanks again I do aperacate the help :) Saving my butt :)
PhishIn4Dmb
09-02-2004, 11:19 AM
Ok one thing I just noticed, the dates are now missing. I looked over the code and figured that the PHP class ID name was left out. In any case If this is something that I can do easley let me know.
Also does the CSS in this PHP affect it at all when it comes into FLASH? Or can I just clean up this code?
Thanks again for the help
Sincerley
Steve Reynolds
Owner/Producer
XsXtreme
<?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; include ("blog.header.php"); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- layout credits goto http://bluerobot.com/web/layouts/layout2.html -->
<head>
<title><?php bloginfo('name') ?><?php single_post_title(' :: ') ?><?php single_cat_title(' :: ') ?><?php single_month_title(' :: ') ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="reply-to" content="<?php bloginfo('admin_email'); ?>" />
<meta http-equiv="imagetoolbar" content="no" />
<meta content="TRUE" name="MSSmartTagsPreventParsing" />
<<style type="text/css">
<!--body,td,table,p
{font-family: Times New Roman; font-size: 13px; color="white"; line-height:10px;}
A:link {text-decoration: none; font-weight:white; color: white;}
A:visited {text-decoration: underline; color: gray;}
A:hover {text-decoration: none; cursor:finger; color: blue; }
A:active {text-decoration: none; cursor:wait; color: white; }
--></style>
<style type="text/css">
body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
font-family: Times New Roman;
color: white ;
background-color: black;
text-align : Center;
scrollbar-arrow-color : #8E8E8E;
scrollbar-face-color : #EEEEEE;
scrollbar-highlight-color : #FFFFFF;
scrollbar-3dlight-color : #D3D3D3;
scrollbar-shadow-color : #DEDEDE;
scrollbar-darkshadow-color : #E9E9E9;
scrollbar-track-color : #8E8E8E;
}
</style> </style>
</head>
<body>
<div id="header"><a href="" title="<?php bloginfo('name'); ?>"><?php bloginfo('name'); ?></a></div>
<div id="content">
<!-- // b2 loop start -->
<?php while($row = mysql_fetch_object($result)) { start_b2(); ?>
<?php the_date("","<h2>","</h2>"); ?>
<?php permalink_anchor(); ?>
<div class="storyTitle"><?php the_title(); ?>
<a href="" title="category: <?php the_category() ?>"><span class="storyCategory">[<?php the_category() ?>]</span></a> -
<span class="storyAuthor"><?php the_author() ?> - <?php the_author_email() ?></span> @ <a href="<?php permalink_link() ?>"><?php the_time() ?></a>
</div>
<div class="storyContent">
<?php the_content(); ?>
<div class="rightFlush">
<?php link_pages("<br />Pages: ","<br />","number") ?>
<?php comments_popup_link("Comments (0)", "Comments (1)", "Comments (%)") ?>
<?php trackback_popup_link("TrackBack (0)", "TrackBack (1)", "TrackBack (%)") ?>
<?php pingback_popup_link("PingBack (0)", "PingBack (1)", "PingBack (%)") ?>
<?php trackback_rdf() ?>
<!-- this includes the comments and a form to add a new comment -->
<?php include ("b2comments.php"); ?>
<!-- this includes the trackbacks -->
<?php include ("b2trackback.php"); ?>
<!-- this includes the pingbacks -->
<?php include ("b2pingbacks.php"); ?>
</div>
</div>
<!-- // this is just the end of the motor - don't touch that line either :) -->
<?php } ?>
</div>
<div id="menu">
<h4>archives:</h4>
<?php include("b2archives.php"); ?>
<br />
<h4>other:</h4>
<a href="b2login.php" target="_blank">Admin login</a><br />
</div>
<!-- BlueRobot was here. -->
</body>
</html>
madgett
09-02-2004, 03:48 PM
I believe CSS is ignored when coming into Flash (statically) unless you specifically specify the PHP document in a Flash CSS style sheet object.
To get the text to automatically display onLoad...just add this to the function startDisplayCategory
getRSS(1); // It's already there but you can uncomment it out and add 1 as the parameter
The dates aren't displaying because the code is not configured to display the dates. If you want to add another nodeValue of the RSS Channel to be displayed all you have to do is edit the function parseRSSChannel and the function displayRSSChannel. Then you add a myDate parameter that the function can except, and another array value to hold the date object (if you look closesly you don't even need arrays for the parseRSSChannel, but since you started it with arrays I figured it best to keep them).
Here is the updated code to display the date, unformatted and automatically display the first option in the combobox:
// ---------------------------------------------------------------
// b2flash
// read b2 blog system (RSS 0.90+ & RSS 1.00)
// design: erational <http://www.erational.org>
// version: 0.50
// date: 2002.12.12
// ---------------------------------------------------------------
// notice: to display URL, please edit b2config.php with $rss_encoded_html = 1; (line 169)
// ---------------------------------------------------------------
// 1. load category (once)
// ---------------------------------------------------------------
//uft8
category = new Array();
categID = new Array();
rssCat = new XML();
rssCat.ignoreWhite = true;
rssCat.load("http://www.xsxtreme.com/b2/b2flashxml.php?action=cat");
rssCat.onLoad = startDisplayCategory;
function startDisplayCategory(success) {
var rssData = new XML();
var i = 0;
if (success == true) {
rssData = rssCat.firstChild.childNodes;
trace("This is rssData = "+rssData);
trace("*********************END rssData");
while (i<=rssData.length) {
if (rssData[i].nodeName.toLowerCase() == "category") {
category[i] = rssData[i].firstChild.nodeValue;
categID[i] = rssData[i].attributes.id;
// Performing Traces
trace("This is category[i] = "+category[i]);
trace("This is categID[i] = "+categID[i]);
}
i++;
}
// -> gen combobox
myComboBox.addItem("All", "");
// list all categories, can be removed
for (i=0; i<category.length; i++) {
myComboBox.addItem(category[i], categID[i]);
}
getRSS(1); /**************COMMENT THIS OUT*************/
// load default
createText();
// ************************ADDED THIS *************************
}
}
// -> combobox behaviour /************Need to add a proper listener function for the combobox
var myComboListener:Object = new Object();
myComboListener.change = function() {
getRSS(myComboBox.getValue());
};
myComboBox.addEventListener("change", myComboListener);
// ---------------------------------------------------------------
// 2. load feed
// ---------------------------------------------------------------
function getRSS(id) {
rss = new XML();
rss.ignoreWhite = true;
rss.load("http://www.xsxtreme.com/b2/b2rss.php?cat="+id);
txtLoad = "";
loadingBar._visible = true;
rss.onLoad = startDisplay;
// Call the startDisplay function on XML object onLoad
}
function startDisplay(success) {
// XML onLoad function relating to rss (XML object)
if (success == true) {
loadingBar._visible = false;
txtLoad = "Loaded: "+Math.floor(rss.getBytesLoaded()/1024)+" Kilobytes";
// init
var rssData:Array = new Array();
// RSSChannel init
var myDate:Array = new Array(); // *****************Date Array
var myLink:Array = new Array();
var myTitle:Array = new Array();
var myDesc:Array = new Array();
// RSSItem init
var myBodyLink:Array = new Array();
var myBodyTitle:Array = new Array();
var myBodyDesc:Array = new Array();
nbItem = 0;
// let's go !
trace("This is rss.firstChild.firstChild.childNodes.length = "+rss.firstChild.firstChild.childNodes.length);
var rssNodes:Number = rss.firstChild.firstChild.childNodes.length;
var RSSChannelXML:Array;
for (var i = 0; i<rssNodes; ++i) {
rssData.push(rss.firstChild.firstChild.childNodes[i]);
trace("This is rssData = "+rssData[i]);
//trace("rssData.length = "+rssData.length);
// Tracing 1 right now, that's not the intention
if (rssData.length < 9) {
parseRSSChannel(rssData);
// three values to be displayed within the Channel part of the XML object
trace("RSSDATA !!!!!!!!!!!!!!!! = "+rssData);
}
if (rssData[i].nodeName == "item") {
parseRSSItem(rssData[i]);
}
}
}
}
// displays the next news ***********************The <br> are not working...something with Flash rendering the html, work around that by using textArea component
function displayNews(thisTitle:Array, thisLink:Array, thisDesc:Array) {
//txtMainString = ""; /*******************THIS WAS MADE GLOBAL (on this frame)******************/
if (thisTitle.length<1) {
attachMovie("mc_error", "myWarning", 11000);
myWarning._x = 335;
myWarning._y = 210;
} else {
for (i=0; i<thisTitle.length; i++) {
trace("myTitle.length ???????????????????????? "+thisTitle.length);
txtMainString += "<font color=\"#C0BAA5\"><U><b>"+thisTitle[i]+"</b></U></font>";
txtMainString += "<br />";
//desc = convertHTML(myDesc[i]);
//txtMainString += "<font color=\"#C0BAA5\">"+desc+"</font><br>";
txtMainString += "<font color=\"#C0BAA5\">"+thisDesc[i]+"</font><p>";
txtMainString += "<u><font color=\"#666666\"><a href=\""+thisLink[i]+"\" target=\"_blank\" >"+thisLink[i]+"</a></font></u><p>";
txtMainString += "<br />";
}
txtMain.text = txtMainString;
txtMain.setTextFormat(classicFormat);
}
}
function displayRSSChannel(thisTitle:String, thisLink:String, thisDesc:String, thisDate:String) {
txtMainString = "";
txtMainString = thisDate+"<br>"; // ****************************ADD THIS to show date ***********
txtMainString += "<font color=\"#C0BAA5\"><U><b>"+thisTitle+"</b></U></font>";
txtMainString += "<br />";
//desc = convertHTML(myDesc[i]);
//txtMainString += "<font color=\"#C0BAA5\">"+desc+"</font><br>";
txtMainString += "<font color=\"#C0BAA5\">"+thisDesc+"</font><p>";
txtMainString += "<u><font color=\"#666666\"><a href=\""+thisLink+"\" target=\"_blank\" >"+thisLink+"</a></font></u><p>";
txtMainString += "<br />";
txtMain.htmlText = txtMainString;
txtMain.setTextFormat(classicFormat);
}
//-----------------------------------------------------------------
// xml parser function
//-----------------------------------------------------------------
// parse <channel> object
function parseRSSChannel(xmlObject) {
rssTemp = xmlObject;
trace("THIS IS xmlObject.childNodes****************** "+rssTemp);
//******************THIS contains the data of each nodeName => this is what needs to populate the textfield
var ii = 0;
// init empty arrays (free's of old data), this function will display undefined values without this
myTitle = [];
myLink = [];
myDesc = [];
myDate = [];
while (ii<=rssTemp.length) {
// The if statement below adds the date
if (rssTemp[ii].nodeName.toLowerCase() == "lastbuilddate") {
myDate[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myDate:Array = "+myDate[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
myTitle[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myTitle:Array = "+myTitle[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
myLink[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myLink:Array = "+myLink[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
myDesc[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myDesc:Array = "+myDesc[0]);
}
ii++;
}
trace("in parseRSSChannel = "+myTitle[0]+" "+myLink[0]+" "+myDesc[0]);
displayRSSChannel(myTitle[0], myLink[0], myDesc[0], myDate[0]);
}
// parse <item> object
function parseRSSItem(xmlObject) {
var rssTemp = xmlObject.childNodes;
var ii = 0;
nbItem++;
myBodyTitle = [];
myBodyLink = [];
myBodyDesc = [];
while (ii<rssTemp.length) {
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
myBodyTitle.push(rssTemp[ii].firstChild.nodeValue);
}
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
myBodyLink.push(rssTemp[ii].firstChild.nodeValue);
}
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
myBodyDesc.push(rssTemp[ii].firstChild.nodeValue);
}
ii++;
}
trace("This is myBodyTitle[0] = "+myBodyTitle[0]);
displayNews(myBodyTitle, myBodyLink, myBodyDesc);
}
// ---------------------------------------------------------------
// misc. function
// ---------------------------------------------------------------
// underline link in given string
/*function convertHTML(txt) {
var tab = new Array();
var str = "";
var str2 = "";
var i = 0;
tab = txt.split("<a ");
tabL = tab.length;
for (i=0; i<tabL; i++) {
if (tab[i].indexOf("href") != -1) {
str += "<font color=\"#3399CC\"><u><a ";
}
str += tab[i];
}
tab = str.split("</a>");
tabL = tab.length;
for (i=0; i<tabL; i++) {
str2 += tab[i]+"</a></u></font>";
}
return str2;
}*/
// ---------------------------------------------------------------
// init
// ---------------------------------------------------------------
// globals var
rssTemp = new XML();
rssTemp.ignoreWhite = true;
rssTempData = new Array();
// projector and player options
fscommand("showmenu", false);
fscommand("allowscale", false);
fscommand("fullscreen", true);
// ---------------------------------------------------------------
// init component and text format
// ---------------------------------------------------------------
// -> main text
function createText() {
// ****************ADDED FUNCTION HERE *********************
//_root.createTextField("txtMain", 1, 182, 127, 293, 550);
txtMain.wordWrap = true;
txtMain.vScrollPolicy = "on";
txtMain.html = true;
txtMain.border = true;
txtMain.font = "Garmond";
txtMain.background = false;
initialization = {_targetInstanceName:"txtMain", horizontal:false};
_root.attachMovie("FScrollBarSymbol", "scrollMain", 2, initialization);
scrollMain._x = txtMain._x+txtMain._width;
scrollMain._y = txtMain._y;
scrollMain.setSize(txtMain._height);
// format txt
classicFormat = new TextFormat();
classicFormat.size = 16;
classicFormat.font = "Papyrus";
//-> myList
myList.setStyleProperty("textFont", "Papyrus");
myList.setStyleProperty("textSize", "10");
//->myCombo
myComboBox.setStyleProperty("textFont", "Papyrus");
myComboBox.setStyleProperty("textSize", "10");
}
PhishIn4Dmb
09-03-2004, 10:37 AM
Sweet well I feel like I know this code backwards and forwards. Though I couldent write it from scratch I defentley understand 90% of what is going on. I tweeked out the code to make it more acceptable to my viewing pleasure as well as took out some misc code that was not needed.
I saw all the changes you did and thanks again. But I got a couple more for you. I noticed that it only posted a date on my displayRSSChannel So I went in and added the nesscary code to add the date to my displayNews which brings up the current news threads.
Course I went through my PHP and noticed that it dident have any other name except for the lastbuilddate. So I decided that the current news feeds would use the same name and preceded to code it all. (you have no idea how trying this is for me)
So I think I got it coded right but when I Publish the area where the date is supose to go is UNDEFINED. Now I am guessing this has everything to do with the PHP file? In my last blog it did desply the dates on all the posts, so it's got to be in there somewhere. Do you have any clue? Cause there is no other mention of it in there.
Again I was working my brain to do the code my self so I am not just getting hand outs. I do thanke you for the help for now I understand XML and PHP soooo much more now.
My last question: In flash you cant format the text in a txtField can you? Atleast that is what it looks like from the posts on the site. I can get the color, boldness, underline and all that. But I cant get the font or the alingement to change. I am pretty sure I got the code right, with the embedded font..
Well I hope I am not takeing all your time. Thanks again, you simplyfyied my Site sooo much.
Sincerley
Steve Reynolds
P.S. It can be seen here on my site www.xsxtreme.com (http://www.xsxtreme.com/index.swf)
category = new Array();
categID = new Array();
rssCat = new XML();
rssCat.ignoreWhite = true;
rssCat.load("http://www.xsxtreme.com/b2/b2flashxml.php?action=cat");
rssCat.onLoad = startDisplayCategory;
function startDisplayCategory(success) {
var rssData = new XML();
var i = 0;
if (success == true) {
rssData = rssCat.firstChild.childNodes;
trace("This is rssData = "+rssData);
trace("*********************END rssData");
while (i<=rssData.length) {
if (rssData[i].nodeName.toLowerCase() == "category") {
category[i] = rssData[i].firstChild.nodeValue;
categID[i] = rssData[i].attributes.id;
// Performing Traces
trace("This is category[i] = "+category[i]);
trace("This is categID[i] = "+categID[i]);
}
i++;
}
// -> gen combobox
myComboBox.addItem("All", "");
// list all categories, can be removed
for (i=0; i<category.length; i++) {
myComboBox.addItem(category[i], categID[i]);
}
getRSS(1);
createText();
}
}
// ---------------------------------------------------------------
// 2. load feed
// ---------------------------------------------------------------
function getRSS(id) {
rss = new XML();
rss.ignoreWhite = true;
rss.load("http://www.xsxtreme.com/b2/b2rss.php?cat="+id);
txtLoad = "";
loadingBar._visible = true;
rss.onLoad = startDisplay;
// Call the startDisplay function on XML object onLoad
}
function startDisplay(success) {
// XML onLoad function relating to rss (XML object)
if (success == true) {
loadingBar._visible = false;
txtLoad = "Loaded: "+Math.floor(rss.getBytesLoaded()/1024)+" Kilobytes";
// init
var rssData:Array = new Array();
// RSSChannel init
var myDate:Array = new Array(); // *****************Date Array
var myLink:Array = new Array();
var myTitle:Array = new Array();
var myDesc:Array = new Array();
// RSSItem init
var myBodyLink:Array = new Array();
var myBodyTitle:Array = new Array();
var myBodyDesc:Array = new Array();
var myBodyDate:Array = new Array(); //I added this
nbItem = 0;
// let's go !
trace("This is rss.firstChild.firstChild.childNodes.length = "+rss.firstChild.firstChild.childNodes.length);
var rssNodes:Number = rss.firstChild.firstChild.childNodes.length;
var RSSChannelXML:Array;
for (var i = 0; i<rssNodes; ++i) {
rssData.push(rss.firstChild.firstChild.childNodes[i]);
trace("This is rssData = "+rssData[i]);
if (rssData.length < 9) {
parseRSSChannel(rssData);
// three values to be displayed within the Channel part of the XML object
trace("RSSDATA !!!!!!!!!!!!!!!! = "+rssData);
}
if (rssData[i].nodeName == "item") {
parseRSSItem(rssData[i]);
}
}
}
}
// displays the Channel
function displayRSSChannel(thisTitle:String, thisLink:String, thisDesc:String, thisDate:String) {
txtMainString = "";
txtMainString = "<font color=\"#FFFFFF\"><U><b>"+thisDate+"</b></U></font><br>"; // ******ADD THIS to show date
txtMainString += "<font color=\"#C0BAA5\"><U><b>"+thisTitle+"</b></U></font>";
txtMainString += "<br><br/>";
txtMain.htmlText = txtMainString;
txtMain.setTextFormat(classicFormat);
}
// displays the news
function displayNews(thisTitle:Array, thisLink:Array, thisDesc:Array, thisDate:Array) {
for (i=0; i<thisTitle.length; i++) {
trace("myTitle.length ???????????????????????? "+thisTitle.length);
txtMainString += "<font color=\"#666666\"><U><b>"+thisDate[i]+"</b></U></font>";
txtMainString += "<font color=\"#C0BAA5\"><U><b>"+thisTitle[i]+"</b></U></font>";
txtMainString += "<br/>";
txtMainString += "<font color=\"#C0BAA5\">"+thisDesc[i]+"</font><p>";
txtMainString += "<br>";
txtMainString += "<u><font color=\"#666666\"><a href=\""+thisLink[i]+"\" target=\"_blank\" >"+thisLink[i]+"</a></font></u><p>";
txtMainString += "<br><br/>";
txtMainString += "<br><br/>";
}
txtMain.text = txtMainString;
txtMain.setTextFormat(classicFormat);
}
//-----------------------------------------------------------------
// xml parser function
//-----------------------------------------------------------------
// parse <channel> object
function parseRSSChannel(xmlObject) {
rssTemp = xmlObject;
trace("THIS IS xmlObject.childNodes****************** "+rssTemp);
//******************THIS contains the data of each nodeName => this is what needs to populate the textfield
var ii = 0;
// init empty arrays (free's of old data), this function will display undefined values without this
myTitle = [];
myLink = [];
myDesc = [];
myDate = [];
while (ii<=rssTemp.length) {
// The if statement below adds the date
if (rssTemp[ii].nodeName.toLowerCase() == "lastbuilddate") {
myDate[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myDate:Array = "+myDate[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
myTitle[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myTitle:Array = "+myTitle[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
myLink[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myLink:Array = "+myLink[0]);
}
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
myDesc[0] = rssTemp[ii].firstChild.nodeValue;
trace("Function parseRSSChannel, myDesc:Array = "+myDesc[0]);
}
ii++;
}
trace("in parseRSSChannel = "+myTitle[0]+" "+myLink[0]+" "+myDesc[0]);
displayRSSChannel(myTitle[0], myLink[0], myDesc[0], myDate[0]);
}
// parse <item> object
function parseRSSItem(xmlObject) {
var rssTemp = xmlObject.childNodes;
var ii = 0;
nbItem++;
myBodyTitle = [];
myBodyLink = [];
myBodyDesc = [];
myBodyDate = [];
while (ii<rssTemp.length) {
if (rssTemp[ii].nodeName.toLowerCase() == "title") {
myBodyTitle.push(rssTemp[ii].firstChild.nodeValue);
}
if (rssTemp[ii].nodeName.toLowerCase() == "link") {
myBodyLink.push(rssTemp[ii].firstChild.nodeValue);
}
if (rssTemp[ii].nodeName.toLowerCase() == "description") {
myBodyDesc.push(rssTemp[ii].firstChild.nodeValue);
}
if (rssTemp[ii].nodeName.toLowerCase() == "lastbuilddate") {
myBodyDate.push(rssTemp[ii].firstChild.nodeValue);
}
ii++;
}
trace("This is myBodyTitle[0] = "+myBodyTitle[0]);
displayNews(myBodyTitle, myBodyLink, myBodyDesc, myBodyDate);
}
// ---------------------------------------------------------------
// misc. function
// ---------------------------------------------------------------
rssTemp = new XML();
rssTemp.ignoreWhite = true;
rssTempData = new Array();
// projector and player options
fscommand("showmenu", false);
fscommand("allowscale", false);
fscommand("fullscreen", true);
// ---------------------------------------------------------------
// init component and text format
// ---------------------------------------------------------------
// -> txtMain Field
function createText() {
txtMain.setStyle("backgroundColor", "black");
txtMain.wordWrap = true;
txtMain.vScrollPolicy = "on";
txtMain.html = true;
txtMain.background = false;
txtMain.setStyle("border", "false");
txtMain.setStyle("embedFonts", "true");
txtMain.setStyle("fontFamily", "papyrus");
txtMain.setStyle("textAlign", "center");
// format txt
classicFormat = new TextFormat();
classicFormat.size = 16;
classicFormat.font = "Papyrus";
//->myComboBox
myComboBox.setStyle("color", "white");
myComboBox.setStyle("backgroundColor", "black");
myComboBox.setStyle("rollOverColor", "0xAAAAAA");
myComboBox.setStyle("selectionColor", "0xAAAAAA");
myComboBox.setStyle("embedFonts", "true");
myComboBox.setStyle("fontFamily", "papyrus");
}
madgett
09-03-2004, 09:39 PM
Your RSS feeds are outputted by the server-side script into an XML format. What I did to find out what kind of XML was being outputted was to go straight to the page in the browser.
Notice your function getRSS(id)
function getRSS(id) {
rss = new XML();
rss.ignoreWhite = true;
rss.load("http://www.xsxtreme.com/b2/b2rss.php?cat="+id);
txtLoad = "";
loadingBar._visible = true;
rss.onLoad = startDisplay;
// Call the startDisplay function on XML object onLoad
}
The bold part is where Flash's XML object is being populated from...so I took that link and replaced 1 in "id" to get: http://www.xsxtreme.com/b2/b2rss.php?cat=1
If you put that into your browser and pull up the RSS feed (which is in XML format) then you can see all the nodes that Flash is parsing. Notice that there is no lastBuildDate inside any of the item nodes. That is why what you are doing isn't working...what you can do is make the PHP output the missing node or just use the one in the top of the Channel part.
Perform a search in the help on these to find out about CSS text formatting:
Supported CSS properties
Loading external CSS files
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.