Link to home
Start Free TrialLog in
Avatar of ocgstyles
ocgstyles

asked on

loadVars (flash/access/asp)

I am trying to make a web chatting application using flash, asp, and an access database.  i made the windows to send and receive messages in flash.  

Every 3 seconds it queries the database to see if there are any new messages for your user name.  To do this I created a loadvars object, and send out the sting of data, &username=xxxxx to the server.  the asp takes that, and checks if there are any new messages.  if it finds one, it stores the information in variables.  then deletes the record as to not be sent to you again.  i am using the asp command object with select and delete statements to do that.  when a message is found, it creates a string of text to send back to flash (response.write).

the response contains the sender and recipient of the message, the message, and a value to tell flash that something was found.  after the data is loaded (myLoadVar.load) it takes the received info, and if a new message was located, it formats it, and sends it your window..... pretty simple there.....

now here is my question.  for testing purposes i placed the IM window on the stage.  i hardcoded who the sender and recipients are.  i exported two swfs, the second having the sender and recipients names reversed.  now i can open these two movies in flash player and have a real time conversation (with myself :) ).......

but when i place these two swf's into web pages, they don't work right.  here is whats happening.....

i open two web pages, each opening one of the windows, so i can have a convo.  on the first page, i send a message.  the second one never receives it.  i send something from the second window to the first, it never receives it.  

if i check in the database now, i can see that there are two records created, but they are not being sent to the proper windows.  

if i refresh the browser windows, they still don't go to the IM windows.  if i close each IE window, and reopen each of the webpages, the messages start coming.  only now, they come in, and they don't stop!!  

i am thinking that the delete statement isn't being ran for some reason.  but i think it would have to be, because it comes before the response.write in the ASP file.  

i was thinking that maybe after the message is received and written maybe i should overwrite the variables with a blank string, or manually change the value that flash uses to verify if a new message is there.  but this is a function, the variables should be destroyed when the function completes.....

but is all seems to work perfectly in flash player, not on web pages...  

any ideas?  (i know seeing code may be useful, but i am not sure how much of it to send....)
Avatar of rascalpants
rascalpants
Flag of United States of America image

I think you are having a problem with the SWF being cached...

one way that I heard to do this was to put a ? with an integer after the file extension... but make the integer random each time the page is loaded

something like:

page.swf?random(100000000)


I have never used the random method, but I got the ? plus integer to work...  all of the other methods don't seem to work...


let me know if that helps...


rp
Avatar of ocgstyles
ocgstyles

ASKER

just tried it...  to make sure i understood you correctly, i typed the following into the browser, after emptying  temp internet files:

http://localhost/chat/file1.swf?4

and

http://localhost/chat/file2.swf?7

no change though.  i entered text into each and submitted, but the text didn't appear in the other.  when i refreshed with a different integer, the messages appeared, but wouldn't stop...

did i get that right?
I thought of something to add, but not sure it would help solve this...

this project uses the loadVars object to send the info to ASP to the database.  I tried one SWF on one computer, and the other on another computer, both computers being on the same network.  the URL used in loadVars.load is an absolute URL, not relative.  

so one would think that if i tested both as SWFs on one computer, when I used the above situation, it would work.  it doesn't.  

stumped....
hi ocgstles,

i did a similar app with ms sql not access and it works fine. the TIMING is the most important factor.

1) infinite calls of setInterval
check your script and make sure u clear the setInterval & and only setInterval if the variable is empty or null ...
clearInterval(msgtimer);
msgtimer = null;
..
..
if (msgtimer == null) {
  msgtimer = setInterval(getMsg,3000);
}
.. etc
the msgtimer is an integer once initialise and the number is ++ everytime it is assign using setInterval.
even it is calling the same function so it get calls forever and never stops ...

2) variable scope
true if u have a function and when it is done all variables used is released/destryed, that if u have use "var" to intialise all vars.

3) cache
the swf might be cached but that's ok, when u use loadVars & post etc ... it is a new submission everytime and the correct result will be returned

4) TIME!!!????
i) the browser ( local: swf + html) -> send request -> (LoadVars)
ii) the server -> execute select, delete query then send data back
iii) the traffic jam - internet ...

now if the above 3 items can be done within 3 sec  u are good, otherwise, ...


//therefore
instead of call the function every 3 sec, use an onLoad handler to check if the asp page returned with result, if not then don't send the request again, ...

OR ... test it again using a longer timer, say 5 sec on a live connection. and don't use absolute address.

i haven't seen ur code so i am only guessing it seems like a "time" problem. when u run ur app at localhost, u have all the script and swf, db etc on the same computer, it will take less than 3 sec to complete the cycle. but when u published the code the web ... now things are much different.

that explains why u can't get the msg when it is send during the session and it keeps on comming when u close the browser and open again.

in session - time too short for loading data & finish the asp script. reason - server is slow, connection is slow etc.

close & open - the movie initial ok, get's all the data from server. however there is something wrong with the setInterval or whatever calls the function

post the live link or fla so i can better understand what u are doing... :)

again i am only guessing ...

cheers
I will post the code that I am using.  I believe that the ASP files I created are correct because they work without fail when typed manually into the browser.  Any ideas are welcome.  Hre goes.....


Lets say I am at _root, I have a movieclip that checks whether or not to check for new messages(I guess the above could be coded simpler, using setInterval).  The code is as follows:

onClipEvent(load){
     sound_in = new Sound(this);
     sound_out = new Sound(this);
     sound_in.attachSound("in");
     sound_out.attachSound("out");
     i = 0;
     getData = 60;     //at 30fps, this checks every 2 seconds
     sending = false     //when you send messages, it disables checking until sending is complete
     
}

onClipEvent(enterFrame){
     if(!sending){
          if(i > getData){
               _parent.getMessages(_parent.username);
               i = 0;
          }else{
               i++;
          }
     }
}




On the first frame of _root, I have the following code:


username = "ocgstyles";
receiver = "chaimdavid";

//username = "chaimdavid";  <-- did this so i could quickly export the movie to test
//receiver = "ocgstyles";


//sets title of im window
imname.text = " - " + receiver;    


//URLs for ASP pages
URL_fetch = "http://localhost/chat/getmsg.asp"
URL_send = "http://localhost/chat/sndmsg.asp"



//loadVars
checker = new LoadVars();
checker.onLoad = showMessages;



//get messages
function getMessages(n){
     checker.load(URL_fetch + "?username=" + n);
}



//format names in IM window
function createSender(n){
     t = "<b><font color=\"#0000FF\">" + n + ": </font></b>"
     return t;
}
function createReceiver(n){
     t = "<b><font color=\"#FF0000\">" + n + ": </font></b>"
     return t;
}



function showMessages(){
     if(checker.newmsg == "True"){
          var ret_message = checker.message;
          var ret_receiver = checker.receiver;
          var ret_sender = checker.sender;
         
          if(ret_sender == username){
               var msg = createSender(ret_sender) + ret_message + newline;    
          }
          if(ret_receiver == username){
               var msg = createReceiver(ret_sender) + ret_message + newline;
          }
          computer.sound_in.start();
          receive.im += msg;
          receive.im.scroll = receive.im.maxscroll;
     }
}



function sendMessage(message){
     if(message != ""){
          //pause receiving data to send data
          computer.sending = true;
         
          //create URL
          URL = URL_send + "?sender=" + username + "&receiver=" + receiver + "&message=" + message
     
          //send data
          snd = new LoadVars();
          snd.load(URL)
     
          //update IM window
          computer.sound_out.start();
          receive.im += createSender(username) + message + newline;
          receive.im.scroll = receive.im.maxscroll;
         
          //clear sent text
          send.im.text = "";
         
          //allow receival of data
          computer.sending = false;
     }
}


stop();


I will post the code that I am using.  I believe that the ASP files I created are correct because they work without fail when typed manually into the browser.  Any ideas are welcome.  Hre goes.....


Lets say I am at _root, I have a movieclip that checks whether or not to check for new messages(I guess the above could be coded simpler, using setInterval).  The code is as follows:

onClipEvent(load){
     sound_in = new Sound(this);
     sound_out = new Sound(this);
     sound_in.attachSound("in");
     sound_out.attachSound("out");
     i = 0;
     getData = 60;     //at 30fps, this checks every 2 seconds
     sending = false     //when you send messages, it disables checking until sending is complete
     
}

onClipEvent(enterFrame){
     if(!sending){
          if(i > getData){
               _parent.getMessages(_parent.username);
               i = 0;
          }else{
               i++;
          }
     }
}




On the first frame of _root, I have the following code:


username = "ocgstyles";
receiver = "chaimdavid";

//username = "chaimdavid";  <-- did this so i could quickly export the movie to test
//receiver = "ocgstyles";


//sets title of im window
imname.text = " - " + receiver;    


//URLs for ASP pages
URL_fetch = "http://localhost/chat/getmsg.asp"
URL_send = "http://localhost/chat/sndmsg.asp"



//loadVars
checker = new LoadVars();
checker.onLoad = showMessages;



//get messages
function getMessages(n){
     checker.load(URL_fetch + "?username=" + n);
}



//format names in IM window
function createSender(n){
     t = "<b><font color=\"#0000FF\">" + n + ": </font></b>"
     return t;
}
function createReceiver(n){
     t = "<b><font color=\"#FF0000\">" + n + ": </font></b>"
     return t;
}



function showMessages(){
     if(checker.newmsg == "True"){
          var ret_message = checker.message;
          var ret_receiver = checker.receiver;
          var ret_sender = checker.sender;
         
          if(ret_sender == username){
               var msg = createSender(ret_sender) + ret_message + newline;    
          }
          if(ret_receiver == username){
               var msg = createReceiver(ret_sender) + ret_message + newline;
          }
          computer.sound_in.start();
          receive.im += msg;
          receive.im.scroll = receive.im.maxscroll;
     }
}



function sendMessage(message){
     if(message != ""){
          //pause receiving data to send data
          computer.sending = true;
         
          //create URL
          URL = URL_send + "?sender=" + username + "&receiver=" + receiver + "&message=" + message
     
          //send data
          snd = new LoadVars();
          snd.load(URL)
     
          //update IM window
          computer.sound_out.start();
          receive.im += createSender(username) + message + newline;
          receive.im.scroll = receive.im.maxscroll;
         
          //clear sent text
          send.im.text = "";
         
          //allow receival of data
          computer.sending = false;
     }
}


stop();


I will post the code that I am using.  I believe that the ASP files I created are correct because they work without fail when typed manually into the browser.  Any ideas are welcome.  Hre goes.....


Lets say I am at _root, I have a movieclip that checks whether or not to check for new messages(I guess the above could be coded simpler, using setInterval).  The code is as follows:

onClipEvent(load){
     sound_in = new Sound(this);
     sound_out = new Sound(this);
     sound_in.attachSound("in");
     sound_out.attachSound("out");
     i = 0;
     getData = 60;     //at 30fps, this checks every 2 seconds
     sending = false     //when you send messages, it disables checking until sending is complete
     
}

onClipEvent(enterFrame){
     if(!sending){
          if(i > getData){
               _parent.getMessages(_parent.username);
               i = 0;
          }else{
               i++;
          }
     }
}




On the first frame of _root, I have the following code:


username = "ocgstyles";
receiver = "chaimdavid";

//username = "chaimdavid";  <-- did this so i could quickly export the movie to test
//receiver = "ocgstyles";


//sets title of im window
imname.text = " - " + receiver;    


//URLs for ASP pages
URL_fetch = "http://localhost/chat/getmsg.asp"
URL_send = "http://localhost/chat/sndmsg.asp"



//loadVars
checker = new LoadVars();
checker.onLoad = showMessages;



//get messages
function getMessages(n){
     checker.load(URL_fetch + "?username=" + n);
}



//format names in IM window
function createSender(n){
     t = "<b><font color=\"#0000FF\">" + n + ": </font></b>"
     return t;
}
function createReceiver(n){
     t = "<b><font color=\"#FF0000\">" + n + ": </font></b>"
     return t;
}



function showMessages(){
     if(checker.newmsg == "True"){
          var ret_message = checker.message;
          var ret_receiver = checker.receiver;
          var ret_sender = checker.sender;
         
          if(ret_sender == username){
               var msg = createSender(ret_sender) + ret_message + newline;    
          }
          if(ret_receiver == username){
               var msg = createReceiver(ret_sender) + ret_message + newline;
          }
          computer.sound_in.start();
          receive.im += msg;
          receive.im.scroll = receive.im.maxscroll;
     }
}



function sendMessage(message){
     if(message != ""){
          //pause receiving data to send data
          computer.sending = true;
         
          //create URL
          URL = URL_send + "?sender=" + username + "&receiver=" + receiver + "&message=" + message
     
          //send data
          snd = new LoadVars();
          snd.load(URL)
     
          //update IM window
          computer.sound_out.start();
          receive.im += createSender(username) + message + newline;
          receive.im.scroll = receive.im.maxscroll;
         
          //clear sent text
          send.im.text = "";
         
          //allow receival of data
          computer.sending = false;
     }
}


stop();


forgot something...

The instance name of that movieclip on _root is "computer".
apparently, this things wants to post my comments more than once...  yee all shall read the writings of thee, a total number of times, three!  =)  ok, that was corny.
.... !!!

yeah i was wondering where the hack is "computer" come from ... ha ha ha

well well ...
at a glance it seems ok ...

let me chew on it a bit more.
i believe in ya henryww!!  i've seen your work on this thing!  =)
1) use setInterval will save u from doing the onClipEvent(load) & onClipEvent(enterFrame) and easier to work with


2)that looks a bit funny

function sendMessage() { // ....
...
...
         //create URL
         URL = URL_send + "?sender=" + username + "&receiver=" + receiver + "&message=" + message
   
         //send data
         snd = new LoadVars();
         snd.load(URL)

// maybe u can try this
var snd = new LoadVars();
snd.sender = username;
snd.message = message; // this way it will be escaped
snd.send(URL_send,"POST");
// u have to use request("message") or request.form("message") and NOT request.querystring in ur ASP
..
..
}

3) this may work on localhost but not online
functio sendMessage() {
// u have set the sending = true here
computer.sending = true;
...
...
...
// within the same function u then turn the sending = false???
computer.sending = false;
}

however, i suppose u want to set it to false when sending is done so, u should do something like that

var snd = new LoadVars();
snd.sender = username;
snd.message = message; // this way it will be escaped
snd.sendAndLoad(URL_send,"POST");
// and have the sndmsg.asp write finish=true or something

snd.onLoad = function () {
 if (snd.finish == "true") {
  // reset the flah here
  computer.sending = false;
  // etc etc
 }
}

that's what i've got so far ...
not having the complete fla ... i can only do so much.
but i am quite sure that's something to do with ur timing and variables.

change the functions so it will only check for new msg at exactly 2 sec or 3 sec ... but that if the last checking has completed so u will have to check it with a onLoad handler for the checker.

cheers
yeah? where?? ha ha ha ha ...

well, another way of doing a chat app with flash & asp ... that's if u have the control of the hosting server, u may try using application object with (change the global.asa and write functions there to send the new msg) ...

using database to keep track of the msg is ok, but having to delete and select and everything it is a really slow and processor intensive task, esp access !!!

btw, are u using DSN? do u have permission to delete records from the db ... that's something u should check also, if not u may not be able to delete the last sent msg. on localhost it maybe fine if u have done so allowing full control of the mdb file, on remote computer, u may have to see if the iusr_computerName has the right too to do so.

:) cheers

Thanks!  I will try you suggestions when i get a chance today.  I meant that I have seen your work here at experts-exchange....you always have answers!  Where would I put the setInterval line in my code, I have never used that function before, although I do know the syntax....??

here is my getmsg.asp file:  

<!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
' OPEN DATABASE
dim conn, conn_str, loc
set conn = Server.CreateObject("ADODB.Connection")
conn_str = "DBQ=" & Server.MapPath("OfficeIM.mdb") & ";DRIVER={Microsoft Access Driver (*.mdb)}"
loc = instr(conn_str, "OfficeIM.mdb")
conn_str = left(conn_str, loc-1) & "OfficeData\" & mid(conn_str, loc)
conn.Open conn_str

' DECLARE AND SET VARIABLES
dim rs, s_select, s_delete, com
dim username, message, sender, receiver, id, newmsg

set rs = Server.CreateObject("ADODB.Recordset")
set com = Server.CreateObject("ADODB.Command")

username = Request("username")
newmsg = false

' CHECK FOR MESSAGES
s_select = "select receiver, sender, message, id from messages where receiver='" & username & "' order by id"

com.ActiveConnection = conn
com.CommandText = s_select
com.CommandType = adCmdText
set rs = com.Execute

if not rs.EOF then
     newmsg = true
     message = rs("message")
     sender = rs("sender")
     receiver = rs("receiver")
     id = rs("id")
end if
rs.Close
set rs = nothing

' CLEAR READ MESSAGES

if newmsg then
     s_delete = "delete from messages where id=" & id
     com.CommandText = s_delete
     com.Execute
end if

set com = nothing

' RETURN RESULTS TO FLASH
response.write "&sender=" & sender & "&receiver=" & receiver & "&message=" & message & "&newmsg=" & newmsg

' CLEANUP
conn.Close
set conn = nothing

%>

I don't know why, but I used to use a different type of connect string...

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=myDB.mdb;Persist Security Info=False"

But for whatever reason, that was giving errors, so I used what I have above.

Like I said though, if I enter a message into the database:

sender: me
receiver: you
message: test
id: autonumber

if i type in browswer:
getmsg.asp?username=you

the code will return to the browser the reponse.write statement.  if i go back into the access file, the record was deleted.

stumped...  appreciate all the help!
I'm gone for a few hours, and all h@ll breaks loose :)


I don't feel like reading through all of the code, but I am sure you guys are working everything out fine...

I tested my example this morning, and I couldn't get it to work properly either :(    I need to find the application I made that stops the browser from caching the SWF...

I believe if you find that out, then your Application will work just fine...

I will look into it...

rp
i thought u had actually seen my chat app ... which is being used only in gov intranet... & my company's new website (to be launched soon) ...

and thanks for the compliment :)

// here's something wrong
' CHECK FOR MESSAGES
..
..
..
if not rs.EOF then
    newmsg = true
    message = rs("message")
    sender = rs("sender")
    receiver = rs("receiver")
    id = rs("id")
end if
rs.Close
set rs = nothing

'**** FINE : WHAT IF THERE IS MORE THAN 1 MSG??
' CLEAR READ MESSAGES
' ****** u are only delete 1 msg ??

if newmsg then
    s_delete = "delete from messages where id=" & id
    com.CommandText = s_delete
    com.Execute
end if





maybe i can just give u the pseudo logic of the chat ur trying to do ... u think that's ok?

[f] flash - [a] asp

+++++++++++ chkeck msg +++++++++++++++

*** 1) [f]
//frame 1 _root

// u can adjust the time 2000 millisecond
chkTimer = setInterval("chkMsg",2000);

// frame 2 _root
function chkMsg(){
      //so to stop the function being call again
      clearInterval(chkTimer);

      // set flag checking = true
      // checkfor new msg using loadVar, sendAndLoad (send username & load msg back) -> chatmsg.asp
      checker= new LoadVars();
      checker.username = username xxx;
      checker.load("chatmsg.asp",checker,"POST");
      // do a onLoad function to set the next interval
      checker.onLoad = function () {
            if (checker.msg != null) {
                  addmsg(checker.msg);
            }
            //only when it has finished loading and set the interval again, so this won't overload the server
            /:chkTimer = setInterval("chkMsg",2000);
      }
}


function addmsg(msg) {
      // split the msg using "$::$" or what delimited used
      // loop thru the array
            //send the new msg to chat window
      // end loop
}

*** 2) [a] chatmsg.asp
action = request("action");
if (action = "send") then
      // insert msg in the db, etc
end

chk for new msg
// sql = select all msg sent by the other user + delete all msg ie. delete * from table where username <> this user
// example
sql = "select * from messages where username<> '" & request("username") &"'" & vbcrlf
sql = sql + "delete from messages where username <> '" & request("username") &"'"
set rs = con.execute(sql)

// etc ... this way u will get all the records and delete all of them at the same time
// it will also prevent duplication of msg while fetching the same records while user is send a new one
// however ... !!! this is ONLY GOOD for a one to one chat !!! for a broadcast, no good, one user takes
// the msg doesn't mean all of them gets it already ... so ... a different approach

if new msg in db (rs not eof)
      fetch all record
      loop
            'use a delimited to separate multiple msg
            msg = msg + "$::$" + rs("msg")
      end loop
      ' so u won't have trouble with special characters
      response.write "newMsg=" & server.urlEncode(msg)      
end if



+++++++++++ send msg +++++++++++++++

1) flash - button - on release

if (msg !="") {
      // call the send function
}

function sendmsg(){
      snd = new LoadVars();
      snd.msg = msg;
      snd.usrname = xxxx;
      snd.action = "send";
      snd.sendAndLoad("chatmsg.asp",snd,"POST")
      snd.onLoad = function () [
            if (msg != null) {
                  addmsg(snd.msg);
            }
      }
}


ok... a bit of explanation for u ...

1) use the setInterval to run the function to check for new msg, that's if the user is idle,
doing nothing the msg checker will be run every some time to get new msg

2) use a function to sendAndLoad, while u are sending msg, might as well check for new msg ...

3) use only 1 asp to load & send, paste the extra insert code at the beginning so if it is a send command then do the insert db sql

4) fetch all msg and use a delimiter to separate different msgs anything u like but make sure it is hard enough that the user
won't use it. otherwise u may use the "newline" as delimiter if u only use a single line for entering chat

5) when select new msg from db, delete the records once is fetched, this u don't have to do the delete again and open the connection
which is faster and more efficient

i am  not sure if i am explaining it well, so ... let me know if u have any problem understanding it ...
or u can just stick with ur way of doing it ... :) mine is only a suggestion and a similar way i do it, but my chat is a multi-user broadcast so it is a bit more complicated from urs

:) cheers
ok cheers rp ... :)

we are close there ... i think ocgstyles is just missing on the flag settings and order, what to do 1st and what to do next .. it should be fine.



I just tried the send method, here is what i did.  on(press) would of course call this function....

function sendMessage(message){
 computer.sending = true;
 var snd = new LoadVars();
 snd.username = username;
 snd.message = message;
 snd.onLoad = function(){
  if(snd.finish=="true"){
   computer.sending = false;
  }
 snd.sendAndLoad(URL_send) //POST is default so left it blank
}

Added line at end of sndmsg.asp:
response.write "&finish=true"


That didn't work.  Now that I think about it, when I first started this project, I tried the send method, and I found that it wasn't working.  My method (as I showed you) did, so I just kept that.  Am I doing something wrong?  I even used the debugger in MX, placing a breakpoint in the onLoad function, it doesn't break there.  Never breaks at all....  

The problems are just 'a snowballin'!  =)
I just tried the send method, here is what i did.  on(press) would of course call this function....

function sendMessage(message){
 computer.sending = true;
 var snd = new LoadVars();
 snd.username = username;
 snd.message = message;
 snd.onLoad = function(){
  if(snd.finish=="true"){
   computer.sending = false;
  }
 snd.sendAndLoad(URL_send) //POST is default so left it blank
}

Added line at end of sndmsg.asp:
response.write "&finish=true"


That didn't work.  Now that I think about it, when I first started this project, I tried the send method, and I found that it wasn't working.  My method (as I showed you) did, so I just kept that.  Am I doing something wrong?  I even used the debugger in MX, placing a breakpoint in the onLoad function, it doesn't break there.  Never breaks at all....  

The problems are just 'a snowballin'!  =)
nevermind about the sendAndLoad question.  figured that out.  I had to change the command:

didn't work:
snd.sendAndLoad(URL_send, "POST");

worked:
snd.sendAndLoad(URL_send, snd, "POST");

whew!  ::wipes forehead::
so if someone could post the entire code, so I can figure out what is going on, I would appriciate it  :)


rp
ha ha ha .... snowballing... i like it ...

snd.sendAndLoad(URL_send) ??? WRONG

snd.sendAndLoad(URL_send,snd) <- this triggers the onload event

can u use debugger for that? u must run the flash in the browser to get it to work, u can't do a real submission that way (debugger & inside flash)

try again ...
ok ... give an hr or so ...
i will make an fla + asp + ms SQL example and post the link for u ..., so u can view it, download it ... etc

but u will have to change the connection string etc for the DB ... if think that's going to help u a bit more?

reply this post then i will start on it ... otherwise, i am too lazy to setup the table blah blah in ms sql remotely from home. 3am now, i wish i could sleep at 4am tonight ... he he he ....
ok then u figure it out ... fine :)


sorry rp, WYSIWYG ...

ocgstyles is a bit stingy on showing us the complete thing ... HA HA HA ...

nah .. just joking .. :)
I found it!!!!


okay...  here is a simple way to not have your variables cached...

http://www.macromedia.com/support/flash/ts/documents/no_caching.htm


you have to put the random thing in the loadVariables code like this:

loadVariables("mypage.asp?nocache=" + random(65000), 0, "POST");


that is how I got my other application to work properly...


so if you feel like abandoning all of the hard work that you two have done :) then you could just have your application call a PHP or ASP page every couple of seconds and the new data from the database will automatically appear in the SWF...


I have made a prototype with just a txt page, but an ASP/PHP page is much better...


This is an extremely simple way to create an IM or chat system...  just make a SWF with a display text area and and form that sends the variables back to the database...


I think I might just develop something like this for fun...  what would you recomend to use to store the information?  I think the typical database(Access or SQL) will get bogged down pretty quickly...


rp


what do u think ocgstyles? ....
ha ha ha ....

well, i wish that could just solve the problem :)

cheers rp

just for fun & practise
ocgstyles, let's have a race and see who fix the chat problem 1st, u work on ur code using rp's extra help + the above mentioned method and i start doing it from scratch now ...

if i win, extra 50pts :) and u get the code/working demo of it, if u win ... then .. well ... what do u want?

ha ha ha ...
cheers
I can send the files...just tell me the email address(es).  problem is, i don't have any web space that will execute the ASP scripts....  :(

ooh...that doesn't mean you guys don't though!  ;)

i was going to eventually work out something to retrieve all messages, using pretty much your method, but i figured i would work step by step.  just want to make sure it WILL work first.  Just wanted to get the basic sending and receiving working first.

I am trying (typing) the suggested pseudo-code up now....more later.
oh no!!   you gotta hold on for an hour or two.  i am leaving work in 25 mins, then there is the drive home.  yer gonna kill me in this race!!  

when i get home, i will also try rp's code too.  

this is actually my first post on here...  i guess i set how many points the question os worth, then whoever solves it, gets the points?  

if that is the case, this should be worth way more than 50, but 100 is all i have :).....

ha ha ha ... no no ... only if u can afford the 100 pts .. it is ok, just to make it a bit more fun ...

i am almost there ...

10 more mins ... then i can go to sleep ...

SHXT, i said i was going to sleep at 4am ...
are you really making yur own now?!?  that would be soooo not fair if you beat me!  are you in england by any chance?  (..cheers)
ASKER CERTIFIED SOLUTION
Avatar of henryww
henryww

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh .. i am sorry ...
just to make sure i know what i am doing ... that's all ...
it is all done.

hey ... i am the expert ok ... ha ha ha ... just kidding... no i am not!

anyway, i am using exactly the same the logic as provided in my previous msg ...

any chance u wanna chat?

ok i will wait for u ...
my uid=1

so u can choose any other uid=2 , 3 ,4 etc...

let's chat - will be there for 10 mins if u want ... :)

cheers

no i am in england, i am in HK GMT +8 & it is 5:30AM NOW ..
ok .. time's up ...
i am going to bed ... definitely this time!!!

adios amigo ...
well well ... that was fun ... :)
still trying all the suggestions i got.....
good ... :) it is better to learn and do it ur way rather than copy & paste the code ... isn't it?

take ur time, i am not in any hurry to claim the extra 50pts i won. .... BWHAHAHAHAHHAHAHAHA

cheers
well, here is what I did.  i studied the code that henryww sent me.  i got a lot of pointers out of it, saw some things in the ASP files that I never saw before....

ex.  concat'ing two SQL statement with a vbCrLf in between them.  I assume that when the connection is executed, it will run both in one shot.  (will this work for an access database too?)  

i created a simpler flash file that used some of my methods and his, and i did get it to work...HOORAY!!!  

if i had to say what was the problem, i think it was either the timing issue or the absolute address i was using, but i am leading more towards the address one.

when i made these, i tried them first with an absolute address, that didn't work.  i just kept getting blank messages.  when i changed the ASP page to a relative address, it worked!!!  i believe the use of setInterval and clearInterval definitly helped with the amount of I/O too.  
henryww, as they say in the English movies.... "GOOD SHOW!"  
Just when I got my chat system working :(  

It is very simple in nature, and I have to "upgrade" it a bit, but I just use the loadVariables("message.asp?nocache=" + random(65000), 0);  method, and an ASP page connecting to a SQL database...

It works like a charm...  I just need to add some username/login features...


I will try and convert it to an Access database system, so it is more "portable" and so you guys can see it on my person site...  right now it is on the DEV box at my work...  

let me know if anyone is interested in seeing what the prototype can do...


rp
i just tested mine with a guy here at work.  i am not sure if his system just crashed or if my chat app did it.  worked fine on mine.  i would think that my computer would get hit more because i am handling mine and his requests, plus my SWF....  

not sure if it is related though.  he is affraid to test it with me again.  :(
rp, i am interested in seeing the prototype..
I will try to convert it to Access and post it on my personal site then...

I will let you know when it is live...


rp
hi all,

thanks ocgstyles  for the extra pts :) ha ha ha ...

(will this work for an access database too?)  
i am not 100% sure, i have not use access since 2.0, sorry ... but give it shot it should be right. because opening db connection and excuting query is a costly action, do it as quick as possible and only when necessary, u may also want to change sql, don't use "select *", list all fields even "*" is what u required (that's faster) ... there is more & many useful tricks as to do asp, sql, flash, i am only a beginner :)

maybe is his flash player, try install the lastest from macromedia ... i only used an hour or so to build the thing (i thought u were racing with me too), so there must be some flaws in the code, if u follow some of it and not all, then ... the chance of crashing is even great ... ha ha ha ... nah ... i am like u ocgstyles, don't like copy & paste code, i would rather learn from the code and add my own part to it or improve on it, so i know every single line what is it doing... the point is not just to have it there, but knowing how to do it again and better next time, right?

as for the annoying "click to send", paste these code

keyListener = new Object();
keyListener.onKeyDown = function () {
     if (Key.getCode() == 13) {
          sendChat()
     }
}

Key.addListener(keyListener);

so u can just press enter to send msg
could have done better if i was not that sleepy ...

rp, yes sure. show us the link. i am sure urs is better mine. after all i am not designer, no sense in that...

everyone knows something the rest don't, since everyone is here, together we can help to build the chat room ocgstyles wants. a common lobby and a 1v1 chat in a popu p right?

but i am not quite sure if u should stick with the access db method ... hmmm... it is only good for a few users but say 50 users online chating, i don't think so.

i actually leaning to the application object using asp only, the database is only used for authentication and this way works faster for sure, less overhead etc ...

what sort of hosting environment do u have ocgstyles? can u have global.asa for ur site?

cheers

Okay....  if anyone is interested in testing out my IMC, then go to the below address at exactly 11:30am GMT - 06:00, which is in about 8 minute on my clock... I will have my page open for about 5 or 10 minutes...


http://www.rascalpants.com/imc


rp


P.S. don't laugh at my prototype...  I just made it to test :)
no no ... it is good ...
i am there, can we with more than 1v1 there?
mayday mayday .... ... .. .. over & out ...

I will keep my page open until someone helps me test :)

rp
i can see the date & time coming out, but u can't seems to see what i sent ... u there ...

i am still there ... i sent msg but can u see it?
i've just got "Hello World!  -  5:48:19 PM" come up on my screen ...

who wrote this message:

so .. .so this thing is going to boardcast the msg to all every how long?
  -  6:01:03 PM


It is the only one I did not write, so something is working...

rp
at first the IMC chatting was going ok...  but it seemed to slow down as it progressed.  when i would press send, my message would just stay on the screen for a bit, then after 1-2 mins, the screen would refresh.  kinda like when you press submit on an html form, and the page tells you... "ONLY PRESS ONCE!!" :)

i knew about the keylistener object, thanks henryww.  although the thing i am not too sure about it how to turn the listener on or off.  obviously when there is more than one chat window, you only want to send the focused window.  it will take some experimenting with maybe the selection object ... (????)  i am thinking that i will have to make each window that is created, its own separate object.  

right now, i don't really have any webspace.  i have been thinking about getting some though, just don't know what to look for.  obviously i would want something that could handle server-side scripts, and an available SQL database would be nice too.  but i gotta look around.  

at home i am running an oracle 9i instance on my box too.  only problem with that is, i can't use IIS when i use that, because apache opens too(i don't know anything about apache.  i know the physical/logical structures for oracle, but don't know much on the networking part yet.....  

i usually just resort to access because the development is so much quicker.  
That is really weird about the problems you were having... because my co-worker and I were able to send messages one after the other, and it was almost instantanious...  and when I was trying to communicate with you, I could send a dozen or so messages before you replied back to me...

I wonder if it has something to do with the location of my host company in relation to the people using the web application...  I am located in the Midwest USA, and I think you said you were in England somewhere...  One would think that you would be able to post quicker than me, because my hosting company is located in either Ireland or England...


anyway... I need to test this out more with people here in the US...

let me know if someone else wants to test this thing with me... or feel free to test amongst yourselves...


rp
i was commenting on henryww, because he says cheers, figured he was from england.... turns out he is.  i am located on the east coast, USA.  i am testing mine out with some other people here at my office, seems to work OK, no big lag.....of course the server is my computer!  
well then you are closer to me to my server :)  not sure why you were having problems...  if you get a second have your coworkers test my app as well, and see it it helps to have the people on the same network....


http://www.rascalpants.com/imc


if you don't have time, I understand...


rp
Big O,

thanks for testing...

are you in NYC per chance?


I might post a question and try to have a bunch of people in different parts of the world use the app all at one time...  see if we can break it :)

rp
yo .. how's it all going?
hmmm .. i am not in UK, neither from UK ...
i am actually in HK (hong kong)... :)

well i had the same problem ocgstyle had, i type in so many things and no reply that message u got... like i have entered a dozen of msg before that, and it seems like is talking some time ... a few mins for each msg to come.

hmm ... i am trying to modify the code for multiple-user chat base on the same db logic. it is still kind of fun to work on it...

wow... ocgstyles, what do u do to have oracle on ur box, ... are u a developer? DBA? having played around with sybase for a little while, i will no to oracle & alike.

it is hard to imagine what u have on ur box, NT?2K + apache + IIS + oracle + Access ... etc?

apache can work with asp & odbc too ... on linux it needs chilli asp ... or something ... it comes free with cobalt server, and they are everywhere for hosting use.

as for ms sql ... i don't think so. guess the license is too expensive. that's why using application object might solve the problem, but then again ... not many hosting will allow a global.asa cos if it crash, it may crash the whole iis too ... !!!

:) will be right back as soon as i know how to store make the date/time field to millisecond precision ...

cheers
ok ... done ...

here's the new version :)

http://www.smartclever.net/example/flash/chat/

anyway one can join and chat, next is to have a userlist and see who is online - the lobby ...

so this is the common area u can chat and later when we have the lobby then we can do 1v1 in a popup window. user can invite private chat from the list ...

cheers :)
the original code was code, and i used a session variable to check the last question fetched, but then ...

IT DIDN'T WORK ... then i thought it was something to do with my date/time field,.... playing around with the code checking everything and i looks good... no ... it still doesn't work ...

and u know what ... the stupid thing is when i was testing the it i have 4 windows opened ... all from the 1st browser window & ctrl-N to open a new one! ... so ... the same session variable is being used! damn ... wasted an hour for this!

...... !!!

cheers guys, have fun and i am going to have a early night tonight ... bye now!
oh... one more thing ...

got a few bugs in the original 1v1 chat,

1) there should be an extra line in the sendMsg function so to scroll the text box to the bottom

2) uid is not right, i am using the user's uid instead of the sender's uid ...

... but everything has been fix in the new one :)
another question about this project.  i see that in the ones you guys made, you use a 1 line sending textbox.  in mine i have a multiline input textfield.  i added the keylistener into my code.  the listener works and the message is sent, but the enter keypress is still received by flash, and the cursor jumps to the next line.  how can i get the cursor to jump back to the first line after sending?

i have tried....

Selection.setSelection(0,0);

-and-

send.im.text = "";

i was kind of hoping for something like VB, pseudo-code

if key="enter" then
 do action
 key=null
end if

when u assign null to key, it would see this as never hitting the key, but your action would still be called.

the weird thing is, this only happens the first time you send a message, the cursor stays at the second line for every other keypress.

ideas?
tried this in a separate file, in an onpress button event

Selection.setFocus(send.im);
Selection.setSelection(0,send.im.length)
send.im.text = "";

that works fine for the button press, but because of the keylistener, it inserts the "newline"
i am not quite sure what u mean by multiline and "hit enter to send" ... how?

if the box where u enter the text is multi-line then ... ? enter sends each line? ....?  don't know ...

but if u are clearing a the textbox everytime after it's been sent, set .text = ""; and it will go back to the top.

... just try to reset the text=""; for both even ...
or do the icq style - ctrl-s or button to send, enter=newline ...

:)

cheers
in case RP and henryWW check back soon...  i am nearing completion with that chat application.  got some webspace too...

check it out:

http://elementfixe.net/echat

it won't be up for another hour or so.  the files are there, i just needed to have my web host modify some stuff.  the application is a little buggy, but nothing huge.
I saw your application... looks pretty good...

I have a question though...  In my application... I am using a simple looping movieclip that does a loadVariablesNum("message.asp?nocache="+ random(1000000), 0 );  in about every quarter of a second...  

Is the application calling my server every quarter second and using bandwidth?  I want to know, because I only have 1000mb of bandwidth per month...  I don't want to waste it all testing out my Flash Chat application...  


any thoughts on the subject...

Also, I have the screen open on the development laptop pretty much all day long, so if anyone wants to chat :) I will reply pretty quickly...


rp
Thats probably why your application was taking so long...too many calls to the server.  i found another way, and easier to refresh the pages.  can't believe i didn't think of it before.  if you are working with ASP too, just add:

Response.Expires = -1442

That will make sure your page expires once viewed, for all time zones.

mine is checking every three seconds. and the buddy list checks every 10.  

i guess i should check out how much bandwidth i have, because i don't remember.

i don't have anything really up yet, except testing that, so right now its not a big deal if i use alot of bandwidth yet.

i updated my chat app too...so when i get a chance i will be updating that too.

laters...

-ocgstyles
newer version is up....

http://www.elementfixe/eim

=)
hmmm i can't see anything ...
too late?
aren't i stupid!!!  forgot something in the URL....

http://www.elementfixe.net/eim

sorry bout that
the interface looks cool man :)
let's try it together some time ...
cheers
I put these lines of code in the page, and it works better now...

<meta http=equiv="Expires" content="Fri, Jun 12 1981 08:20:00 GMT">
<meta http=equiv="Pragma" content="no-cache">
<meta http=equiv="Cache-Control" content="no-cache">

I also added you line of code O, and I really can't tell any difference...

Does anyone have any idea about bandwidth using and a Flash application loading info from a another page...  Is that the same as a user requesting a page from the server?  If so, then I need to increase my message checking to more than a 1/4 second!!!  

any ideas?

rp
hi rp ...

well ... i don't why it doesn't work for u ...
but it is like the random variable we used to do, very common...

see this
http://www.permadi.com/tutorial/flashcache/
for more info.

that way u do it will work too, and is the standard way to add document header prevent browser from caching, 100% perfect  ... i just don't like this Uritsukidoji guy, the way he thinks that his solution is the most "elegant" and tell ppl to look at it from other thred ... what is that!!!

he is so ... so ... don't know what word to use ... i am not saying that my solution is the best, i didn't even provide a solution for the question.

i have no problem with what he said in avirama2's thread but just that he goes to other thread and started again ... !! damn!

i didn't really want to argue with anyone, but telling ppl to switch off the cache of the browser is an "elegant" solution ... yeah right!!

cheers rp
turning off your browser cache isn't a solution!!  don't know why that would even be an option.  i would think that is why there are method that we are describing.

for rp... I believe that you should decrease the frequency that yours checks for new messages.  i looked at the statistics for my site, and i do see a lot of hits.  i would imagine that it also counts for bandwidth.  with each check you probably aren't using more than 1-2K bandwidth, but if you are in a situation with a lot of people...that can add up.  

i didn't even think about that actually....about it taking up bandwidth.  i changed mine from checking for messages every 3 seconds and buddy list every 10, to just check everything every 5 seconds.  that would cut out on a lot of IO.  and frankly, you would be using this over a network anyway, so the other person would have no idea when you actually sent the message....ya know.  

i haven't posted this new one yet though....  i am logged on mine right now...will be for the next 10-15 mins...

-styles
u guys still there?
"that way u do it will work too, and is the standard way to add document header prevent browser from caching, 100% perfect  ... i just don't like this Uritsukidoji guy, the way he thinks that his solution is the most "elegant" and tell ppl to look at it from other thred ... what is that!!!"

that guy is an idiot...  I hope he doesn't start up again, because I would probably get kicked of the site for Flaming him too much :)

What does Uritsukidoji mean anyway?  if you are going to have a dumb user name, it should be something like rascalpants....

I hope that isn't the guys name though... he would be offended by that last comment...  :)


rp
oh sorry rp ...

i was so pissed off by the Uritsukidoji's comment so ... i didn't read what u were actually saying ...

ocgstyles - i missed the chat again ... hmmm ...
very nice, i think that feature is good, like a personal msg ... it makes sense, i like it

cheers guys
ha ha ha .... .... ha ha ha .....

hey ocgstyles,

why i see so many henryww when i login ...
like i saw 3 at 1st then i log off and on again ... then i saw 5 ... henryww on the user list ....

hmmmm ...
I think you see multiple usernames, because clicking on a name is sending the info to that person... am I right?

since typically there is only one person on this thing, you can only talk/test with yourself... so you click on the only name there....

I might be way off though...


rp
hmmm ... maybe that's the case, or a feature which can be used, somehow, so if we have no one to talk to at least we get the echo back .... interesting ... :)

rp ... no ... no ... why are u doing this to me ... i worked so hard to get up to 9... and now u want to send me back to rank 10 ... why?? LOL ...

u know i can imagine how happy u are now, and me too ... this is fun ... well, at least to have a competitor & a true expert to work together & solve problems ....

cheers all
I just can't believe how fast you went from 10,000 to almost 23,000 in like a week or two...  you are truly an EXPERT.

this is fun though...  I don't think that single question is going to do much at the rate you are going...

hell you will be in the top 5 by the end of the month!


go show!

rp
ha ha ha no no ...

i don't think so, but i do enjoy working & solving problem here in this community ... nice :) and learn a lot really, i have just copied ur code for the php & pdf question ... gonna work it out tomorrow.

huh? by the time we both get up to the top 5 ... maybe no more questions ppl will have to ask about flash... until a new version is out flash XP or flash 2003 .. !? unless they don't look into the previously asked questions... HA HA HA ... LOL ...

just kidding, i am sure there heaps of things we don't know and never heard of ...

but it is amazing how some similar questions keeps poping up every now & then ... preloaders, i don't like preloader questions ... it is boring.

anyway, goodnight guys ... have to get some sleep now
geez H!!!  you must really like the chat room a lot....yer there 6 times!! =)  so you guys figure out why that is happening yet?!?

simple actually...  i don't know how i can get a browser close event to delete the username from the current users list in the database.  so, if you just close it, you remain there.  if you click the X at the top of the buddy list, you can logoff the right way.  

i know there is a flash event when you unload a movie, but i don't think it will work for "this"... only movies that have been dynamically loaded.

stumped on what i should do....  i thought of just putting a flashing logoff button.....but that seems tacky.  damn stateless web...

-styles
well styles, you could perform an Javascript function that does something when the page unloads...

just like the popup windows that come up when you try to close a porn site... or so I have heard :)


is that an option?


rp
most definitly!!  gotta dig out the ol' javascript book and look at it....
hmmmm.... i don't know how i would pass the username value to the onUnload function though.  i would have to rework everything....
i don't know what ur are doing now styles, but it is supposed to automatically remove any outdated message etc right? and u can do that to the user too.

like everything when a user checks for new message it will also update the time (if there is a login record) and when a user sends a message, remove users from the database which have been idle for a prolonged period ...


ie:
henrywww login
a record is create .. when datetime etc ...
everytime henryww checks for a new message, it also updates the datetime field
(say if every user checks for new msg every 3sec)


rp login
another record is created, ... blah blah ..
when rp sends a message ..
if also checks and see if henryww's record shows the corrcet time stamp, if not ... remove henryww for the active user list.

(inactive for 5,6,7sec etc ... therefore longer than the 3sec ... no longer active, so henryww must close the browser already or something ... remove henryww from the active user list)

would that help?

cheers

i was thinking something like that.  i just find it funny actually that a group can make an application 'flash' and not include something to test for when the movie unloads all together.  ...a lot of other langs have that option.....
well .. it is the browser not the flash ... flash embed in the html is still connectionless & stateless

actually if u can change the global.asa then u can have a script for the session.end and have it remove the user list automatically.
i gotta look into that...i think you mentioned that above too....  but if i have an error it brings down the whole server....something like that.  so they may not give me access to that.
that's true !!! ... ha ha ha ...
i am not sure if the hosting actually allow that .. if any at all ... guess i am lucky to have servers to play with since a long time ago ... cheers O
HENRY!

I just can't keep up!  I thought the 2000 pointer would give me some breathing room, but you go off and get a couple thousand more points on me...

I am afraid I will have to throw in the towel.  I will have to get a couple of those 2000 pointers a week just to keep up...


Maybe someday I will see you at the top :)


happy coding...

rp
:) no ... that easy rp .. i will slow down a bit ...

i've got a 500pt coming and u too :)
but some previously answered questions keep coming back and asking for help for other stuffs .... so it is quite overwhelming that way.

but those 2000pt questions u answered were so fast ... i don't even have time to think and u got it already ... one i didn't even see it ... u cheat while i was sleeping LOL...

ha ha ha ....

no no ... if i am at the top, i will throw some 500pts hard questions and u will be the only one to answer those questions right?

cheers all
no need to throw me a bone...  I can't keep up, because I am getting way to busy here at work...  I will make it up to the number 2 position someday :)


rp
LOL ... not like that man ...

i know u are a real expert too. :) honestly.
come on rp ...

u are not angry with me are u ... ?

i was only joking about the pts ...

u know ...
you guys are funny!  one day i hope i can see my name in the top 15 experts...  that is, as long as people answer questions when H is sleeping.  he is just too quick!  

u saw i was pretty busy last night, right H!  =)

cheers experts!

-styles
yes ... i was suprised ...
great work my friend ....
big H, no problem0, and no offense taken at all my man...


rp
what a race man ...

this is getting so exciting ...
see the jumps in pts we made in this few weeks ...

and before u know ...
very soon ... both rp & i will be in the 1st & 2nd position and wrestling up & down ... LOL
... then every afternoon/evening, styles will answer all the questions and sneak right up on yall!  that may take a long time now that i think about it.... =(  
still u are making progress O .. won't be long ... we will see u soon in the top 15 ...