Tutorial: Realizziamo una chat per il nostro sito (Lesson 2)

Spread the love

Cominciamo la nostra seconda lezione sulla creazione di una piccola chat da inserire in un box del nostro sito web, spiegando a cosa servono le righe di comando che abbiamo utilizzato nell’Action Script del pulsante Invia.

 

L’azione:

 

loadVariablesNum (“resp.asp”, 0, “POST”);

 

da l’avvio al inserimento del nuovo messaggio, effettua il refresh dei messaggi e pulisce il nostro campo di testo per inserire i nuovi messaggi.

Lo script di resp.asp, va comunque inserito in codice. Di seguito vedremo l’inserimento effettuato con i commenti per capire meglio passo passo cosa stiamo facendo:

<%
Dim strLinea, FileObject, Instream, intVisite, intTipo, OutStream, i, k, arrMsg(100), fine, allMsg
‘questa stringa permette l’utilizzo semplice in visualizzazione di : “username _ messaggio”
stringa = Trim(Request(“stringa”))
strFile = Server.MapPath(“msg.txt”)
definiamo l’oggetto creato in questo caso i messaggi che andranno in un file di testo
Set FileObject = Server.CreateObject(“Scripting.FileSystemObject”)
‘faccio la lettura del file
intTipo = 1 ‘ lettura
Set InStream = FileObject.OpenTextFile(strFile,IntTipo,true)
‘inseriamo il valore di data e ora al messaggio per fare in modo che in ordine cronologico siano aggiunti nella lista
i = 0
arrMsg(i) = FormatDateTime(Now(),3)&” – “&stringa
‘leggiamo il file di testo ed inseriamo i messaggi
Do While not InStream.AtEndOfStream
StrLinea = InStream.ReadLine()
i=i+1
arrMsg(i) = StrLinea
Loop
Set OutStream = FileObject.CreateTextFile(strFile, true)
‘determiniamo il numero massimo di messaggi
if i>15 then
fine=15
else
fine=i
end if
k=0
‘visualizziamo in Flash i messaggi inserendo il (br) a capo dove necessario
Do While k<=fine
OutStream.WriteLine(arrMsg(k))
allMsg=allMsg&arrMsg(k)&”<br />”
k=k+1
Loop
OutStream.Close
Set OutStream = Nothing
InStream.Close
Set InStream = Nothing
Set FileObject = Nothing
‘inviamo definitivamente i messaggi alla chat
Response.Write(“corpo=”&allMsg)
%>

Ecco, così abbiamo inserito il codice alla nostra chat e potremmo utilizzarla in modalità standard per dare la possibilità agli utenti del vostro sito di scambiare due chiacchiere. Ricordiamo che la versione utilizzata per la realizzazione di questo tutorial è l’ActionScript 4 incluso nella suite Adobe Macromedia Flash CS4 Professional.

Nella prossima ed ultima lezione, vedremo come dare un “tocco di colore” alla nostra chat.

731 commenti su “Tutorial: Realizziamo una chat per il nostro sito (Lesson 2)”

  1. Hi, possibly i’m being a little off topic here, but I was browsing your site and it looks stimulating. I’m writing a blog and trying to make it look neat, but everytime I touch it I mess something up. Did you design the blog yourself?

    Rispondi
  2. I discovered your weblog site on google and verify just a few of your early posts. Proceed to maintain up the very good operate. I simply further up your RSS feed to my MSN News Reader.

    Rispondi
  3. The post is absolutely great! Lots of great info and inspiration, both of which we all need! Also like to admire the time and effort you put into your blog and detailed information you offer! I will bookmark your website!

    Rispondi
  4. I don’t know if it’s just me or if everybody else experiencing issues with your site. It appears as though some of the written text on your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This could be a problem with my web browser because I’ve had this happen before. Appreciate it

    Rispondi
  5. That is really fascinating, You’re an excessively skilled blogger. I’ve joined your rss feed and look forward to in the hunt for extra of your magnificent post. Additionally, I’ve shared your website in my social networks!

    Rispondi

Lascia un commento