2 Replies - 2136 Views - Last Post: 18 July 2008 - 12:32 PM

#1 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

chat update script

Posted 17 July 2008 - 01:43 PM

i've been working on my own chat... yadda yadda... I have this current code... it takes the info from the XML, and adds it to the text area that displays the chat logs... chatLog is a public static var...


So, first matter:
as of right now, the chat only updates if there's something new added... I want it to do that, but instead of completely changing everything (because images reload), I want it to just add it to the data... I know it would be added using +=, but i need some help figuring out how exactly to do it...

private function updateDone(event:ResultEvent):void
{
				var i:int;
				var tempString:String = "";
				var tempString2:String;
				var tempString3:String;
	for(i=0; i<event.result.poster.length; i++)
	{
		if(event.result.bold[i] == 'yes'){
			tempString2 = "<b>" + str_replace(":P","<img src=\"tongue.gif\">",event.result.content[i]) + "</b>";
		}else{
			tempString2 = str_replace(":P","<img src=\"tongue.gif\">",event.result.content[i]);
		}
		if(event.result.italics[i] == 'yes'){
			tempString3 = "<i>" + tempString2 + "</i>";
		}else{
			tempString3 = tempString2;
		}
		tempString += "<font color=\"" + event.result.fontColor[i] + "\">" + event.result.poster[i] + ": " + tempString3 + "</font>" + "\n";
	}	
			if(chatLog == tempString)
			{
				
			}
			else
			{
				chatLog = tempString;
		   		chatDisplay.htmlText = tempString;
				chatDisplay.verticalScrollPosition = chatDisplay.maxVerticalScrollPosition;
			}
}


Second matter:
as you've probaly seen, I use a custom function to replace the tempString with basically image parsing... so i turn :P into an image... I want to be able to use arrays for it, but i'm not sure how... i know in PHP you can replace the array keys with the array values, but i'm not sure about actionscript...

so i'd make an array that contains things like ":P" i want to replace as a key, and things like "<img src=\"tongue.gif\">" as a value...

anyway, here's the current function:
private function str_replace(replace_with:String, replace:String, original:String):String
{
var array:Array = original.split(replace_with);
return array.join(replace);
}			



and a third thing:
when I replace the text with an image, i end up with this.... Posted Image i'm not sure if it's a problem with my code, or just really bad placing =/

This post has been edited by JBrace1990: 17 July 2008 - 01:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: chat update script

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1651
  • View blog
  • Posts: 8,523
  • Joined: 07-September 06

Re: chat update script

Posted 17 July 2008 - 10:56 PM

Okay, here is a variation of the previous code that I posted for replace strings with an array of items (got rid of the second loop)

var from:Array = new Array(":)", ":(");
var to:Array = new Array("SMILE", "FROWN");
var str:String = new String("Oh Happy Day :) or it is? :(");
var newStr:String = new String(replace(from, to, str));

function replace(from_array:Array, to_array:Array, str:String){
	var nstr:String = str;
	for(var i:Number=0; i<from_array.length; i++){
		var ostr:String = '';
		var str2:Array = nstr.split(from_array[i]);
		ostr = str2.join(to_array[i]);
		nstr = ostr;
	}
	return ostr;
}


Outputs: Oh Happy Day SMILE or it is? FROWN

Hope that part helps.

Now, looking at your other issue, I would suggest not trying to sort out which messages are new o old on the client side. Have PHP send back a single extra variable that is called something like "previousTime" which is a timestamp taken right before it echoes the xml to the Flex app. Then have Flex send it back and have a variable that you use when querying so you can say (assuming that you have been taking a timestamp of when the messages are imputted into the database) something like so: SELECT * FROM [table_name] WHERE [time_posted]>FLEX_TIMESTAMP That way you get all the messages posted since the last update. Then just output them with the += as usual.

Hope that helps there.

On to the third part... well I am not actually sure what is causing the offset... It is probably the SWF's interpretation of image tags in HTML that says it has to be on a different line than any text around it...

Well, hope I was able to help.

<EDIT>
Upon further investigation (posting some on the chat to see howit works out). It looks like the images have been told to float left, that is causing some interesting problems when posting additional text... You may want to check the html that the Flash chat thinks it is getting (what it says it has) and that will probably give us an answer as to why it is acting strange.
</EDIT>

This post has been edited by BetaWar: 17 July 2008 - 11:03 PM

Was This Post Helpful? 1
  • +
  • -

#3 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: chat update script

Posted 18 July 2008 - 12:32 PM

I learned Flex does not like images in textareas, and they're not fully supported... which is REALLY stupid T_T

anyway, thanks Beta... i used part of those, actually... the arrays work like a charm ;) (even though the images don't lol)

about the update: I tried this, but it didn't display anything...
private function updateDone(event:ResultEvent):void
{
				var i:int;
				var tempString:String = "";
				var tempString2:String;
				var tempString3:String;
	for(i=0; i<event.result.poster.length; i++)
	{
		if(event.result.bold[i] == 'yes'){
			tempString2 = "<b>" + replace(from,to,event.result.content[i]) + "</b>";
		}else{
			tempString2 = replace(from,to,event.result.content[i]);
		}
		if(event.result.italics[i] == 'yes'){
			tempString3 = "<i>" + tempString2 + "</i>";
		}else{
			tempString3 = tempString2;
		}
		tempString += "<font color=\"" + event.result.fontColor[i] + "\">" + event.result.poster[i] + ": " + tempString3 + "</font>" + "\n";
	}	
			if(chatLog == tempString)
			{
				
			}
			else
			{
//this is where the problems start.. before replacing, it works fine
//what I want to do is use the public static var chatLog to hold the
//current chat data... I then replace the chat data with nothing, and add the difference
//however, it's not working as intended, and just gives me a blank textarea
//where the data usually is
		   		var tempString4:String = str_replace("", chatLog, tempString);
		   		chatDisplay.htmlText += tempString4;
		   		chatLog += tempString4;
		   		chatDisplay.validateNow();
				chatDisplay.verticalScrollPosition = chatDisplay.maxVerticalScrollPosition;
			}
}


EDIT: has anyone used images before in a textfield and have some type of workaround?

This post has been edited by JBrace1990: 18 July 2008 - 01:04 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1