Groups | Blog | Home
all groups > macromedia flash flash remoting > may 2004 >

macromedia flash flash remoting : AAAHHH!!! Movie loads before database Insert


CF_Admin
5/3/2004 9:34:29 AM
Hi all...

I really am ready to scream. I have tried everything I can think of, but no
matter what I do I get one of the same 2 results.
Either the movie loads faster than the data can be sent to ColdFusion, or the
data gets sent, but the movie doesn't load. I have TONS of other work to do on
this project, but I have to get this figured out before I can move on.

This is a registration form, in Flash, for a chat room... that is also in
Flash. I am sending the user info from the form to a ColdFusion Component. This
works fine, the database insert goes smoothly, as long as I don't try and load
the movie (either login.swf, or the chat room, doesn't matter at this point).

Here is the current client side ActionScript:

stop();
message = "Only the biography field is not required"

Password.password = True
Verify_Pass.password = True

Selection.setFocus("_root.fname");

#include "NetServices.as"
#include "DataGlue.as"
if (isGatewayOpen == null) {
// do this code only once
isGatewayOpen = true;

NetServices.setDefaultGatewayUrl("http://127.0.0.1:8500/flashservices/gateway");
gatewayConnnection = NetServices.createGatewayConnection();
register = gatewayConnnection.getService("poetry.register", this);
}


function putRegister() {

if (fname == null) {
Selection.setFocus("_root.fname");
message = ("first name is a required field.");
}

else if (lname == null) {
Selection.setFocus("_root.lname");
message = ("last name is a required field.");
}

else if (uname == null) {
Selection.setFocus("_root.uname");
message = ("user name is a required field.");
}

else if (email == null) {
Selection.setFocus("_root.email");
message = ("email is a required field.");
}

else if (passw == null) {
Selection.setFocus("_root.passw");
message = ("password is a required field.");
}

else if (varpassw != passw){
Selection.setFocus("_root.passw");
message = ("Passwords don't match, please re-enter passwords.");
}


else {
register.putUser(fname,lname,uname,passw,email,bio);
message = "";
}


if (message == "") {
loadMovie("index.swf",_root.background_mc.gotoAndStop(2));

}

}

Also, as a minor annoyance, the above load movie goes to the root (the home
page) instead of the chat room (background_mc frame 2). I would probably load
login.swf after they register anyway, but then I will have the same problem.
The client wants the registration and login to be in pop up windows so there
are 3 seperate .swf files... as I said though, this is just an additional minor
annoyance, the REALLY BIG problem is that when the movie loads at all, it
interupts the data transfer before it can happen... I have tried a variety of
conditions, and combinations of conditions, and always with those same 2
results... movie w/o insert or insert w/o movie %^/

Please someone Help!

Thanks

pstnotpd
5/3/2004 11:53:40 AM
You start the loadmovie depending on the value of message. This will not
work as the remoting call is by nature asynchronous. You should only
start the loadmovie when actually receiving a result from remoting
indicating that the form is handled correctly. If your CFC component
doesn't return anything make sure it does. The trace will then show a
result function being received which you can use as a trigger to start
your loadmovie.

CF_Admin
5/3/2004 3:18:38 PM
Yes, like I said this was the current version, I tried everything I could think
of. I tried setting <cfreturn 9> in the cfc and the output window returns the
value in putUser_Result... but if I try to use "if (putUser_Result == 9)" as
the condition, the movie does not play (although the insert works).
CF_Admin
5/3/2004 10:53:39 PM
OK, I got it. I knew it had to be I was misshandling the variables returning
from CF (I'm new to ActionScript). Thanks to the one post I got too. You
reafirmed that that was the problem. I have also noticed many posts here
without any replies, and many others that got replies 3-6 MONTHS later!!!
(Allaire was far from perfect, but they kept on top of their forums, and often
the answers were from top engineers... WHAT"S UP MM!?). So thanks for posting
the help, I feel privlaged ;^).

This is what worked for me (for the top half of the client side ActionScript,
see my original post):

function putRegister() {

if (fname == null) {
Selection.setFocus("_root.fname");
message = ("first name is a required field.");

}

else if (lname == null) {
Selection.setFocus("_root.lname");
message = ("last name is a required field.");
}

else if (uname == null) {
Selection.setFocus("_root.uname");
message = ("user name is a required field.");
}

else if (email == null) {
Selection.setFocus("_root.email");
message = ("email is a required field.");
}

else if (passw == null) {
Selection.setFocus("_root.passw");
message = ("password is a required field.");
}

else if (varpassw != passw){
Selection.setFocus("_root.passw");
message = ("Passwords don't match, please re-enter passwords.");
}


else {
register.putUser(fname,lname,uname,passw,email,bio);


}

}

________________________________________________________________________________
_________

function putUser_Result(result)
{
if (result == 1)
error_message.text = "That user name is taken, please try again";
else
error_message.text = "";
loadMovie("login.swf",_root);

}

________________________________________________________________________________
____

And even though I didn't have any problems with the CF, here's that code too,
in case it might help someone:

<cfcomponent>
<cffunction name="testUser" access="remote" returntype="string">
<cfargument name="reg_mess" type="string" default="Only the field biography
is not required" />
<cfreturn reg_mess>
</cffunction>
<cffunction name="putUser" access="remote" returntype="numeric">

<cfargument name="fname" type="string" required="true" />
<cfargument name="lname" type="string" required="true" />
<cfargument name="uname" type="string" required="true" />
<cfargument name="passw" type="string" required="true" />
<cfargument name="email" type="string" required="true" />
<cfargument name="bio" type="string" default="none" />

<cfquery name="UniqueUser" datasource="poetry_users">
SELECT user_name FROM "user" WHERE user_name = '#uname#'
</cfquery>
<cfif UniqueUser.RecordCount LT 1>
<CFQUERY NAME="insertUser" Datasource="poetry_users">
INSERT INTO user
(first_name, last_name, user_name, password, email, biography)
VALUES
('#fname#', '#lname#', '#uname#', '#passw#', '#email#', '#bio#')
</CFQUERY>
<cfreturn 9>
<cfelse>
<cfreturn 1>
</cfif>

</cffunction>

</cfcomponent>
pstnotpd
5/4/2004 8:31:34 AM
Yep, that's what I meant. Maybe I should have mentioned the callback
function being needed.

And you're welcome. I do have some outstanding questions here myself
aren't likely to be answered so I agree with you.
CF_Admin
5/4/2004 2:28:09 PM
Actually, not in the code I originally posted, but in several of the versions I
had tried before, I actually had everything correct except for one thing... I
didn't understand that "(result)" was the variable, and that it contained the
returned value I needed. Once I finally understood that, it was much easier.
AddThis Social Bookmark Button