Welcome, Guest. Please login or register.
Did you miss your activation email?
05/22/12, 18:12
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash and AS 3 (Moderators: papachan, kofi addaquay)
| | |-+  savin/loading text files
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: savin/loading text files  (Read 1425 times)
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« on: 02/22/11, 16:55 »

Hi, I'm new.

I succesfully used your saving/loading data (text) tutorials. Thank You very much!
Now, since I know how to load multiple data, I'm looking for the best way to save multiple data too. I'd like to save text incrementing Title0, Title1, Title2...
I think the best way to do it is incrementing of 1 from the .php file (in a manner like $x++;) but I'm newbie regarding PHP and AS3 too. I read a lot of topics in various forums but I don't find a solution. This is my PHP code, any help is really appreciated.:

<?php
   $nomi = $_POST['tester1'];
   $commenti = $_POST['tester2'];   
   $toSave ="Title=$nomi&Comments=$commenti";
   $fp = fopen("everything_text_file.txt", "a+");
   if(fwrite($fp, $toSave)) echo "writing=Ok";
   else echo "writing=Error";
   fclose($fp); 
?>
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #1 on: 02/22/11, 17:38 »

this realy depends on the kind of application and number of texts you want to save.

you could concatinate the textes, like it is done in the guestbook tutorial, create a XML-File, create different textfiles, or store them in a database.

The loading and saving tutorials can give you further directions.
Logged

happy flashing
Cool
Ronald
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« Reply #2 on: 02/22/11, 17:49 »

Thank you Ronald for your reply.

I just want to save text in this manner:
Title0=a&Comments0=aTitle1=b&Comments1=bTitle2=c&Comments2=c

Now I have, using a+ into the .php:
Title=a&Comments=aTitle=b&Comments=bTitle=c&Comments=c

Giving an incremental feauture to Title&Comments,
I'll be able to open the Title&Comments I want, using the "loading multiple data" tutorial.

Can you suggest me the rigt way to do it please?
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #3 on: 02/23/11, 02:47 »

It realy depends on the amount of data.

If it is relative little data, I would use XML for transport using the XML-Object:

<textblock>
<titel>your first title</title>
<comment>first comment</comment>
<titel>second title</titel>
<comment>second comment</comment>
....
</textblock>

If it is large ammounts, have a look into remoting with AMFPHP and use structured objects.

First it might look complicated, but then it is so easy.
Logged

happy flashing
Cool
Ronald
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« Reply #4 on: 02/23/11, 05:16 »

eh -  thank you Ronald  -

I was trying to use amfphp (tutorial),
but with CS5 and AS3 the code is changed
and since I'm not an expert, every change take me from 1 day to an endless time...
Logged
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« Reply #5 on: 02/23/11, 07:03 »

Sorry to bother you again,
I use flash 11.02.489 and AS3.

I'm testing in xampp the "Hello Remoting with AS3", the "remoting.fla"
but it doesn't happen anything except for an error in flash:

Error #2044: NetStatusEvent non gestito:. level=error, code=NetConnection.Call.BadVersion
   at remoting_fla::MainTimeline/frame1()

I followed the "README.txt" and moved the files in the right places.
What must I do more?
Import some flash.net class?
and I can't find the file "person.txt" in the folders.

Thank you.
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #6 on: 02/23/11, 09:00 »

can you open the amfphp browser?
what do you receive, if you enter the name of the php file into the browser?
did you install charles?

what does charles say?
Logged

happy flashing
Cool
Ronald
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« Reply #7 on: 02/23/11, 09:49 »

this seems to be the error in charles (saving and loading):

Parse error: syntax error, unexpected '}' in /Applications/XAMPP/xamppfiles/htdocs/amfphp/services/SimplePerson.php on line 9

amfphp seems to be ok, I can open the browser,
if I enter the name of the php file into the browser,
I can see the service browser tree, then clicking on Simple Person I get the same above error,
clicking instead on TestPerson I get "Invalid AMF message" or:

Error retrieving service info:
Function eregi_replace() is deprecated
/Applications/XAMPP/xamppfiles/htdocs/amfphp/core/shared/util/MethodTable.php on line 505

Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #8 on: 02/23/11, 12:50 »

This message is clear and true.

Load the SimplePerson.php into the editor of your choice and make sure, all opening brackets have a closing bracket - and theat you have no closing without opening Wink

This is a very common error, happening to the best programmers Wink

Replace ereg_replace with preg_replace.

ereg_replace was valid until php4 - but you seam to have php5 installed.
There is the new function preg_replace replacing ereg_replace.
« Last Edit: 02/23/11, 12:52 by Ronald Wernecke » Logged

happy flashing
Cool
Ronald
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« Reply #9 on: 02/23/11, 13:22 »

sorry,

but where is the place where I must replace ereg_replace with preg_replace?

This is the code of SimplePerson.php, everything seems to be correct, I didn't make any change:

<?php
class SimplePerson {
   function getPerson() {      
      $fp = fopen("person.txt", "r");
      $contents = fread($fp, filesize("person.txt"));
      fclose($fp);
      $data = explode("|", $contents);
      return $data
   }
   function savePerson($name, $age, $address){
      $contents = "$name|$age|$address";
        $fp = fopen("person.txt", "w");
      if(fwrite($fp, $contents)){
         fclose($fp);
         return "Data saved";
      };
      return "Error writing data";
   }
}
?>

Thanks....

Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #10 on: 02/23/11, 13:40 »

The problematic code is here:

MethodTable.php on line 505

Logged

happy flashing
Cool
Ronald
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« Reply #11 on: 02/23/11, 15:56 »

Hi Ronald, yes I've php 5.

I replaced line 505 and 507 with preg_...
but I continue to have errors:

from SimplePerson:
Error retrieving service info:

Invalid AMF message

Parse error: syntax error, unexpected '}' in /Applications/XAMPP/xamppfiles/htdocs/Files/simpleExample/amfphp/services/SimplePerson.php on line 9

from TestPerson:
Error retrieving service info:

preg_replace(): Unknown modifier '+'
/Applications/XAMPP/xamppfiles/htdocs/Files/simpleExample/amfphp/core/shared/util/MethodTable.php on line 505


and from Flash:
Error opening URL 'http://localhost/Files/simpleExample/amfphp/gateway.php'
Error #2044: NetStatusEvent non gestito:. level=error, code=NetConnection.Call.Failed
   at remoting_fla::MainTimeline/frame1()


Don't know what I can do...
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #12 on: 02/23/11, 16:30 »

you still have a problem with curly brackets - they must be used as pairs

your preg_replace has an ilegal plus sign (download the current php manual, to read the syntax of the commands)

At the end the call fails, because of these errors
Logged

happy flashing
Cool
Ronald
lasmiveni
Server what's that
*
Posts: 20


View Profile Email
« Reply #13 on: 02/24/11, 10:27 »

Yes, they seams to be the problems.

Did anybody, reading this topic, run in the same issue with tutorial "Hello Remoting with AS3"
and flash 11.X...and knows how to modify the PHP files inside?
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #14 on: 02/24/11, 12:37 »

In line 8 in the simple person class is a semicolon missing.
Logged

happy flashing
Cool
Ronald
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!