FORUMS: list search recent posts

AS3 and xml

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
travis farrenkopf
AS3 and xml
on Aug 8, 2008 at 4:19:07 pm

I have two xml loaders in my flash file. One xml loads news and the other loads the weather. The news xml loader is on the timeline and the weather widget is a movie clip that contains the code in the timeline of the movie clip. If the file is executed with both "widgets" I get the following error in the output. However, the file runs smoothly if only the news loader or only the weather widget is on the timeline. None of them have variables with the same name.

Retrieving Weather Forecast RSS for Zipcode: 02215
ReferenceError: Error #1065: Variable redsoxXML is not defined.
at pru_news_fla::forecast_clip_8/loadRSS()
at pru_news_fla::forecast_clip_8/pru_news_fla::frame1()

XML Widget Code:

import flash.events.Event;

var redsoxXML:XML = new XML();
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("http://www.windowgain.com/antflash/rss/MassNews/massnews.php"));
myLoader.addEventListener(Event.COMPLETE, process_xml);

function process_xml(e:Event):void {
redsoxXML = new XML(e.target.data);
if (redsoxXML.namespace("") != undefined) {
default xml namespace = redsoxXML.namespace("");
};


headline1.text = redsoxXML.item[2].title;
body1.text = redsoxXML.item[2].description;
headline2.text = redsoxXML.item[3].title;
body2.text = redsoxXML.item[3].description;

}

Weather Widget Code:

import flash.display.StageScaleMode;
import flash.display.StageAlign;

// For the Alpha tween effects - Src @ http://blog.greensock.com/tweenliteas3
import gs.TweenLite;

var XMLLoader;
var IMAGE_PREFIX = "http://l.yimg.com/us.yimg.com/i/us/nws/weather/gr/";
var IMAGE_SUFFIX = "d.png";

var IMAGE_WIDTH = 100;
var SPACING = 50;
var TWEENFX = 2;


// If the zipcode starts with a 0, the entire zipcode must be in quotes
var DEFAULT_ZIPCODE = "02215";


// **************************
// ** Load XML
// **************************
function loadRSS(url:String):XML {
XMLLoader = new URLLoader(new URLRequest(url));
XMLLoader.addEventListener("complete", xmlLoaded);
}

function xmlLoaded(evtObj:Event):void
{
var _XML:XML = new XML();
_XML.ignoreWhite = true;

XMLString = XMLLoader.data;
XMLString = XMLString.split("yweather:").join("yweather_");
_XML = XML(XMLString);

if (_XML.namespace("") != undefined) {
default xml namespace = _XML.namespace("");
}
days = new Array();
tweather = new Object();
var elem = _XML.channel.item["yweather_condition"];
tweather["desc"] = elem.@text;
tweather["dayname"] = "Today";
tweather["date"] = elem.@date;
tweather["temp_main"] = elem.@temp;
tweather["temp_main_label"] = "Currently:";
tweather["temp_alt"] = null;
tweather["image_url"] = IMAGE_PREFIX + elem.@code + IMAGE_SUFFIX;
days.push(tweather);

for each (elem in _XML.channel.item["yweather_forecast"]) {
tweather = new Object();
tweather["desc"] = elem.@text;
tweather["dayname"] = elem.@day;
tweather["temp_main"] = elem.@high;
tweather["temp_main_label"] = "High:";
tweather["temp_alt"] = elem.@low;
tweather["temp_alt_label"] = "Low:";
tweather["image_url"] = IMAGE_PREFIX + elem.@code + IMAGE_SUFFIX;
days.push(tweather);
}


if (days[0].date.indexOf(days[1].dayname) != -1) {
// It is mid day, and the next forecast entry is for tonight
days[1].dayname = 'Tonight';
days[1]["temp_main"] = days[1]["temp_alt"];
days[1]["temp_main_label"] = days[1]["temp_alt_label"];
days[1]["temp_alt"] = null;
} else {
days[0].dayname = 'Tonight';
days[0]["temp_main"] = days[1]["temp_alt"];
days[0]["temp_main_label"] = days[1]["temp_alt_label"];
days[0]["temp_alt"] = null;
}

for (elem in days) {
day = days[elem];
day["mc"] = new forecast();
day.mc.initApp(day);
this.addChild(day.mc);
day.mc.x = elem * day.mc.bg.width/2;
// ldrThumb.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
// ldrThumb.contentLoaderInfo.addEventListener(Event.COMPLETE, progressHandler);


ow = day.mc.bg.width;
oh = day.mc.bg.height;
if (TWEENFX == 1) {
day.mc.alpha = 0;
day.mc.scaleX = 1.25;
day.mc.scaleY = 1.25;
TweenLite.delayedCall(elem * 0.75, TweenLite.to, [day.mc, 0.75, {alpha:1, scaleX:.5, scaleY:.5, x:day.mc.x, y:day.mc.y}]);
day.mc.x += (ow-(day.mc.bg.width * day.mc.scaleX))/2;
day.mc.y += (oh-(day.mc.bg.height * day.mc.scaleY))/2;
} else if (TWEENFX == 2) {
day.mc.alpha = 0;
TweenLite.delayedCall(elem * 0.75, TweenLite.to, [day.mc, 0.75, {alpha:1, y:day.mc.y}]);
day.mc.y = 550;
}
}

default xml namespace = new Namespace("");

}




stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
sw = stage.stageWidth;
sh = stage.stageHeight;

zipCode = loaderInfo.parameters.zipCode;
if (!zipCode) {
zipCode = DEFAULT_ZIPCODE;
}
trace ("Retrieving Weather Forecast RSS for Zipcode: "+zipCode);
loadRSS("http://weather.yahooapis.com/forecastrss?p="+zipCode);


Thanks!





Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]