Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,545 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,181 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



chat update script

 
Reply to this topicStart new topic

chat update script

JBrace1990
post 17 Jul, 2008 - 01:43 PM
Post #1


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 427



Thanked 19 times

Dream Kudos: 350
My Contributions


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...

CODE
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 tongue.gif 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:
CODE
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.... IPB 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 Jul, 2008 - 01:50 PM
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 17 Jul, 2008 - 10:56 PM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,266



Thanked 38 times

Dream Kudos: 775
My Contributions


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)

CODE
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 Jul, 2008 - 11:03 PM
User is online!Profile CardPM

Go to the top of the page

JBrace1990
post 18 Jul, 2008 - 12:32 PM
Post #3


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 427



Thanked 19 times

Dream Kudos: 350
My Contributions


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 wink2.gif (even though the images don't lol)

about the update: I tried this, but it didn't display anything...
CODE
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 Jul, 2008 - 01:04 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/7/08 10:02PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month