I put together a stock ticker for pixelacres.com (new site I’ve taken a liking to so i’ve been contributing what I can) & it works exactly the way I planned. Here’s the catch, I forgot all about cpu usage while I was making it :-/
As it is now it loads xml & creates a textfield for each childNode in the xml , then onEnterFrame “leapfrogs” (hence this title) all of theese textfields making for a rather boggy experience with 30+ childNodes on a 500mhz (don’t laugh) cpu.
I’ve tried switching it around so it has 4 tapes full of ticks (code will explain that) & leapfrogging theese 4 tapes instead of umpteen kajillion textfields, but so far it’s been a headscratching experience.
Rather than getting fustrated I figured I’d pop this up in here for suggestions/ideas & set the project on the back burner for the day.
Here’s what the XML looks like, // h=“newestRate.PreviousRate”
<exch>
<stk nme="supermans super stuff" h="123.432"/>
<stk nme="mikey mikarudens moon cheese" h="456.543"/>
Here’s the movie, (other than a textfield for the time, & 4 speed buttons this is it) (oh yeah there’s a 1 _alpha button over where the ticker shows up that pauses the stream onRollOver)
// Variables
spds = [spd1,spd2,spd3,spd4];
_global.tickSpeed = gTSpd();
_global.tapeArry = [];
_global.up = new TextFormat();with(up){color = '0x008800';font='Tahoma';size=12;}
_global.dwn = new TextFormat();with(dwn){color = '0xff0000';font='Tahoma';size=12;}
_global.unch = new TextFormat();with(unch){color = '0x00000';font='Tahoma';size=12;}
// cookies
function gTSpd(){
var sol = SharedObject.getLocal("tckSpd");
var R;
sol.data.spd!=undefined ? R=sol.data.spd : R=2;
for(var i in spds){spds*.textColor='0x000000';};spds[R-1].textColor='0xff0000';
return R;
}
function sTSpd(s){
var sol = SharedObject.getLocal("tckSpd");
sol.data.spd = s;
sol.flush();
}
// speed controll
MovieClip.prototype.sB = function(id){
this.useHandCursor = false;
this.id=id;
this.onRollOver = function(){this._alpha=20;}
this.onRollOut = function(){this._alpha=0;}
this.onPress = function(){tickSpeed = this.id+1;for(var i in spds){spds*.textColor='0x000000';};spds[this.id].textColor='0xff0000';sTSpd(this.id+1);}
}
/* XML */
rtes = new XML();
rtes.ignoreWhite = true;
rtes.load("ticker_rates.xml");
rtes.onLoad = function(success){
if(success){
createEmptyMovieClip('tape',0);
var newOld = [];
var tickInfo;
var tFmt;
for(var i=0; i<this.firstChild.childNodes.length; i++){
var a = this.firstChild.childNodes*.attributes;
i==0 ? null : tape.newTick(' | | ', unch, i+1000);
tickInfo = '';
tickInfo += (a.nme + ': ');
newOld = a.h.split('.');
tickInfo += newOld[0];
newOld[0]<newOld[1] ? (tickInfo+=(' -'+(newOld[1]-newOld[0])), tFmt=dwn) : (newOld[0]>newOld[1] ? (tickInfo+=(' +'+(newOld[0]-newOld[1])), tFmt=up) : (tickInfo+=' Unch.', tFmt=unch));
tape.newTick(tickInfo,tFmt,i);
}
}
tape.newTick(' | | ', unch, i+1000);
tape._x=tape._y=0;
rtes=0; delete rtes;
stream(false);
}
// textfields creation
MovieClip.prototype.newTick = function(tInfo,frmt,dpth){
this.createTextField(['tick'+dpth],dpth,0,0,1,1);
with(this['tick'+dpth]){
selectable = false;
text = tInfo;
autoSize = true;
setTextFormat(frmt);
}
this['tick'+dpth]._x = (this._width);
tapeArry.push(this['tick'+dpth]);
}
// ticker effect
MovieClip.prototype.stream = function(off){
if(!off){
this.onEnterFrame = function(){
for(t=0; t<tapeArry.length; t++){
s = tapeArry[t];
(s._x<(0 - s._width)) ? (s._x=(tape._width+s._x)) : s._x-=tickSpeed;
}
}
}else{delete this.onEnterFrame;
}
}
time = new Date();
hrs = time.getHours();
mins = time.getMinutes();
mins<10 ? (mins=('0'+mins)) : mins=mins;
hrs>11 ? (hrs-=12,suf='PM') : hrs==0 ? (hrs=12, suf='AM') : (hrs=hrs, suf='AM');
qTime = hrs+':'+mins+' '+suf;
go1.sB(0);go2.sB(1);go3.sB(2);go4.sB(3);
pause.useHandCursor = false;
pause.onRollOver = function(){stream(true);}
pause.onRollOut = function(){stream(false);}
I won’t cry if noone has any ideas, & I’m sure I’ll figure it out sooner or later, but hey, what good is being a member if you don’t participate 