PibbTibbs
04-10-2008, 07:00 PM
Hi All
I have built a little news reader in Actionscript 3. I am having a problem with assigning the url property for each news item. Being completely new to as3 i was thinking that i may be doing this all wrong so i hope somebody can help.
here is the script in quetion:
import fl.motion.easing.*;
import flash.net.navigateToURL;
import gs.TweenLite;
var ySpacing:Number = 55;
var itemCount:Number = 0;
var pageNum:Number = 1;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("newsReader.php"));
function loadXML(e:Event):void
{
var xml = new XML(e.target.data);
for (var i=0;i<xml.item.length();i++) {
var newsBit:newsClip = new newsClip();
newsBit.newsHeader.htmlText = "<b>" + xml.item.newsHeader[i] + "</b>";
newsBit.newsDate.htmlText = "<b>" + xml.item.newsDate[i] + "</b>";
newsBit.newsText.htmlText = xml.item.newsText[i];
if (xml.item.newsLink[i] != "") {
var clickObj:moreInfo = new moreInfo();
clickObj.y = 43;
clickObj.x = 175;
clickObj.goToLink = new URLRequest();
clickObj.goToLink.url = xml.item.newsLink[i];
clickObj.addEventListener(MouseEvent.CLICK, loadLink);
function loadLink() {
navigateToURL(clickObj.goToLink, "_parent");
}
newsBit.addChild(clickObj);
}
newsBit.y = itemCount * ySpacing;
newsHolder.addChild(newsBit);
itemCount++
}
}
Everything works great except that no matter which clickObj you click, the URLRequest always loads the last item from the xml. I am thinking that a unique instance of the URLRequest object is not being created on each loop pass so the url parameter of the URLRequest object is being overwritten with the last value in the xml ech time around.
Can anyone shed some light on what i can do?
Thanks
pT
I have built a little news reader in Actionscript 3. I am having a problem with assigning the url property for each news item. Being completely new to as3 i was thinking that i may be doing this all wrong so i hope somebody can help.
here is the script in quetion:
import fl.motion.easing.*;
import flash.net.navigateToURL;
import gs.TweenLite;
var ySpacing:Number = 55;
var itemCount:Number = 0;
var pageNum:Number = 1;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("newsReader.php"));
function loadXML(e:Event):void
{
var xml = new XML(e.target.data);
for (var i=0;i<xml.item.length();i++) {
var newsBit:newsClip = new newsClip();
newsBit.newsHeader.htmlText = "<b>" + xml.item.newsHeader[i] + "</b>";
newsBit.newsDate.htmlText = "<b>" + xml.item.newsDate[i] + "</b>";
newsBit.newsText.htmlText = xml.item.newsText[i];
if (xml.item.newsLink[i] != "") {
var clickObj:moreInfo = new moreInfo();
clickObj.y = 43;
clickObj.x = 175;
clickObj.goToLink = new URLRequest();
clickObj.goToLink.url = xml.item.newsLink[i];
clickObj.addEventListener(MouseEvent.CLICK, loadLink);
function loadLink() {
navigateToURL(clickObj.goToLink, "_parent");
}
newsBit.addChild(clickObj);
}
newsBit.y = itemCount * ySpacing;
newsHolder.addChild(newsBit);
itemCount++
}
}
Everything works great except that no matter which clickObj you click, the URLRequest always loads the last item from the xml. I am thinking that a unique instance of the URLRequest object is not being created on each loop pass so the url parameter of the URLRequest object is being overwritten with the last value in the xml ech time around.
Can anyone shed some light on what i can do?
Thanks
pT