lot of people asked me for this, so here it is:
most important part of it is php file which will receive commands and datas from smax.
CODE
<?
/******************************************************************/
// copyright cybernetix
// http://cybernetix.t35.com
/******************************************************************/
// initiate var, which will tell to smax what is going on
$done=0;
if($action == "dump") { // erase existing content on text file and place new one
if ($fp = fopen( $datafile, "w" )) { // open data file for writing only. place the file pointer at the beginning of the file and truncate the file to zero length. if the file does not exist, attempt to create it.
fputs( $fp, $myText."\n" ); // dump text, ."\n" means - new row at the end of line, remove it if not needed
fclose( $fp ); // close data file
echo "&done=1&"; // if 1, tell to smax everything is ok
} else {
echo "&done=-1&"; // if -1 tell to smax something is wrong, can not open file
}
}
if($action == "add") { // add text to existing one
if ($fp = fopen( $datafile, "a" )) { // open data file for writing only. place the file pointer at the end of the file. if the file does not exist, attempt to create it.
fputs( $fp, $myText."\n" ); // add text, ."\n" means - new row at the end of line, remove it if not needed
fclose( $fp ); // close data file
echo "&done=1&"; // if 1, tell to smax everything is ok
} else {
echo "&done=-1&"; // if -1 tell to smax something is wrong, can not open file
}
}
if($action == "read") { // read content of file
if(filesize($datafile)>0) { // if file size is greater than 0 there is something in it
if ($fp = fopen( $datafile, "r" )) { // open data file for reading only. place the file pointer at the beginning of the file.
$theContent = fread($fp,filesize($datafile)); // read data file
fclose( $fp ); // close data file
echo "&fileContent=$theContent&"; // send variable to smax
echo "&done=1&"; // if 1, tell to smax everything is ok
} else {
echo "&done=-1&"; // if -1 tell to smax something is wrong, can not open file
}
} else {
echo "&done=-2&"; // if -2 tell to smax file is empty, nothing to read
}
}
?>
note: using echo will send variable to smax, pay attention to & (ampersend) and $ (dollar) signs.
CODE
echo "&fileContent=$theContent&";
means next: variable fileContent in smax will receive from php value of variable theContent.
var fileContent must me initiated in smax or it can be dynamic text field or vaiable in dynamic text field.
in this case it is dynamic text filed.
IMPORTANT: do not forget to chmode text data file to 777!
ok, let's see how it looks like in smax file.
there is an sprite "test" which hold all items, so it can be loaded inot swf or inserted into another swi file.
in sprite "test" there are buttons, not real one but also sprites and dynamic text field.
_root.test.dumpText
CODE
on (press) {
action="dump";
gotoAndPlay("doIt");
}
when pressed, it will send change var "action" to value "dump" and will go to frame label "doIt"
CODE
onFrame (3) {
setLabel("doIt");
// if action == dump or add
if (this.action=="dump" || this.action=="add") {
// call php file and send info what action we want, var "action" will handle that info and 'POST' will send it. in php it is var "$action".
this.loadVariables(this.phpfile,'POST');
} else if (this.action=="read") {
// call php file and send info what action we want, var "action" will handle that info. in php it is var "$action", but this time we want something back, so we shall use HTTP method 'GET' for sending variables
this.loadVariables(this.phpfile,'GET');
}
}
and finally
CODE
onFrame (12) {
if (this.done==1) { // everything is cool
gotoAndPlay("input"); // go to starting position
} else if (this.done==0) { // still working
prevFrameAndPlay(); // loop
} else if (this.done==-1) { // something is wrong, can not open file
// make some action here, depends on your application
} else if (this.done==-2) { // file is empty
gotoAndPlay("input");
// make some action here to tell user file is empty
}
}
thats all folks

you can find source files in download section
hereexample can be reviewed
:: here ::