Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Managing Text Files, with smax and php
cybernetix
post Nov 2 2004, 02:53 PM
Post #1


ReloadeD
Group Icon
Group: Honored
Posts: 562
Joined: 20-May 04
From: Belgrade, Serbia
Member No.: 17





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 bigwink.gif



you can find source files in download section here

example can be reviewed :: here ::
 
+Quote Post  Go to the top of the page
cmonney
post Jun 9 2005, 09:51 AM
Post #2


~ Soul Rebel ~
Group Icon
Group: Main Team*
Posts: 3,625
Joined: 18-May 04
From: a mind-altering psychedelic trip
Member No.: 3





thanks "Agent"!

Tip-Hat.gif
 
+Quote Post  Go to the top of the page
*D*
post Jul 14 2005, 01:40 PM
Post #3


Merry KissMoose
Group Icon
Group: Main Team
Posts: 15,990
Joined: 18-May 04
From: North Pole
Member No.: 2





url is repaired for those wishing to see working version of this tut flowers.gif
 
+Quote Post  Go to the top of the page
chimera
post Sep 23 2005, 03:08 AM
Post #4


New Member
Group Icon
Group: Member
Posts: 1
Joined: 8-September 05
Member No.: 6,786



i can's find the source files in download section
from this link
http://www.13dots.com/forum/index.php?download=547
Sad.gif Sad.gif Sad.gif
where are they?
10x
 
+Quote Post  Go to the top of the page
acmestudio
post Oct 10 2005, 08:13 AM
Post #5


New Member
Group Icon
Group: Member
Posts: 1
Joined: 10-October 05
Member No.: 7,454





I cannot download source files? Please help me!
 
+Quote Post  Go to the top of the page
Phyrriz
post Oct 10 2005, 11:39 AM
Post #6


Banned for Ripping
****
Group: Banned
Posts: 358
Joined: 8-October 05
From: Sundsvall
Member No.: 7,416





Nice one. Wished my C++ beginner tutorial got some feedback too .. But no no!
 
+Quote Post  Go to the top of the page
matteh
post Dec 21 2005, 03:53 AM
Post #7


New Member
Group Icon
Group: Member
Posts: 3
Joined: 21-December 05
Member No.: 8,686





HELPPP! link doesnt work >:[
 
+Quote Post  Go to the top of the page
omer24
post Dec 22 2005, 02:58 PM
Post #8


Getting Used To The Dots
Group Icon
Group: Member
Posts: 30
Joined: 19-October 05
From: Tel Aviv, Israel
Member No.: 7,656





great tutorial, helps a lot. why the example isn't working?
 
+Quote Post  Go to the top of the page
Faakher
post Dec 28 2005, 03:41 AM
Post #9


Regular Dot
Group Icon
Group: Member
Posts: 57
Joined: 28-December 05
Member No.: 8,750





Thanks Agent Dear
its a Realy Grat Sharing Brother.........

Faakher
 
+Quote Post  Go to the top of the page
cronotec
post Nov 12 2007, 08:57 PM
Post #10


New Member
Group Icon
Group: Member
Posts: 1
Joined: 12-November 07
Member No.: 18,283





QUOTE(cybernetix @ Nov 2 2004, 02:53 PM) [snapback]16757[/snapback]
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 neededfclose( $fp ); // close data fileecho "&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 neededfclose( $fp ); // close data fileecho "&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 itif ($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 filefclose( $fp ); // close data fileecho "&fileContent=$theContent&"; // send variable to smaxecho "&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 addif (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 variablesthis.loadVariables(this.phpfile,'GET');}}
and finally
CODE
onFrame (12) {if (this.done==1) { // everything is coolgotoAndPlay("input"); // go to starting position} else if (this.done==0) { // still workingprevFrameAndPlay(); // 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 emptygotoAndPlay("input"); // make some action here to tell user file is empty}}
thats all folks bigwink.gif you can find source files in download section hereexample can be reviewed :: here ::
Can you fix the link, it don't works... Thanks
 
+Quote Post  Go to the top of the page

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 29th July 2010 - 11:06 PM
Cheap Books | Package Holidays | Home Insurance | ADHD Coaches | Adsense Paying Keywords