The following AS3 code works great to pull in some xml data and do a little slideshow like transition to display news. I’ve been banging my head against the wall trying to figure out the logic to get it to go back to the xml file and reload it after it displays the last node//class for transitions
import caurina.transitions.Tweener;
//all global variables
//the array which contains all newsSetup objects
var _newsHolderArr:Array = new Array();
//Timer which adds the next news
var _timer:Timer;
//array which contains the objects which are currently being moved in and out
var _tweenArr:Array = new Array();
//blur for the motion blur
var _blur:BlurFilter = new BlurFilter(0, 40, 3);
//variables which are set later by the loaded XML file
var _transTypeIn:String = “easeOutQuart”;
var _transTypeOut:String = “easeOutQuart”;
var _transSpeed:int = 1;
var _randomRotation:int;
//number of the active news in the _newsHolderArr array
var _currentNews:int;
//calls the load XML function, which requires a String with the path to the XML file
//change the path if you don’t have the XML in the same folder as the .swf file
loadXML(“news_xml.xml”);
//load XML file
function loadXML(path:String):void {
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onXMLLoaded);
loader.load(new URLRequest(path));
}
//load of XML file is done!
function onXMLLoaded(event:Event):void {
//a scroll rect, makes anything outsite the actual stage invisible
this.scrollRect = new Rectangle(0, 0, 590, 300);
//ignore comment and white spaces
var newsData:XML = new XML(event.target.data);
newsData.ignoreWhitespace = true;
newsData.ignoreComments = true;
//the news index, starts at 1
var index:int = 1;
//a loop for each news in the XML news section
for each(var news:XML in newsData.news.news) {
//creats an instance of the news setup which can be found in this .fla file
//all text in the each NewsSetup is filled out
var newsHolder:NewsSetup = new NewsSetup();
newsHolder.title.autoSize = TextFieldAutoSize.LEFT;
newsHolder.title.text = news.attribute("title");
newsHolder.index.autoSize = TextFieldAutoSize.LEFT;
newsHolder.index.text = String(index) + " of " + newsData.news.news.length();
newsHolder.index.x = newsHolder.title.width + 10;
newsHolder.text.autoSize = TextFieldAutoSize.LEFT;
newsHolder.text.condenseWhite = true;
newsHolder.text.htmlText = news;
//the newsHolder is hidden to so we won't se it before we are supposed to
//here we also possition it
newsHolder.visible = false;
newsHolder.x = (app.width * .5 - newsHolder.width * .5) + 20;
addChild(newsHolder)
//finaly the newHolder is added to our holder array, so we can find it later on
_newsHolderArr.push({object:newsHolder, link:news.attribute("link")});
index++;
}
//the amount of motion blur is set here, and so are all other parameters from the XML file
_blur.blurY = int(newsData.adjustment.attribute("motionBlur"));
_randomRotation = int(newsData.adjustment.attribute("randomRotation"));
_transTypeIn = newsData.adjustment.attribute("transitionIn");
_transTypeOut = newsData.adjustment.attribute("transitionOut");
_transSpeed = Number(newsData.adjustment.attribute("transitionSpeed"));
//app.bannerTitle.autoSize = TextFieldAutoSize.LEFT;
//app.bannerTitle.htmlText = newsData.adjustment.attribute("bannerName");
//the first object is pushed into the _tweenArr and blured
_tweenArr.push(_newsHolderArr[0].object);
_newsHolderArr[0].object.filters = [_blur];
//the first news is initiated
showNextNews();
//timer speed is set and started
_timer = new Timer(Number(newsData.adjustment.attribute("speed"))*1000);
_timer.addEventListener(TimerEvent.TIMER, onTimerCount);
_timer.start();
}
//when the timer counts next news is added
function onTimerCount(event:TimerEvent):void {
showNextNews();
}
function showNextNews():void {
if(_tweenArr.length == 1) {
_tweenArr.unshift(_newsHolderArr[_currentNews].object);
_tweenArr[0].alpha = 0;
_tweenArr[0].visible = true;
Tweener.addTween(_tweenArr[0], {y:app.height * .5 - _tweenArr[0].height * .5, alpha:1, _blur_blurY:0, rotation:-_randomRotation + Math.random() * (_randomRotation * 2), time:_transSpeed, transition:_transTypeIn});
}
else {
_currentNews++;
if(_currentNews == _newsHolderArr.length) {
_currentNews = 0;
}
trace("we are in the else statment");
_tweenArr.unshift(_newsHolderArr[_currentNews].object);
_tweenArr.pop();
_tweenArr[0].alpha = 0;
_tweenArr[0].visible = true;
_tweenArr[0].y = 0;
_tweenArr[0].filters = [_blur];
Tweener.addTween(_tweenArr[1], {y:app.height, alpha:0, _blur_blurY:10, time:_transSpeed, transition:_transTypeOut});
Tweener.addTween(_tweenArr[0], {y:app.height * .5 - _tweenArr[0].height * .5, _blur_blurY:0, rotation:-_randomRotation + Math.random() * (_randomRotation * 2), alpha:1, time:_transSpeed, transition:_transTypeIn});
}
}