PDA

View Full Version : Problem with AS (text) file, help please


SteveH
06-14-2008, 06:12 PM
Hello

I am trying to get a newsfeed to work on a test MX 2004 Flash site here:

http://stevehigham59.7host.com/feed/news.html

I have used the script from an online tutorial and changed only the xml link to the BBC.

I am getting a 'connect failed' error message and I'm not sure why. I have an aspx file (which is fine), an FLA, and an external AS text file. Here is the script for it:

function set_gStyles(){
tStyle = new TextFormat();
tStyle.font = "verdana";
tStyle.color = parseInt("ffffff",16);
tStyle.leftMargin = 5;
}
/////////////////////////////////////////////////////

function chk_server_conn(){
_root.createTextField("item_text",0,0,(_root["newsitem_text"]._y)+23,300,16);
tStyle.size = 10;
_root["item_text"].selectable = false;
_root["item_text"].text = "Checking Server Connection";
_root["item_text"].setTextFormat(tStyle);
}
/////////////////////////////////////////////////////

function showErrMsg(){
tStyle.size = 10;
_root["item_text"].text = "Connection Failed";
_root["item_text"].setTextFormat(tStyle);
}
/////////////////////////////////////////////////////

function make_header(){
_root.createEmptyMovieClip ("headerbg", -1);
with (_root["headerbg"]){
beginFill (0x284E75);
lineStyle (.5, 0x333333, 100);
moveTo (0, 0);
lineTo (0, 23);
lineTo (450, 23);
lineTo (450, 0);
endFill();
}

_root["headerbg"].createTextField("header",110,0,0,300,16);
_root["headerbg"]["header"].text = "BBC Internet News";
_root["headerbg"]["header"].type = "static";
_root["headerbg"]["header"].selectable = false;
_root["headerbg"]["header"].autoSize = "left";
tStyle.size = 14;
_root["headerbg"]["header"].setTextFormat(tStyle);
}
/////////////////////////////////////////////////////

function make_newsitem(){
_root.createEmptyMovieClip ("news_item", -20);
with (_root["news_item"]){
moveTo (0, 10);
beginFill (0x336699);
moveTo (0, 23);
lineTo (0, 40);
lineTo (450, 40);
lineTo (450, 23);
endFill();
}
}
/////////////////////////////////////////////////////

function makeList(tAry,uAry){
for (var i=0,j=1;i<uAry.length;i++,j++){
duplicateMovieClip(_root["news_item"],"news_item"+i,i);
_root["news_item"+i]._y = (_root["news_item"]._y + ((_root["news_item"]._height-1) * i));
_root.createTextField("item_text"+i,j*10,0,(_root["news_item"+i]._y)+24,300,14);
this["news_item"+i].theUrl=uAry[i];
this["news_item"+i].item_index = i;
this["item_text"+i].selectable = false;
this["item_text"+i].autoSize = "left";
this["item_text"+i].text=tAry[i];
tStyle.size = 10;
this["item_text"+i].setTextFormat(tStyle);


this["news_item"+i].onRollOver = function(myColor){
var myBg = new Color(this);
myBg.setRGB(parseInt("aaaaaa",16));
var myFontColor = new Color(_root["item_text"+this.item_index]);
myFontColor.setRGB(parseInt("333333",16));
}


this["news_item"+i].onRollOut = function(){
var myBg = new Color(this);
myBg.setRGB(parseInt("336699",16));
var myFontColor = new Color(_root["item_text"+this.item_index]);
myFontColor.setRGB(parseInt("ffffff",16));
}

this["news_item"+i].onRelease = function(){
getURL(this.theUrl,"_blank");
}
}
}
/////////////////////////////////////////////////////

function get_news(){
ret = new LoadVars();
ret.onLoad = function(success){
if(success){
ret.myUrlAry = ret.theUrls.split('|');
ret.myTitleAry = ret.theTitles.split('|');

makeList(ret.myTitleAry,ret.myUrlAry);
} else {
showErrMsg();
}
}

// load the values from "getNews.aspx"
ret.load("getNews.txt");
}
/////////////////////////////////////////////////////

function init(){
set_gStyles();
chk_server_conn();
make_newsitem();
make_header();
get_news();
}
/////////////////////////////////////////////////////

init();
/////////////////////////////////////////////////////

Is there anything obviously wrong here and, if not, what might cause me to get the error message?

Many thanks.

Steve

gnomeontherun
06-14-2008, 08:26 PM
Does the xml feed output in the same format as the BBC?

SteveH
06-17-2008, 11:05 AM
Hello Jeremy

Thanks for your post.

I'm not sure how I would verify that and I'm not sure if incorrect formatting would give me a 'can't connect to the server' message.

I have confirmed with feedburner.com that the feed address is verifiable.

Steve

gnomeontherun
06-17-2008, 06:06 PM
What does the getNews.txt contain?

SteveH
06-17-2008, 06:36 PM
Hello Jeremy

Thanks for posting back.

'getNews', referred to in the AS, is an ASPX file which contains the link to the feed:

<%@ Import NameSpace="System" %>
<%@ Import NameSpace="System.Net" %>
<%@ Import NameSpace="System.IO" %>
<%@ Import NameSpace="System.Text.RegularExpressions" %>
<script language="C#" runat="server">


string _path = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml";

public void Page_Load(Object sender, EventArgs e) {
getData(_path);
}

protected void getData(string url){

string _url = "";
string _urlAry = "";
string _desc = "";
string _descAry = "";
string _titleAry = "";

WebClient request = new WebClient();

Stream s = request.OpenRead(url);

StreamReader sr = new StreamReader(s);

Regex myRegex = new Regex(@"(<url>.*</url>)|(<title>.*</title>)");

MatchCollection mc = myRegex.Matches(sr.ReadToEnd());

foreach (Match m in mc){

if (m.Value.IndexOf("url") > 0){

_url = m.Value;

_url = _url.Replace("<url>","");
_url = _url.Replace("</url>","");

_urlAry += _url + "|";
} else {

_desc = m.Value;
_desc = _desc.Replace("<title>","");
_desc = _desc.Replace("</title>","");
_descAry += _desc + "|";
}
}

_descAry = _descAry.Substring(0,_descAry.Length-1);
_urlAry = _urlAry.Substring(0,_urlAry.Length-1);

Response.Write ("theUrls="+Server.UrlEncode(_urlAry)+"&theTitles="+Server.UrlEncode(_descAry));
}
</script>

I have posted this to the ASP.NET forum and they have given it the 'thumbs up'.

I have even contacted the BBC to ask them for verification that the link/path is correct - they haven't come back to me yet.

I suppose I could try it with another path to another RSS feed - if I can find one.

AS I say, I got this from a Flash MX 2004 tutorial and the original link went to Macromedia; it doens't work now - I just get directed to the Adobe site.

Cheers

Steve

gnomeontherun
06-17-2008, 06:49 PM
// load the values from "getNews.aspx"
ret.load("getNews.txt");
}

Then why is the getNews.txt being called? Did you change this value? Should it be calling getNews.aspx? I know nothing about ASP, but I'm guessing it outputs the latest right?