PDA

View Full Version : When to output data from php in Flash


snapple
07-23-2004, 02:32 PM
Hello,

I have been filling the hours of my recent days with a drawing application i am building. I would really appreciate someone who has a better grasp [than me] on Flash > php matters to point out to me why the following is not working.

The application already sends and loads loads of data to and from MySQL, but for some reason (and i have tried to battle it out) - the following variables are not showing in Flash.

My Actionscript is as follows:


_root["userCoord||"+g].onRelease = function ()
{
image_lv = new LoadVars();
image_lvBack = new LoadVars();
image_lv.varName = getUser(this._name, storeNames);
image_lv.myNamesX = myNamesX;
image_lv.onLoad = function (checkPlease)
{
if(checkPlease)
{
//trace("loadVars worked");
}
}
image_lv.sendAndLoad("http://localhost/genDraw_x.php", image_lvBack, "POST");
//trace(image_lvBack.varName);
}
myHeight +=18;
}
}


What i would like to do is send the variable 'varName' to php, this then tells php which row of data to pull from the database. My php is as follows:



$varName = $_POST['varName'];
$myNamesX = $_POST['myNamesX'];

$tmpStrX = "";

$resData = mysql_db_query ("images","SELECT draw_x, FROM draw WHERE draw_name = '$varName'");

while ($entry = mysql_fetch_array ($resData))
{
$tmpStrX = $tmpStrX . $entry["draw_x"] . ",";

}

mysql_free_result($resData);

print "varName = $varName";
print "myNamesX = $tmpStrX";

?>


I have about 7 other variables but i have just left them out for ease of reading. varName needs to be sent to Flash and interpreted, where as all i need to do for myNamesX is load the x_coordinates from the database.

What i don't understand, is when or how to definitely recognise when Flash can seperatley load in variables from a php file, whilst sending them, or when to call them in flash. I am very annoyed with myself, because i have successfully, inserted all the data into the db, successfully, brought back data from the database, put it into arrays etc, etc - but this crucial part is messing me around.

Many, many thanks for any help. I have been working on this non stop for quite a while now and thought i had Flash > php > Flash vars sorted..perhaps not.

Thank you very much in advance. Regards, snapple :)

CyanBlue
07-23-2004, 02:52 PM
Howdy... :)

I am not sure how much I can help, but I am just trying to be nice here... :D

Okay... Here is my question... I see that you are sending out varName and myNamesX from the Flash and your PHP returns those variables back to image_lvBack in Flash...
What do you see when you do this??? Can you do the copy and paste???

image_lvBack.onLoad = function ()
{
trace(unescape(this));
}

(I am assuming that the PHP returns the data fine, right???)

snapple
07-23-2004, 03:06 PM
ahhhh - trying to be nice = very very helpful! I got the data for each user back into flash, thanks - let me just examine whats happening a little closer.

Massive thanks CyanBlue, excellent!

Best regards, snapple :)

CyanBlue
07-23-2004, 03:09 PM
Um... What did I do??? :confused:
I just said use the darn trace() function... That's all... :D

But, seriously... I don't really see anything wrong in the script... (I've got to admit that I am really bad at reading other people's code...) Let me know what and where the problem is... :)

snapple
07-23-2004, 03:09 PM
Sorry - i see this when i click on a button for a user:

varName = snapplemyNamesX = 473.95,506.95,523.95,myNamesY = 465.95,294,445.95,myNamesAlpha = ,100,100,100,myNamesColour = 6710886,6710886,6710886,myNamesThick = ,20,20,20,&onLoad=[type Function]

So - i still dont understand why my variables weren't getting back to flash, or was it just because i could not see them? Because what i need to do now is get that data into 6 arrays.

Rgeards, snapple :)

CyanBlue
07-23-2004, 03:11 PM
Oh... Oh... I know what you are missing, I think... :)

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

:D

print "varName = $varName";
print "&";
print "myNamesX = $tmpStrX";

snapple
07-23-2004, 03:23 PM
Right ok - so do i put the '&' there because the varName i am sending into php from flash and the others i am just loading into flash?

If i click on a user button i get:

myNamesX = 488.95,573.95,550.95, myNamesY = 463.95,327,443.95, myNamesAlpha = ,100,100,100, myNamesColour = 6710886,6710886,6710886, myNamesThick = ,20,20,20,&varName = Andy&onLoad=[type Function]

How come varName is being echoed like that? I really (as always) appreciate your help, thank you for taking the time.

Regards, snapple :)

CyanBlue
07-23-2004, 03:25 PM
Um... I might need some more coffee... :D
You do need to get rid of extra spaces between the = signs as well...

print "varName=$varName";
print "&";
print "myNamesX=$tmpStrX";


How come varName is being echoed like that?

What do you mean by that 'like that'???

snapple
07-23-2004, 03:32 PM
Sorry, like this: &varName = Starbucks&onLoad=[type Function]

I just need to sit and think for a little bit. How would i access those variables now then? Because earlier on in this project, i have (working fine):


getNames_lv = new LoadVars();
getNames_lv.load("http://localhost/genName.php");
getNames_lv.onLoad = function (worked)
{
if(worked)
{
outPut();
}
}
function outPut ()
{
storeNames = getNames_lv.myNames.split(",");
}


But i don't seem to be able to do this with the current (first) example. Don't sweat it, if its late or you're tired, this is not for anyone - just a personal project for 'fun'.

Regards, Sam :)

CyanBlue
07-23-2004, 03:39 PM
Sorry, like this: &varName = Starbucks&onLoad=[type Function]

Um... I still am not quite getting it, but if you are specifically talking about onLoad=[type Function] part, that's because you asked Flash to trace out whatever is in that LoadVars() instance and it contains the onLoad handler so that gets traced out as well...

I don't know why the same approach is not working on this case, but keep posting... I might not be able to help you much, but explaining your problem at the form helps you solve the problem quicker... At least that's what I do... I squeeze my brain and gets stuck after spending several hours and searching the forum do not help me, so I post the question and I read it again before I press Post button... Then I understand where my problem is... That happened quite a few times... :)

snapple
07-23-2004, 04:41 PM
Solved - cheers mate. Much appreciated. When you get to 230 lines of Actionscript in one frame and 3 php files - you know its a big one!

Thank you for your time and effort.

Best regards, snapple :)

CyanBlue
07-23-2004, 05:25 PM
Sounds great... Good... :)