Page 1 of 1

PHP/Flash

Posted: Fri Dec 03, 2004 7:51 pm
by ivo.kirov
Hey guys,

I'm hoping some of you can help me with this.

My goal is to be able to email an unique url which will reference a drawing that was previously created in Flash..
the drawing itself is composed by lots of movie clips that could each be on a certain frame (2-9)..
What I'm doing at this point is an insert into the database with the frame values for those clips everytime you want to "save/email to friend" your drawing.

So for example one would be "www.url.com/script.php/unique=12343254238997"

unique's value would be the "primary key" for the drawing and will return stuff like hat=2 so in flash I just want to do load_vars.hat so I can assign that number to the hat clip's gotoAndPlay();

Now what I would ideally achieve is to be able to change unique's value.. click refresh.. and have the swf now load the new values and basically change the look of the drawing.

I have this working to a point where I can echo the database values in the browser based on my url string so thats all good
BUT
The problem is that I can't figure out how to have my swf that's going to show the drawing to load those same values with every refresh.. and not only that but it doesn't even load them initially.. so i'm looking at my monitor and seeing the echo to the browser update everytime with new values but my flash never changes.
Now I know what you're thinking.. my actionscript isn't working but get this..

if instead of doing
load_vars.load("myscript.php","_self","POST);
I do
load_vars.load("http://www.url.com/myscript.php?unique=123838483", "_self", "POST");

then it actually WORKS and loads the values for that record and displays them.


It's very confusing.. I know.. and I've been at it for a long time now so even if there's some link you have in mind that could give me an insight id really appreciate it.

Here is my actual code

by the way I'm using SQL Server NOT MySQL

PHP
----
I've only ommitted the login values from the top.. below this script is my html code that has the swf in it.

Code: Select all

$sqlconnect = odbc_connect($dsn, $username, $password); 
$primo_from_url = $_GET['snowmanID']; 
$sqlquery="SELECT * FROM ".$table." WHERE snowmanID = '".$primo_from_url."'"; 
$result = odbc_exec($sqlconnect, $sqlquery); 
while(odbc_fetch_row($result)){ 
$messagetofriend = odbc_result($result,"messagetofriend"); 
$hat = odbc_result($result,"hat"); 
$eyepiece = odbc_result($result,"eyepiece"); 
$mouth = odbc_result($result, "mouth"); 
$clothing = odbc_result($result, "clothing"); 
$hands = odbc_result($result, "hands"); 
$background = odbc_result($result, "backgroun"); 
$vars = "&hat=".$hat."&eyepiece=".$eyepiece."&mouth=".$mouth."&clothing=".$clothing."&hands=".$hands."&backgroun=".$background; 
echo $vars; 
} 
odbc_close($sqlconnect);



AS
----

Code: Select all

load_values = new LoadVars();
load_values.onLoad = function (success) {
        if (success) {
                //_root.message_txt.text = "loaded";
                //_root.message_txt.text = load_values.messagetofriend;
                _root.Hats.gotoAndPlay(load_values.hat);
                _root.Eyepiece.gotoAndPlay(load_values.eyepiece);
                _root.Mouth.gotoAndPlay(load_values.mouth);
                _root.Clothing.gotoAndPlay(load_values.clothing);
                _root.Hands.gotoAndPlay(load_values.hands);
                _root.Background.gotoAndPlay(load_values.backgroun);
        } else {
                _root.message_txt.text = "NO SUCCESS";
        }
};
load_values.load("snowman_mssql_flash.php", "_self", "POST");

Posted: Fri Dec 03, 2004 8:23 pm
by rehfeld
let me start by saying i know nothing about flash, i think i opened the program once and quickly ran and hid in a corner lol.

but

you said


if instead of doing
load_vars.load("myscript.php","_self","POST);
I do
load_vars.load("http://www.url.com/myscript.php?unique=123838483", "_self", "POST");



then why can you not just do it that way?

i know you said you want them to be able to edit the drawing if they want, and keep its new edited state if they refresh it. if thats the problem(hitting refresh reloads the initial settings), then could you do like this?

if (user has modified the settings) {
load vars based on new settings
} else {
load vars from http://www.url.com/myscript.php?unique=123838483",
}


if thats not possible, then maybe modify the php
have the php FIRST check for a cookie, and if it finds one, use the unique id in the cookie to load the db data. otherwise, use the id in the query string to load the data

and probably set the cookie using actionscript if they modify the values, or maybe even put the values in the cookie

or maybe even just build the url

http://www.url.com/myscript.php?unique=123838483"

using actionscript. determine if user has modified anything, if so, generate a new load_vars url, otherwise, use the default

like i said ive no knowledge of actionscript, so its difficult to suggest the most elegant solution.

also, i have a question. can you send data to a server in the background using actionscript? like via POST or GET etc....

Posted: Sat Dec 04, 2004 6:39 pm
by ivo.kirov
hey :)

Thanks for your effort.. I can understand clearly what you are saying but here is where the problem lies.

All I really want to achieve is to figure out how to send different values to my swf based on my url variable which is processed by php and its corresponding database values echoed.

It seems that there is some information about having to properly construct the echo string to flash and methods such as "htmlentities" "urlencode" "escape" "unescape" might come in play but nothing is really helping any or I'm just not doing it properly.

I was hoping someone might have done this before and would notice something unordinary about the way im sending the variables back to flash.

Posted: Sat Dec 04, 2004 7:39 pm
by timvw
meaby you can find inspiration at:

http://www.sephiroth.it/test/unserializer/

Posted: Sun Dec 05, 2004 9:29 am
by ivo.kirov
hmmm

I don't want to get too excited at this point but it seems like that might work.. I'll let you guys know how it worked out :)

Thanks again!

Posted: Sun Dec 05, 2004 9:33 am
by timvw
Offcourse, if you're going to do more complex thingies, this could be also itneresting:

http://www.amfphp.org/
http://ghostwire.com/resources/phpobject/

Posted: Sun Dec 05, 2004 5:24 pm
by ivo.kirov
wow

that's some pretty amazing stuff.. looks like i'll be hooked for a while :)

thank you so much.. do you actually have experience doing any of this? any thoughts?

Posted: Sun Dec 05, 2004 6:26 pm
by timvw
testing it is still on my to-do list.. when i was reading a book on flash i started playing around a little (php generates xml list of urls to images) and displaying those images then in flash........ haven't found time to dig any deeper yet :/

Posted: Sun Dec 05, 2004 7:58 pm
by ivo.kirov
Cool

Well I've decided to use it for the "send to friend" part of the project.

Using the htmlMimeEmail tutorial.. it works great and the external PHP class is amazing.

Just hope I can do both at the same time (save to database/email link with appended primary key)