show last 100 lines textArea AS3 Flash - actionscript-3

I have a very busy chat app and the textArea is set to clear itself after certain amount of text, but what I want is to show the last 100 lines of text in the textArea and remove the rest.
Using Flash CC
The text comes from a Red5 Server like this:
function onReceiveMsg(UserName:String, Msg:String):void{
if (myTextArea.length > 21400){
myTextArea.htmlText = "";
}
//add text to textArea
myTextArea.htmlText += "<font color='#FF0000'>"+UserName+": "+Msg"</font>";
}
So, any idea to maintain the last 100 lines of chat? Thanks! :-)

I would simply store all the messages you receive in an array:
var messages:Array = [];
function onReceiveMsg(userName:String, msg:String):void
{
messages.push({ userName: userName, msg: msg });
displayMessages(); // See below.
}
And pull the last 0-100 items from that for display:
function displayMessages():void
{
myTextArea.htmlText = "";
var recent:Array = messages.slice(-100);
for each(var i:Object in recent)
{
myTextArea.htmlText += "<font color='#FF0000'>" + i.userName + ": " + i.msg + "</font>";
}
}

Related

Create one time popup with materialize css

Is there any way to evade jquery and make notification be shown only one time per browser ?
For example, goes to website, notification pops up and that is it, next time when user comes to site from same browser notification wont be showen to him.
I would mainly try to evade adding jquery just for that, so if anyone knows a way to do this with materializecss or some plain html i would be thankful.
How do you trigger the notification?
You could do a basic localStorage check for example to "detect" if the notification has been displayed or not:
function foo() {
const hasSeenNotification = window.localStorage.getItem('shown');
if (!hasSeenNotification) {
window.localStorage.setItem('shown', true);
// show notification here
// ...
}
}
You need to add cookies.
And then check is it is exists:
if (GetCookieShowMessageDocument('ShowPoPUP'))
{
...
}
Here is a sample:
function GetCookieShowMessageDocument(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
function SetCookieShowMessageDocument(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + escape(value) + expires + "; path=/";
}

Remove dots from button label

I have a button and i give the label value dynamically. And button width=100;
If i give btn.label = "Good Morning Have a nice day"; it shows
But i need to remove the dots. and i have a different function to marquee.
var t:Timer = new Timer(500);
btn1.label += " ";
t.addEventListener(TimerEvent.TIMER,function(ev:TimerEvent): void
{
btn1.label = btn1.label.substr(1) + btn1.label.charAt(0);
}
);
t.start();
i have another button as btn2.
Click event on btn2 calls the above code and the label text start to move towards left. But i need to remove the dot.
any help???
I got my answer.
private var str:String;
str = "Text To Display" + " ";
str = str.substr(1) + str.charAt(0);
btn1.label = updateLabel(str);
private function updateLabel(str:String):String
{
return new String(str).substr(0,10);
}
it works for me. if any one have any other solutions then please share your views. Thank you

Check user entered text aginst xml

i am trying to check user entered text in a dynamic text box against a XML file, so if the user enters the it traces jackpot and the array no its stored at is stored, this is what i have so far but cant get it to work, anyone have any ideas ? all that is on the stage is a dynamic text box called userID and a button called idBtn to check, thanks
EDIT : i changed it around, what i cant get to work is the comparison between the user entered text and what is in the xml, the if loop always runs through even when true,
import flash.display.MovieClip;
import flash.text.TextField;
var xmlloader:URLLoader = new URLLoader();
var xmlreq:URLRequest = new URLRequest("users.xml");
xmlloader.load(xmlreq);
xmlloader.addEventListener(Event.COMPLETE, convertdata);
function convertdata(event:Event)
{
var xmlinfo:XML = new XML(event.target.data);
var postedlist:XMLList = xmlinfo.user;
var totallist:Number = postedlist.length();
trace(totallist);
for(var i:int=0 ; i < totallist ; i++)
{
trace("id_no[i] before lowered " + xmlinfo.user.id_no[i])
xmlinfo.user.id_no[i] = xmlinfo.user.id_no[i].toLowerCase();
trace("id_no[i] after lowered " + xmlinfo.user.id_no[i])
}
function checkUser(event:MouseEvent):void
{
for(var i:int=0 ; i < totallist ; i++)
{
var enteredID:String = userId.text
enteredID = enteredID.toLowerCase();
trace("before if "+ xmlinfo.user.id_no[i] +" and " + enteredID)
if (xmlinfo.user.id_no[i]==enteredID)
{
trace("jackpot");
}
else
{
trace("nope");
}
}
}
idBtn.addEventListener(MouseEvent.MOUSE_UP, checkUser);
}
my xml is just
<root>
<user>
<id_no>a</id_no>
<username>Jane Doe</username>
<banned>-1</banned>
<equip_out>-1</equip_out>
</user>
</root>
my output is :
1
id_no[i] before lowered a
id_no[i] after lowered a
with noting entered in text-box
before if a and
nope
with q entered in text-box
before if a and q
nope
with a entered in text box (this is what i want to return the jackpot trace at)
before if a and a
nope
I think you're comparing an XML with a String.
Try this:
if (xmlinfo.user.id_no[i].toString()==enteredID)
{
trace("jackpot");
}
else
{
trace("nope");
}

Can TeeChart draw value label at cursor point?

I'm looking for HTML5 chart that can show value at cursor point like this
http://www.tradeviewforex.com/forex-blog/tip-14-how-to-use-the-crosshair-on-metatrader-4
I found StockChartX can do this
http://developer.modulusfe.com/stockchartx_html5/
(click Draw -> Annotation)
but I can effort this price :P
Thanks for answer!
Ps. Sorry for my bad english.
Something similar can be done with the Annotation tool in TeeChart HTML5. See the example here
Also, you can format a tool tip, if that is the need.
tip = new Tee.ToolTip(Chart1);
Chart1.tools.add(tip);
tip.format.font.style = "11px Verdana";
tip.render = "canvas";
tip.onshow = function (tool, series, index) {
scaling = 2;
poindex = index;
}
tip.onhide = function () {
scaling = 0;
poindex = -1;
}
tip.ongettext = function (tool, text) {
var txt = tool.currentSeries.title + ":\n" + "Value: " + text + tool.currentSeries.units + "\n" + jsonDataArray[0].evDataTime[tool.currentIndex] + " (ms)";
model.MouseOverY(text + tool.currentSeries.units);
model.MouseOverX(jsonDataArray[0].evDataTime[tool.currentIndex] + " (ms)");
model.SelectedSeries(tool.currentSeries.title);
return txt;
}

How to serialize HTML DOM to XML in IE 8?

Is there a way to do it(serialization of HTML DOM into XML) in IE 8 or any other older version of IE.
In firefox :
var xmlString = new XMLSerializer().serializeToString( doc );
does it.I haven't tried it, though.
XMLSerializer causes error in IE 8, that it is not defined.
var objSerializeDOM = {
//Variable to hold generated XML.
msg : "",
serializeDOM : function() {
dv = document.createElement('div'); // create dynamically div tag
dv.setAttribute('id', "lyr1"); // give id to it
dv.className = "top"; // set the style classname
// set the inner styling of the div tag
dv.style.position = "absolute";
// set the html content inside the div tag
dv.innerHTML = "<input type='button' value='Serialize' onClick='objSerializeDOM.createXML()'/>"
"<br>";
// finally add the div id to ur form
document.body.insertBefore(dv, document.body.firstChild);
},
/**
* XML creation takes place here.
*/
createXML : function() {
objSerializeDOM.msg += "";
objSerializeDOM.msg += "<?xml version='1.0' encoding='UTF-8'?>\n\n";
// Get all the forms in a document.
var forms = document.forms;
for ( var i = 0; i < forms.length; i++) {
// Get all the elements on per form basis.
elements = document.forms[i].elements;
objSerializeDOM.msg += "<FORM name=\"" + forms[i].name + "\" method=\""
+ forms[i].method + "\" action=\"" + forms[i].action + "\">\n\n";
for ( var j = 0; j < elements.length; j++) {
objSerializeDOM.msg += " <" + elements[j].tagName + " type=\""
+ elements[j].type + "\"" + " name=\""
+ elements[j].name + "\"" + " Value =\""
+ elements[j].value + "\" />\n";
}
alert(document.forms[i].elements[1].event);
}
objSerializeDOM.msg += "\n\n</FORM>\n\n";
alert(objSerializeDOM.msg);
objSerializeDOM.writeToFile(objSerializeDOM.msg);
},
/**
* Writes the msg to file at pre-specified location.
* #param msg
* the XML file created.
*/
writeToFile : function(msg) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("c:\\myXML.xml", true);
fh.WriteLine(msg);
fh.Close();
}
};
objSerializeDOM.serializeDOM();
I wrote this JS, I run this javascript using GreaseMonkey4IE. This simply puts a button on every page of the domain you specify in GM4IE. On click of that button it will parse the HTML document and create an XML file. It will also display the same as an alert first and will save the XML in your local drive on path specified.
There a still many improvements I am planning to do, but yes it works and may be give you guys an idea.The program is self-explanatory, I hope.
please have a look here How to get Events associated with DOM elements?Thanks