Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash/ColdFusion refresh?

Status
Not open for further replies.

cruise95

Programmer
Oct 7, 2003
56
US
Hello,

does anybody know how to refresh a FLASH file and/or flush all data? I am currently using Flash to talk to a ColdFusion file - this file retrieves data from a database and sends the results back to Flash. Everything works good on the file, but when I edit the database in Flash, the FLASH file does not reset and show the new data. Upon clicking a button, you are sent to (via gotoAndPlay(1)) frame 1 where loadVariablesNum is called again, yet it seems to continue using the old data.

The FLASH file seems to cache after rendering the page. The only way to see the new Data populate on the Flash file is to closing the browser and reopen it again (or manually refresh the screen).

Is there a way to flush a FLASH file of old data and be able to see the new data while still playing the file?

Thanks
 
How are you sending the variables to the cold fusion page? More importantly how are you returning the variables to Flash?

Are you using the sendAndLoad Object? Something else?

JT
 
Right now I am not using a load object...just loadVarsNum:
loadVariablesNum("selectNames.cfm", 0, "POST");




The code above is implemented on the 1st frame. It sends data to and receives data from selectNames.cfm:

selectNames.cfm:
<cfquery name="selectNames" datasource="#dataSource#">
SELECT id, S1, Name
FROM QBOS_HelpFile
</cfquery>

<cfoutput query="selectNames">
&id#currentrow#=#id#&S1#currentrow#=#S1#&Name#currentrow#=#Name#&
</cfoutput>
<cfoutput>
&numrecords=#selectNames.recordcount#&
</cfoutput>


After recieving the data in Flash, the data is placed into variables. Then the user has the ability to edit these variables (their information). Once they edit it, then Flash sends the new values to updateData.cfm using loadVarsNum again:
loadVariablesNum ("updateData.cfm", 0, "POST")




This works OK for the first time that they edit their information...but if they edit it again, then their information in the database gets messed up. This is because the they are still editing the old information in the variables.

A solution would be to get the new data from the database again. I tried doing this using
loadVarsNum("selectNames.cfm,0,"POST")
but the output in Flash showed the old information and not what is in the database. It is like Flash can only read from the database one time and then will never read it again to get the new information.


Sorry for the long explanation...I was trying to explain the situation well. Did I explain my problem clearly? What do you think I should do?
 
By using the loadVars object you can monitor whether or not you are receiving data. Here is an example.
First frame main timeline:
Code:
_global.updateVars = function (id,s1,personName) {
	myVars = new loadVars();
	myVars.onLoad = function(success){
		if(success){
			_root.flashVariableName1 = myVars.variable1;
			_root.flashVariableName2 = myVars.variable2;
			_root.flashVariableName3 = myVars.variable3;
		}else{
			trace("No information was received from the CFM page");
		}
	}
	myVars.sendAndLoad("selectNames.cfm", this, "POST");
}

In the example above you would call the function everytime you want to update the info in the movie. If on a button:

Code:
on(release){
   _global.updateVars("1","2","3");
}

I think you will find that sendAndLoad is the way you need to go to accomplish what you are trying to do. The code above will definitly require some tweeking to fit your needs but I hope that helps to get you started.

In theory you should be able to use the same CF page to process the original query and the update. If not you would need another function like the one above to go to the "update" page.

Good Luck!

Wow JT that almost looked like you knew what you were doing!
 
Thanx...I appreciate your suggestions. I will try that and let you know -

Frank
 
Sorry I didn't get bask to you sooner...I've been working on some other parts of my Flash app that wasn't dependant on loading details

I did switch to LoadVars using sendAndLoad. It works similar to what I was doing...but it does return a value to let you know if you have recieved the data. I know that I am close...but I am still having trouble getting it to refresh the data.

This is wierd since I've included
getURL("selectNames",_blank) for debugging and it gives me the updated string of name/value pairs.




[highlight]FLASH - "selectNamesLbl" (FRAME 1):[/highlight]

container = new LoadVars();
container.sendAndLoad("selectNames.cfm",container,"POST");

container.onload = function() {
gotoAndStop("resultsLbl");
getURL("selectNames.cfm","_blank");
}
gotoAndStop("selectNamesLbl");



[highlight]COLDFUSION ("selectNames.cfm"):[/highlight]

<cfsetting enablecfoutputonly="Yes">

<cfquery name="selectNames" datasource="#session.PrimaryDS#">
SELECT id, keywords, Name
FROM QBOS_HelpFile
WHERE S2 = 0
</cfquery>

<cfoutput query="selectNames">
&Name#currentrow#=#Name#&keywords#currentrow#=#keywords#&id#currentrow#=#id#&
</cfoutput>
<cfoutput>
&numrecords=#selectNames.recordcount#&
</cfoutput>



[highlight]FLASH - "resultsLbl":[/highlight]

for (i=1; i<=container.numrecords; i++) {
createTextField("textBox" + i,i,20,i*30,100,20);
var thisTitle = eval("textBox"+i);
thisTitle.Text = eval("container.Name" + i);
}

I have a button on this frame:
on(release) {
for (i=1; i<= container.numrecords; i++) {
_root["textBox"+i].removeTextField();
}
gotoAndPlay("updateScreenLbl");
}



[highlight]FLASH - "upadteScreenLbl":[/highlight]

Has two textboxes - uName,uKeywords
And a button:
on (release) {
sendObject = new LoadVars();
sendObject.uName = uName;
sendObject.uKeywords = uKeywords;
sendObject.sendAndLoad("updateTable.cfm",sendObject,"POST");
gotoAndPlay(1);
}



[highlight]COLDFUSION - "updateTable.cfm":[/highlight]

<cfquery name="updateData" datasource="#session.PrimaryDS#">
UPDATE QBOS_HelpFile
SET name = '#form.uName#'
WHERE keywords = '#form.uKeywords#'
</cfquery>




I know that this is a mess to go through. If you can, then can you look at this and let me know what you think? Or let me know if you have any questions...I appreciate it -

Frank
 
Well for starters you don't need the getURL in there. You have just loaded the variables (you don't need to load them again) :) Otherwise it looks like you have a bunch of things that are 99% there but just not quite. Let's see if we can get it to work for you.

Part of your problem is that you are trying to refer to the container object when you haven't made that information available to the whole movie.

I would combine your "selectNames" AS with your "resultsLbl" AS. In other words on the resultsLbl frame place the following.

Code:
function getVars(){
	container = new LoadVars();
	container.onLoad = function(success){
		if (success){
			for (i=1; i<=container.numRecords;i++){ //this will allow you to access your numrecords variable
				createTextField("textBox" + i,i,20,i*30,100,20);
    			var thisTitle = eval("textBox"+i);
			    thisTitle.Text = eval("container.Name" + i);
			}
		}
	}
	container.sendAndLoad("selectNames.cfm",container,"POST");
}
getVars.call();

It looks to me like you are trying to give line item editing is that right? Let me know and I will help you through the button.

Your update screen looks like it should be working. Let me know if you need help there.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
What I am doing (eventually) is creating a drag-n-drop menu like the one like the one in Windows 2000.

The AS for what I have so far is kinda long and so I didn't want to try to simplify my problem as much as possible.

basically, when you drop a file (MovieClip) in between two files, or drop one file ontop of another, another file is created dynamically. This works right the first time, but since the file is not refreshed, then it will not work properly the second time (unless refreshing the screen).

I thought that a textbox would be the easiest thing to replicate and that it would closely resemble what I was trying to accomplish.



I rewrote my example app. so that my Flash is is all within one frame. It now reads:

FLASH (update.fla):
Code:
var chosenNum;

function getVars(){
  container = new LoadVars();
  container.onLoad = function(success){
    if (success){
      for (i=1; i<=container.numRecords;i++){
        createTextField("textBox" + i,i,20,i*40,100,20);
       	  var thisTitle = eval("textBox"+i);
          thisTitle.border = true;
          thisTitle.borderColor = 0x000000;
	  thisTitle.Text = eval("container.name" + i);
          thisTitle.type = "input";

        thisTitle.onChanged = function() {
          chosenNum = Number(this._name.substr(7,2));
        }
      }
    }
  }
container.sendAndLoad("selectNames.cfm",container,"POST");
}

getVars.call();
stop();


[highlight]there is also a button on this page:[/highlight]
on(release) {
  for (i=1; i<=container.numrecords; i++) {
    _root["textBox"+i].removeTextBox();
  }
  sendObject = new LoadVars();
  sendObject.Name = eval("Name" + chosenNum);
  sendObject.id = eval("ID" + chosenNum);
  sendObject.sendAndLoad("updateTable.cfm",sendObject,"POST");
  gotoAndPlay(1);
}


COLDFUSION ("selectNames.cfm"):
Code:
<cfsetting enablecfoutputonly="Yes">

<cfquery name="selectNames" datasource="#session.PrimaryDS#">
    SELECT    id, Name
    FROM    QBOS_HelpFile
</cfquery>

<cfoutput query="selectNames">
&Name#currentrow#=#Name#&keywords#currentrow#=#keywords#&id#currentrow#=#id#&
</cfoutput>
<cfoutput>
&numrecords=#selectNames.recordcount#&
</cfoutput>

COLDFUSION ("updateTable.cfm"):
Code:
<cfquery name="updateData" datasource="#session.PrimaryDS#">
	UPDATE	QBOS_HelpFile
	SET	name = '#form.Name#'
	WHERE	id = '#form.id#'
</cfquery>

Thanx again for your help -
Frank
 
I didn't include the AS code to get the IDs...replace this update.fla with the one above. Here is the REAL AS code:

FLASH (update.fla):
Code:
var chosenNum;

function getVars(){
  container = new LoadVars();
  container.onLoad = function(success){
    if (success){
      for (i=1; i<=container.numRecords;i++){
        createTextField("textBox" + i,i,20,i*40,100,20);
        var thisTitle = eval("textBox"+i);
        thisTitle.border = true;
        thisTitle.borderColor = 0x000000;
        thisTitle.Text = eval("container.name" + i);
        thisTitle.variable = eval("name"+i);
        thisTitle.type = "input";

        _root["id" + i] = eval("container.id" + i);

        thisTitle.onChanged = function() {
          //this gets the number (i) after the name "textBox"
          chosenNum = Number(this._name.substr(7,2));
        }
      }
    }
  }

  container.sendAndLoad("selectNames.cfm",container,"POST");
}

getVars.call();
stop();


[highlight]there is also a button on this page:[/highlight]
on(release) {
  for (i=1; i<=container.numrecords; i++) {
    _root["textBox"+i].removeTextBox();
  }
  sendObject = new LoadVars();
  sendObject.Name = eval("Name" + chosenNum);
  sendObject.id = eval("ID" + chosenNum);
  sendObject.sendAndLoad("updateTable.cfm",sendObject,"POST");

  gotoAndPlay(1);
}
 
alrighty,

its working...at least that little Flash thing works. Now I have to incorporate it into the bigger Flash file that I've been working with.

The ColdFusion code stays the same, and here is the AS:
[highlight]Frame 1:[/highlight]
Code:
var chosenNum;

function getVars(){
  container = new LoadVars();
  container.onLoad = function(success){
    if (success){
      for (i=1; i<=container.numRecords;i++){
        createTextField("textBox" + i,i,20,i*40,100,20);
        var thisTitle = eval("textBox"+i);
        thisTitle.border = true;
        thisTitle.borderColor = 0x000000;
        thisTitle.Text = eval("container.name" + i);
        [COLOR=#0000FF]thisTitle.variable = "name"+i;[/color]
        thisTitle.type = "input";

				
	_root["id" + i] = eval("container.id" + i);
	thisTitle.onChanged = function() {
	  chosenNum = Number(this._name.substr(7,2));
	}
      }
    }
  }
  container.sendAndLoad("selectNames.cfm",container,"POST");
}

getVars.call();
stop();

[highlight]a button on this page encapsulates this code:[/highlight]
on(release) {
    sendObject = new LoadVars();
    sendObject.Name = eval("Name" + chosenNum);
    sendObject.id = eval("ID" + chosenNum);
    sendObject.sendAndLoad("updateTable.cfm",sendObject,"POST");
    gotoAndPlay(1);
}


This can all go in frame 1. That's it...

The thing that I was doing wrong (among other things) was that I was not getting the value of the textField's variable. I coded this in blue in the code above

Also...I'm the only one who even dares to learn Flash around here, and I was wondering if I could look you up and email you if I get stumpped . I've been doing pretty good so far...slow, but contunous. This last problem dosen't seem too hard now that I know what I'm doing! I scoured the tutorials and any leads that I could get, but finding help on it was hard. You seem to know Flash very well.

if you don't want to leave your contact info here then you can email me at frankdewey@hotmail.com.

i appreciate your help -
Frank
 
I goofed...

I only thought that this was working. Once you change the name, then click on the button, the table is updated and the name has changed. The name changed because you changed it and not because Flash uplaoded the edited name from the table.

However, when you try to insert another name into the table, then it is not displayed in flash. Again the new information is inserted into the database, but flash does not display the change.

Any ideas on this one? Thanx
 
I'm going to need to be able to see it. Is it possible to zip up the whole thing and send it to me?

pixl8r@msn.com

BTW: What version of flash are you using?

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top