Remove dots from button label - actionscript-3

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

Related

Read a string in AS3

I have a question regarding to my project which is how to read a string in AS3.
Actually, I have an text file named test.txt. For instance:
It consists of:
Sun,Mon,Tue,Wed,Thu,Fri,Sat
and then I want to put all of them into an array and then a string to show them in the dynamic text Box called text_txt:
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void
{
var days:Array = e.target.data.split(/\n/);
var str:String;
stage.addEventListener(MouseEvent.CLICK, arrayToString);
function arrayToString(e:MouseEvent):void
{
for (var i=0; i<days.length; i++)
{
str = days.join("");
text_txt.text = str + "\n" + ";"; //it does not work here
}
}
}
myTextLoader.load(new URLRequest("test.txt"));
BUT IT DOES NOT show them in different line and then put a ";" at the end of each line !
I can make it to show them in different line, but I need to put them in different line in txt file and also I still do not get the ";" at the end of each line unless put it in the next file also at the end of each line.
And then I want to read the string and show an object from my library based on each word or line. for example:
//I do not know how to write it or do we have a function to read a string and devide it to the words after each space or line
if (str.string="sun"){
show(obj01);
}
if (str.string="mon"){
show(obj02);
}
I hope I can get the answer for this question.
Please inform me if you can not get the concept of the last part. I will try to explain it more until you can help me.
Thanks in advance
you must enable multiline ability for your TextField (if did not)
adobe As3 DOC :
join() Converts the elements in an array to strings, inserts the
specified separator between the elements, concatenates them, and
returns the resulting string. A nested array is always separated by a
comma (,), not by the separator passed to the join() method.
so str = days.join(""); converts the Array to a single string, and as your demand ( parameter passed to join is empty "") there is no any thing between fetched lines. and text_txt.text = str + "\n" + ";"; only put a new line at the end of the text once.
var myTextLoader:URLLoader = new URLLoader();
var days:Array;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void
{
days = e.target.data.split(/\n/);
var str:String;
stage.addEventListener(MouseEvent.CLICK, arrayToString);
}
myTextLoader.load(new URLRequest("test.txt"));
function arrayToString(e:MouseEvent):void
{
text_txt.multiline = true;
text_txt.wordWrap = true;
text_txt.autoSize = TextFieldAutoSize.LEFT;
text_txt.text = days.join("\n");
}
also i moved arrayToString out of onLoaded
for second Question: to checking existance of a word, its better using indexOf("word") instead comparing it with "==" operator, because of invisible characters like "\r" or "\n".
if (str.indexOf("sun") >= 0){
show(obj01);
}
if (str.indexOf("mon") >= 0){
show(obj02);
}
Answer to the first part:
for (var i=0; i<days.length; i++)
{
str = days[i];
text_txt.text += str + ";" + "\n";
}
I hope I understand you correctly..
I wrote from memory, sorry for typos if there are...
For the second part, add a switch-case
switch(str) {
case "sun":
Show(??);
break;
.
.
.
}

Div tag acting as buttons, and also Dynamic buttons like delete, report spam, etc

This is a practice test case where i have to login to gmail and click on all the checkbox in the dynamic web table and delete the mails. So i made the following code.
The problem is when i am checking the delete button is available or not. It is returning true but when i am trying to perform the delete operation it is displaying ElementNotVisibleException. FYI i am able to select all the checkboxes. Only issue is clicking on the buttons made from tag.
//deleting mail by clicking on all checkbox
int count = 1;
List<WebElement> lst = driver.findElements(By.xpath(cbox));
System.out.println("Total number of checkboxes are \t: " + lst.size());
for(int i=0;i<lst.size();i++){
WebElement wwe = lst.get(i);
wwe.click();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
System.out.println("Checked on checkbox number \t: " + count);
count++;
}
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
try{
boolean flag = driver.findElement(By.xpath(delete)).isEnabled();
if(flag){
System.out.println("\nDelete button is enabled");
}else{
System.out.println("\nDelete button is not enabled");
}
driver.findElement(By.xpath(delete)).click();
}catch(Throwable t){
System.out.println("\nUnable to locate delete button");
System.out.println("The exception occuring is \t: " + t);
}
I've tried the following and it worked fine.You just have to add enough wait
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 60 /*timeOut in Seconds*/);
driver.get("https://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("xxx");
driver.findElement(By.id("next")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd"))).sendKeys("xxx");
driver.findElement(By.id("signIn")).click();
String cbox = "//table[#class='F cf zt']//div[#class='T-Jo-auh']";
String delete = "//div[#class='asa']/div[#class='ar9 T-I-J3 J-J5-Ji']";
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(cbox)));
int count = 1;
List<WebElement> lst = driver.findElements(By.xpath(cbox));
System.out.println("Total number of checkboxes are \t: " + lst.size());
for (int i = 0; i < lst.size(); i++) {
WebElement wwe = lst.get(i);
wwe.click();
System.out.println("Checked on checkbox number \t: " + count);
count++;
}
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(delete))).click();
try {
WebElement deleteButton = driver.findElement(By.xpath(delete));
boolean flag = deleteButton.isEnabled();
if (flag) {
System.out.println("\nDelete button is enabled");
} else {
System.out.println("\nDelete button is not enabled");
}
deleteButton.click();
} catch (Throwable t) {
System.out.println("\nUnable to locate delete button");
System.out.println("The exception occuring is \t: " + t);
}
You probably chose not so automation friendly web app like Gmail to start with. I believe they have deliberately developed Gmail client side in such a way that its harder for a Robot to perform actions.
As for your question, I think the delete button appears a little after check boxes are clicked. So I believe you will have to explicitly wait for the button to appear. It's also possible that your xpath is not correct.
You could try this,
WebDriverWait wait = new WebDriverWait(driver, 60 /*timeOut in Seconds*/);
wait.until(ExpectedConditions.
visibilityOfElementLocated(By.css("div[data-tooltip='Delete']"))).click();

show last 100 lines textArea AS3 Flash

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>";
}
}

Inline image in dynamic text

I am working on a chat application using AS3. I am new to AS and flash. I want to add smilies in the chat. So when a user types ":p" i want to replace it with an image in his text message. I simply used image tag to do this. However, image does not show inline. It shows in the next line.
Is there an easy way to do this?
Example:
Currently -> this is my chat
image here
Desired results -> this is my "image here" chat
Sample code
var abc:String="This is my :p chat";
abc.replace(":p", "<img src='url of the image' height='10' width='10'>"
Have you tried:
img{
display: inline;
}
I am assuming you already know about loading stylesheets via AS3?
UPDATE:
Something like this should work:
var style:StyleSheet = new StyleSheet();
style.parseCSS("img{ display: inline; }");
// IMPORTANT: tf is whatever TextField instance you are using
tf.styleSheet = style;
var str:String = "<p>This is my :p chat</p>";
tf.htmlText = str.replace(":p", "<img src='url of the image' height='10' width='10'>");
Try this one:
var _message = "Good to see u :) how are you";
chatTxt.htmlText = doReplace(_message);
function doReplace(msg):String
{
var _str = refDocument._baseURL + "/tool/assets/emotion/";
var _search:Array = [":)",";)"];
var _replace:Array = ["<img width='20' height='20' src='smile.png'>","<img width='20' height='20' src='wink.png'>"];
for (var i:int=0; i<_search.length; i++)
{
msg = msg.split(_search[i]).join(_replace[i]);
}
return msg;
}
make sure chatTxt is TLF text

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;
}