Saving variables from flash?

  • 4ColorZ
  • Newbie
  • Newbie
  • 4ColorZ
  • Posts: 14

Post 3+ Months Ago

hey guys please help me out...i've been doing flash mx for a long time now and this problem has been limiting my ability to create on flash:

i know how to load variables from a text file to flash, but my problem is how to write variables from flash to a text file.

for example, if i have a textbox on flash and it contains a value like, "4" , what will i do to save that value to a text file?

i tried some tutorials but theyre too complicated...can anybody give me a simple solution.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Abelius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 260
  • Loc: Miami Beach, FL, USA

Post 3+ Months Ago

You can't write to a textfile. Only if you use it as an executable file on a CD and if you use software like Flash Studio Pro, then yes, but not like a file that will be published on the web, as an swf...

You will have to send stuff to a database, like I did with my Flash guestbook...
  • 4ColorZ
  • Newbie
  • Newbie
  • 4ColorZ
  • Posts: 14

Post 3+ Months Ago

Quote:
You will have to send stuff to a database, like I did with my Flash guestbook...


yeah, that's what i mean....so, how did you do it? can anybody give me the details? teach me pleaze.... :cry:
  • mtheory
  • Beginner
  • Beginner
  • User avatar
  • Posts: 45
  • Loc: Branford CT

Post 3+ Months Ago

You need to send the variable to a serverside script written in PHP or ASP that will create and write to a txt file.

This PHP will create txt file "file_name" and write variable.

Use loadVariable AS in Flash


<?
$fp = fopen ("$file_name", "w+");
fwrite($fp,"$variable");
fclose($fp);
?>
  • 4ColorZ
  • Newbie
  • Newbie
  • 4ColorZ
  • Posts: 14

Post 3+ Months Ago

mtheory wrote:
You need to send the variable to a serverside script written in PHP or ASP that will create and write to a txt file.

This PHP will create txt file "file_name" and write variable.

Use loadVariable AS in Flash


<?
$fp = fopen ("$file_name", "w+");
fwrite($fp,"$variable");
fclose($fp);
?>


that's it!...its just that i dont know PHP or ASP...so is this the PHP or ASP code?if it is, should i just write it on a file then use loadVariable to use it with flash? well, i'll just try it right away....thank you very much guys!!! :)

i'm still not sure if i can hack it so please keep posting your suggestions....coz i really want to learn this. thanks in advance. :)
  • 4ColorZ
  • Newbie
  • Newbie
  • 4ColorZ
  • Posts: 14

Post 3+ Months Ago

ok...i tried it but icant hack it...i'm so stupid so i need more help....if this is the php code:

<?
$fp = fopen ("$file_name", "w+");
fwrite($fp,"$variable");
fclose($fp);
?>

then what should be the flash actionscript so i can use this code?
  • alecs
  • Student
  • Student
  • User avatar
  • Posts: 79
  • Loc: Timisoara, Romania

Post 3+ Months Ago

An example:

the flash as
-------------
var="sometext";
loadVariablesNum("file.php", 0, "POST");
-------------

file.php
PHP Code: [ Select ]
 
<?
 
$var=$_POST['var'];
 
$f=fopen("file.txt","w");
 
fputs($f,$var,100);
 
fclose($f);
 
?>
  1.  
  2. <?
  3.  
  4. $var=$_POST['var'];
  5.  
  6. $f=fopen("file.txt","w");
  7.  
  8. fputs($f,$var,100);
  9.  
  10. fclose($f);
  11.  
  12. ?>


At the end you should find a new file in the folder called "file.txt" with "sometext" inside it.
  • uknightuss
  • Graduate
  • Graduate
  • uknightuss
  • Posts: 196
  • Loc: Los Angeles

Post 3+ Months Ago

Here is something helpful and relevant to your current situation:

A Good Tutorial which has Flash sending variables from a form to a server side script- http://www.kirupa.com/developer/actions ... _email.htm

This will help you go in the right direction for what you want to do, at least I think so, and it's a simple tutorial!

If you find out Like I did that your server does not support PHP Scripts, then I have a modified version of Kirupa's tutorial that uses an ASP Script instead.

In Fact, here is the ASP equivalent of Kirupa's PHP Script:
Code: [ Select ]
<%
SendEmail Request("email"), "YOU@YOURSITE.COM", "SITE FEEDBACK", Request("message")

Sub SendEmail(ByVal strFrom, ByVal strTo, ByVal strSubject, ByVal strMessage)
    Dim objMail
    Set objMail = Server.CreateObject("CDONTS.Newmail")
    objMail.From = strFrom
    objMail.To = strTo
    objMail.Subject = strSubject
    objMail.BodyFormat = 1
    objMail.MailFormat = 1
    objMail.Body = strMessage
    objMail.Send
    Set objMail = Nothing
End Sub
Response.Redirect "http://www.DOMAIN.COM/index.htm"
%>
  1. <%
  2. SendEmail Request("email"), "YOU@YOURSITE.COM", "SITE FEEDBACK", Request("message")
  3. Sub SendEmail(ByVal strFrom, ByVal strTo, ByVal strSubject, ByVal strMessage)
  4.     Dim objMail
  5.     Set objMail = Server.CreateObject("CDONTS.Newmail")
  6.     objMail.From = strFrom
  7.     objMail.To = strTo
  8.     objMail.Subject = strSubject
  9.     objMail.BodyFormat = 1
  10.     objMail.MailFormat = 1
  11.     objMail.Body = strMessage
  12.     objMail.Send
  13.     Set objMail = Nothing
  14. End Sub
  15. Response.Redirect "http://www.DOMAIN.COM/index.htm"
  16. %>



If you do want to try the ASP version of the script, then follow Kirupa's tutorial step by step, and when you get to the part where it says to add this code to a button:
Code: [ Select ]
form.loadVariables("email.php", "POST");


Just change it to:
Code: [ Select ]
form.loadVariables("email.ASP", "POST");


My friend actually wrote this ASP script as far as I know, and I really personally know nothing about it other than how to change the basic variable names. Insert your email address instead of "YOU@YOURSITE.COM", and insert a subject line for the email message where it says "SITE FEEDBACK". The one thing I know about this script though is that the PHP script didn't work on the server but This ASP script did!

The line where it says "Response.Redirect "http://www.DOMAIN.COM/index.htm", I'm really not sure about... You can/should use your own website address, but I'm not sure if that line is optional in the script or not.. In other words, can it be removed? I don't know, maybe someone will answer that one for me and you!

I hope this helps you!

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.