import flash.external.ExternalInterface;
#include "lsjavascriptbridge.as"
#include "format.as"
_root.Message.text = "Lightstreamer Live Data";
var groupString = "item1 item2 item3 item4 item5 item6 item7 item8";
var schemaString = "stock_name pct_change pct_change last_price time";
var bridge = new JavaScriptBridge("flashObject");
var myTable = new FlashTable(groupString,schemaString,"MERGE");
myTable.setSnapshotRequired(true);
myTable.setRequestedMaxFrequency(0.35);
myTable.onItemUpdate = function (item, itemUpdate) {
if (itemUpdate.isValueChanged(1)) {
var newVal = itemUpdate.getNewValue(1);
newVal = cutName(newVal,item);
updateName(item,newVal);
}
if (itemUpdate.isValueChanged(2)) {
var newVal = itemUpdate.getNewValue(2);
newVal = formactDirection(newVal);
updateDirection(item,newVal);
}
if (itemUpdate.isValueChanged(3)) {
var newVal = itemUpdate.getNewValue(3);
newVal = formatDecimal(newVal, 2, true);
if(newVal > 0){
newVal = "+" + newVal;
}
updatePerc(item,newVal);
}
if (itemUpdate.isValueChanged(4)) {
var newVal = itemUpdate.getNewValue(4);
newVal = formatDecimal(newVal, 2, true);
updateLastPrice(item, newVal);
}
if (itemUpdate.isValueChanged(5)) {
var newVal = itemUpdate.getNewValue(5);
newVal = formatTime(newVal);
updateLastTrade(item, newVal);
}
}
myTable.onStart = function() {
for (var item = 1; item <= 8; item++) {
updateName(item,"");
updatePerc(item,"");
updateLastPrice(item, "");
updateLastTrade(item, "");
}
}
bridge.onStatusChange = function(newStatus) {
Message.text = "Status: " + newStatus;
}
bridge.addTable(myTable,"FlashTable1");
///////////////////////////////////////////////////////////
onEnterFrame = function () {
dat = new Date();
gg = dat.getDate();
if(gg < 10){gg = "0" + gg}
mm = (dat.getMonth() + 1);
if(mm == 1){mm = "Gen"}
else if(mm == 2){mm = "Feb"}
else if(mm == 3){mm = "Mar"}
else if(mm == 4){mm = "Apr"}
else if(mm == 5){mm = "May"}
else if(mm == 6){mm = "Jun"}
else if(mm == 7){mm = "Jul"}
else if(mm == 8){mm = "Aug"}
else if(mm == 9){mm = "Sep"}
else if(mm == 10){mm = "Oct"}
else if(mm == 11){mm = "Nov"}
else if(mm == 12){mm = "Dec"}
aaaa = dat.getFullYear();
_root.CurrentTime = gg + " " + mm + " " + aaaa;
};
function updateInstrument(row) {
this["instrument"+row].gotoAndPlay(1);
}
function updateName(row, newVal) {
this["instrument"+row].nomeinstrument = newVal;
this["instrument"+row].gotoAndPlay(1);
}
function updateDirection(row, direction) {
if (direction == "up" and this["row"+row].direction.vardirection == "down") {
this["row"+row].direction.gotoAndPlay("goUp");
} else if (direction == "down" and this["row"+row].direction.vardirection == "up") {
this["row"+row].direction.gotoAndPlay("goDown");
}
updateInstrument(row);
}
function updatePerc(row, newVal) {
this["perc"+row] = newVal+"%";
this["row"+row].change.gotoAndPlay(1);
updateInstrument(row);
}
function updateLastPrice(row, newVal) {
this["lastPrice"+row] = newVal;
this["row"+row].price.gotoAndPlay(1);
updateInstrument(row);
}
function updateLastTrade(row, newVal) {
this["lastTrade"+row] = newVal;
this["row"+row].trade.gotoAndPlay(1);
updateInstrument(row);
}
//notify the page that we are ready
bridge.bind();
Bookmarks