Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-24-2007, 06:27 PM   #1
pfzngn
Registered Noob
 
Join Date: Jul 2006
Posts: 6
Question Exporting to text file?

I know that taking text from an external text file and inserting it into a variable in Flash is easy peasy, like
ActionScript Code:
var externalRequest:URLRequest = new URLRequest("external.txt"); var externalLoad:URLLoader = new URLLoader(); externalLoad.load(externalRequest); externalLoad.addEventListener(Event.COMPLETE, textLoaded); function textLoaded(event:Event):void { external_txt.text = event.target.data; }

but is it possible to do the same thing, but backwards? Like sending the contents of external_txt (my variable in flash) out to external.txt (the external text file)? Or, if it isn't possible in AS, then how else could I go about saving the contents of external_txt?
pfzngn is offline   Reply With Quote
Old 06-24-2007, 07:16 PM   #2
Tink
Addict
 
Tink's Avatar
 
Join Date: Nov 2001
Location: London
Posts: 2,128
Default

you would need to use a server side language such as PHP to ope the file and write to it, the same as you had to in AS 2.0.
Tink is offline   Reply With Quote
Old 06-24-2007, 07:39 PM   #3
TomMalufe
Salmon Eater
 
TomMalufe's Avatar
 
Join Date: Jun 2007
Location: Doylestown, PA, USA.
Posts: 740
Default

sure,
Quote:
URLRequest
data : Object
An object containing data to be transmitted with the URL request.
method : String
Controls whether the HTTP form submission method is a GET or POST operation.
you need some code or script there to handle the GET or POST, but essentially you just say myURLRequest.data = new Object({sendVar:"some string you want to send with the request"})

You know now I've gone to thinking about how to save to a text file on the server. I don't really know the php you would need for that. Unless you were just going to use a database. I'm going to look that up.
TomMalufe is offline   Reply With Quote
Old 06-24-2007, 07:58 PM   #4
TomMalufe
Salmon Eater
 
TomMalufe's Avatar
 
Join Date: Jun 2007
Location: Doylestown, PA, USA.
Posts: 740
Default

This might not work flawlessly. I'm no php expert and I never tested this.

PHP Code:
$filename "external.txt";

//insert votes to txt file
$insertpost $_REQUEST['content'];
$fp fopen($filename,"w"); // "w" means write-only
fputs($fp$insertpost);
fclose($fp); 
That code should handle a URLRequest.data object with a property of {content:"something"} which could be a string or number basically.
TomMalufe is offline   Reply With Quote
Old 06-25-2007, 03:25 AM   #5
pfzngn
Registered Noob
 
Join Date: Jul 2006
Posts: 6
Default what to do...

ActionScript Code:
function myRequestPostSender():void {     var myRequest:URLRequest = new URLRequest("external.php");     myRequest.data = "This is the data I want to send";     myRequest.method = URLRequestMethod.POST;     navigateToURL(myRequest); } myRequestPostSender();
All right. I think that little bit of actionscript there should send the data out of flash and i have it pointed at external.php, which is where the php code you wrote for me is sitting. But.. I honestly have no clue about php like at all, so it doesn't surprise me that it isn't working. I think flash is doing its job, at least partly, because a new browser window keeps opening up and asking me what to do with "external.php". All the same, i don't think that's what we want it to do. What should i do to the php code to make this work?
pfzngn is offline   Reply With Quote
Old 06-25-2007, 04:28 PM   #6
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

Did you put your PHP file on a server?
__________________
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote
Old 06-25-2007, 04:36 PM   #7
TomMalufe
Salmon Eater
 
TomMalufe's Avatar
 
Join Date: Jun 2007
Location: Doylestown, PA, USA.
Posts: 740
Default

well one problem is that you are using navigateToURL(); which is used to link to another webpage, not to run code in another file.
You want to use URLLoader();
if you add the line echo "&status=OK"; to the end of the php file (all php should be within <?php "your code" ?>) then your URLLoader will have a .data property that contains the var status == "OK"; after it successfully runs the php code.
you can go to www.w3schools.com to learn about php if you want to add an if statement that will let you return OK or NOTOK or something like that.

Also, the data you send with the URLRequest.data has to be in the form of properties of an object, like var myDataObject:Object = {firstVar:"Write me to a file", secondVar:"Me Too!"} and the php that is accepting this stuff has to have code like $writeThis = $_REQUEST['firstVar'];
notice that I used the same variable name in both things.

there is no type declaration in php. $myVar could be an array, int, string, pointer to a file, whatever. the dollar ($) sign shows that it is a variable.
TomMalufe is offline   Reply With Quote
Old 06-25-2007, 05:56 PM   #8
TomMalufe
Salmon Eater
 
TomMalufe's Avatar
 
Join Date: Jun 2007
Location: Doylestown, PA, USA.
Posts: 740
Default

Oops...
You don't send variables in just any old object. you have to use
var variables:URLVariables = new URLVariables();

I knew this, but I forgot till I went back to my own project.

Last edited by TomMalufe; 06-25-2007 at 06:09 PM.
TomMalufe is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting dynamic text info to a file mambo4 ActionScript 2.0 0 03-10-2007 02:02 AM
does flex support urls being opened in it waelselo Flex 2, 3 & 4 14 12-13-2006 08:30 PM
Import text directly into Actionscript from a Text file? waynedoz ActionScript 1.0 (and below) 1 03-12-2006 01:00 AM
External text loads partially & Render text as HTML prevents loading of text file piercedwater ActionScript 2.0 20 03-02-2005 11:33 PM
Dynamic text - set up counter to swap text displayed from text file? confused1 Simple Stuff (Newbies) 2 09-17-2003 07:58 PM


All times are GMT. The time now is 09:07 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.