High Score Table: Writing a Simple Text File with Flash and PHP

I am having a problem getting Flash to work with PHP as I need Flash to read and write to a text file on a server to store simple name/score data for a games hi score table. I can read from the text file into Flash easily enough but also need to write to the file when a new high score is reached, so I need to use PHP to do that. I can send the data from flash to the php file via POST but so far it is not working. The PHP file is confirmed as working as I added an echo to the file which displayed a message so I  could check that the server was running PHP - the files were also uploaded to a remote server so I  could test them properly. Flash code is as follows:
//php filewriter
var myLV = new LoadVars();
function sendData() {
//sets up variable 'hsdata' to send to php
myLV.hsdata = myText;
myLV.send("hiscores.php");
I believe this sends the variable 'myText' to the php file as a variable called 'hsdata' which I want the php file to write into a text file. The mytext variable is just a long string that has all the scores and names in the hiscore. OK, XML would be better way of doing this but for speed I just want to get basic functionality working, so storing a simple text sting is adequate for now. The PHP code that reads the Flash 'hsdata' variable and writes it to the text file 'scores.txt' follows:
<?php
//assigns to variable the data POSTed from flash
$flashdata = $_POST["hsdata"];
//file handler opens file and erases all contents with w arg
$fh = fopen("scores.txt","w");
//adds data to file
fwrite ($fh,$flashdata);
//closes file
fclose ($fh);
echo 'php file is working';
?>
Any help with this would be greatly appreciated - once I can get php to write simple text files I should be ok. Thanks.

Thanks for your help.
I have got Flash working to a certain extent with PHP using loadVars but have been unable to get flash to receive a variable declared in PHP. Here's my Flash code:
var outLV = new LoadVars();
var inLV = new LoadVars();
function sendData() {
outLV.hsdata = "Hello from Flash";
outLV.sendAndLoad("http://www.mysite.com/hiscores/test23.php",inLV,"post");
inLV.onLoad = function(success) {
if (success) {
  //sets dynamic text box to show variable sent from php
  statusTxt.text = phpmess;
} else {
  statusTxt.text = "No Data Received";
This works ok and the inLV.onLoad function reports that it is receiving data but does not display the variable received from PHP. The PHP file is like this:
<?php
$mytxt =$_POST['hsdata'];
$myfile = "test23.txt";
$fh = fopen($myfile,'w');
//adds data to file
fwrite($fh, $mytxt);
//closes file
fclose ($fh);
$mess = "hello there from php";
echo ("&phpmess=$mess&");
?>
The PHP file is correctly receiving the hsdata from flash and writing it to a text file, but there seems to be a problem with the final part of the code which is intended to send a variable called 'phpmess' back to Flash, this is the string "hello there from php". How do I set up Flash and PHP so that PHP can send a variable back to Flash using echo? Really have tried everything but am totally baffled. Online tutorials have given numerous different syntax configurations for how the PHP file should be written which has really confused me - any help would be greatly appreciated.

Similar Messages

  • Loading text file with flash lite 3.0 problem

    Hello,
    I recently ran into a problem with loading a plain text file with Flash Lite 3.0.
    I know there is a way to load name/value pairs using LoadVars class or XML file using XML class. Both methods work great, but these classes parse the data loaded and I need to load just a plain text - no pairs or xml structure. (its because Im loading specific file format, so I can't make any changes to it)
    There is a simple way how to achieve this in Flash using Actionscript 2 by extending the LoadVars class and overriding the onData() method. I used it plenty of times and it works fine.
    There is an example of implementation:
    // the PlainData.as file
    class PlainData extends LoadVars {
        function onData(str) {
            trace(str)
            this.onLoad(true);
    // now in the main file
    var my_data:PlainData = new PlainData();
    my_data.load("my3dmodel.obj");
    This code traces unchanged content of my3dmodel.obj file.
    The problem comes when I try to run this code using Flash Lite 3.0. The code stops working just by changing player version in publish settings to Flash Lite 3.0. It doesnt display any error, but also doesnt trace any content.
    Is there a reason why you cant override onData method in LoadVars class in lite version of flash or am I doing something wrong?
    (also overriding onLoad() method works fine in Flash Lite)
    Ondrej

    Thanks Man
    But i m very unhappy !!! :-(
    1M data to transfer my mp3 files is very small !!! hehehe
    Thanks a lot
    See ya
    Carlos Eduardo Burko - Curitiba - Brazil - Macromedia
    Certified Professional
    "biskero" <[email protected]> escreveu na
    mensagem
    news:e98nrb$a6e$[email protected]..
    > Ciao Carlos,
    >
    > yes you can load mp3. The only issue is that the FL2
    will need to load the
    > entire mp3 in memory which mean you are limited to the
    avalable memory and
    > also
    > there is a limitation of 1M data transfer.
    > Try to create a sample application to test it. You need
    to use the
    > loadSound
    > API.
    >
    > Alessandro
    >

  • Creating links to text files with Tomcat and JSP

    I am trying to create links in a JSP page that bring up text files. Currently, the links point to a file format. When the links are clicked, however, the text files are not displayed in the web browser. When an "http:" format is used, the links point to terminal files that are not being written dynamically (and therefore are useless to me). So in short, I'm looking for a way to get these links to (1) point to text files on the network, and (2) get them to display in a new browser window. Any help or guidance will be greatly appreciated.
    Thanks.
    TGD

    You cannot expect Tomcat or any J2EE Server to give access to the Network files.
    You need to design a different way to give access to the Users.
    What you can do is write a proxy (HttpServlet) which can pass a request parameter as the file name. The Servlet can read the file and then paint it in the Client Browser Window.
    Hope this helps.
    Thanks and regards,
    Pazhanikanthan. P

  • IE10 blocks local files with flash and java content

    Hello,
    we have imported the Microsoft Security Compliance Policys for IE10.
    Now we have unfortunately
    found that, IE is blocking content on the for the "local computer".
    We have installed some software which calls a index.html with some flash and java content, but nothing gets displayed. We`ve already enabled the setting "active content to run in files on my computer", but that doesnt help.
    I have copied the files on a file server which is member in the local intranet sites, an there everything is working perfect. My question is, how can I find out which setting is causing that?
    Hope somebody have a clue.

    Hi,
    Are we using the SCM (Microsoft Security Compliance Manager ) tool here?
    If we have any issue regarding SCM, we might consider seek help in the following forum:
    http://social.technet.microsoft.com/Forums/en-us/home?forum=compliancemanagement
    For Internet Explorer 10 is blocking the page content, please follow Rob's suggestions, consider use F12 debuger to check, and here is some information regarding F12 tool usage:
    How to use F12 Developer Tools to Debug your Webpages
    Best regards
    Michael Shao
    TechNet Community Support

  • Importing WORD text files with formatting and Text Flow issues IDCS3

    I am a designer who has used ID since it first came out, but have not been utilizing the larger document capabilities lately as I've been working in large format graphics (like really large, so if you have questions on that I can answer!). I am working on a new magazine and the copy is in WORD. I want to know the best way to bring in the text and keep the italic and bold formatting. The WORD docs have no style format done by the writers, so therefore changing the styles to my styles in the custom import section doesn't work. I tried making a character style sheet with no font chosen just "italics", but didn't work. I still was unable to make a paragraph style on top of it.
    If anyone has a good methodology for bringing in WORD text and keeping it's attributes while applying ID style sheets please help!
    Also with text flow, I have always had an issue with ID with not creating more pages to keep the flow going. In a test I just did I placed the text, but it did not create any new pages. I know there's a way to make that work, but spell it out for me like I'm a person losing their mind which seems to be the case!
    Thank you in advance to the person who can give me advice!

    What for settings do you have on the importoptions when bringing in Word? Keep formatting or loose formatting? And if loose formatting: is Keep local formatting on or off?

  • High scores table without name repeat

    Hello there,
    I have some code which fills a high scores table.. we've decided to give away a prize to the top ten people in the high scores table.. the problem is that people are playing repeatedly and fillnig the high scores table with their name, this makes it unfair to other players as they can't manage to get onto the table !!
    Is there a way I can modify my code to ignore the same name should it appear and skip to the next non repeated name(pseudo) and score ??
    My text boxes are called pseudo1 - pseudo10 and score1 - score10
    Many thanks in advance for your help below is my code :-
    for (var p:uint = 1; p <= 10; p++) {
              var currentPseudo:String = "pseudo" + p;
              var currentScore:String = "score" + p;
              if (event.target.data["pseudo" + p]) {
                   highScoresPage[currentPseudo].appendText(event.target.data["pseudo"+p]);
              if (event.target.data["score" + p]) {
                   highScoresPage[currentScore].appendText(event.target.data["score"+p] + " points"/*/1000 + "s"*/);
              } else {
                   highScoresPage[currentPseudo].appendText(" \n");
                   highScoresPage[currentScore].appendText(" \n");

    I find using Dictionary class for filtering unique names very useful. The code below shows that. Note how array is sorted in descending order:
    var scores:Array = [];
    scores.push( { name: "Peter Smith", score: 32 } );
    scores.push( { name: "Amanda Smith", score: 112 } );
    scores.push( { name: "Peter Smith", score: 23 } );
    scores.push( { name: "Jerry Pak", score: 45 } );
    scores.push( { name: "Peter Smith", score: 80 } );
    scores.push( { name: "Martin", score: 78 } );
    scores.push( { name: "Andrei", score: 99 } );
    scores.push( { name: "Andrei", score: 65 } );
    scores.push( { name: "Martin", score: 76 } );
    scores.push( { name: "Amanda", score: 10 } );
    scores.push( { name: "Peter Smith", score: 73 } );
    // this sorting assures that only highest score for the same name will be presented
    // default sort is ascending
    scores.sortOn("score", Array.NUMERIC);
    var uniquePlayers:Dictionary = new Dictionary();
    // this creates unqie entries
    for each(var obj:Object in scores) {
         // each element is entered only once
         uniquePlayers[obj.name] = obj;
    // reset array
    scores = [];
    // populate with unique names
    for (var key:String in uniquePlayers) {
         scores.push(uniquePlayers[key]);
    scores.sortOn("score", Array.NUMERIC | Array.DESCENDING);
    for each(obj in scores) {
         trace(obj.name, obj.score);

  • How to generate a text file with values from internal table

    hi,
    can anybody help me out to get the values from different internal table written into a text file.
    regs,
    raja

    used gui_download,ws_download,cl_gui_file_save.
    data: ld_filename type string ;
    ld_filename = 'c:\demo.txt'.
    DATA: begin of it_datatab occurs 0,
    row(500) type c,
    end of it_datatab.
    HII
    call function 'GUI_DOWNLOAD'
    exporting
    filename = ld_filename
    filetype = 'ASC'
    tables
    data_tab = it_datatab[]
    exceptions
    file_open_error = 1
    file_write_error = 2
    others = 3.
    gui_download

  • Cannot print a simple Text File

    Hello All,
    I wrote the following program
    import java.io.*;
    import java.awt.print.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    public class TestPrint
         public static void main(String[] args) throws Exception
              FileInputStream fis = new FileInputStream(new File("pds.txt"));
              byte[] fileByte = new byte[34];
              int read = 0;
              int counter = 0;
              while((read = fis.read()) != -1)
                   fileByte[counter++] = (byte)read;
              PrintService services[] = PrinterJob.lookupPrintServices();
              DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
              PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
              aset.add(MediaSizeName.ISO_A4);
              aset.add(new Copies(1));
              Doc doc = new SimpleDoc(fileByte, flavor, null);
              DocPrintJob pj = services[0].createPrintJob();
              pj.print(doc, aset);
    }The file I am trying to print is a simple text file. My requirement is to convert it to an array of bytes and then print it.
    However I get the exception
    Exception in thread "main" java.lang.IllegalArgumentException: data is not of de
    clared type
    at javax.print.SimpleDoc.<init>(Unknown Source)
    at TestPrint.main(TestPrint.java:25)
    Please help me. I would appriciate any help in this matter.
    regards,
    Abhishek.
    PS: The contents of the file (pds.txt) which I am trying to print is
    PDS
    pds
    pds
    pds
    pds

    Hi,
    you get a java.lang.IllegalArgumentException in line 25:
    So we take the Java API for SimpleDoc:
    IllegalArgumentException - if flavor or printData is null, or the printData does not correspond to the specified doc flavor--for example, the data is not of the type specified as the representation in the DocFlavor.
    Since fileByte seems not the be null, the type must be wrong!
    In line 21 we see:
    DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
    so fileByte must be type java.io.InputStream, which it isn�t. This causes your IllegalArgumentException.
    So try in line 21:
    DocFlavor flavor = DocFlavor.BYTE_ARRAY.TEXT_PLAIN_US_ASCII;
    Let me know if that was the reason!
    Best regards
    Martin

  • Writing or modifying text files in java

    Dear all,
    I have the next text file:
    goods: 5
    bids: 4
    % num, price, good, good, ..., good, #
    0 2075 1 4 #
    1 3000 1 2 3 4 #
    2 520 3 #
    3 3000 2 3 4 #
    I have to modify or create the file above, using output data from one java program. For example, The output of my java program in the next execution is:
    goods: 8
    and price (0) changes from 2075 to 2078.
    so, using this output data my java program should write (create or modify) the next text file with the changes:
    goods: 8
    bids: 4
    % num, price, good, good, ..., good, #
    0 2078 1 4 #
    1 3000 1 2 3 4 #
    2 520 3 #
    3 3000 2 3 4 #
    I have tried using: output.write( objetc );
    but it doesn't work as I need :( .
    Somebody can help me or give me some idea?
    Thanks,
    Andrea

    This is the code:
    File testFile = new File("D:\\result1.txt");
    setContents(testFile, " bla bla bla (few characters) ");
    static public void setContents(File aFile, String aContents)
    throws FileNotFoundException, IOException {
    try {
    //use buffering
    output = new BufferedWriter( new FileWriter(aFile) );
    output.write( aContents );
    finally {
    //flush and close both "output" and its underlying FileWriter
    if (output != null) output.close();
    I mean, this code dont work because it let me write few characters only. I need to write the whole file:
    goods: 8
    bids: 4
    % num, price, good, good, ..., good, #
    0 2078 1 4 #
    1 3000 1 2 3 4 #
    2 520 3 #
    3 3000 2 3 4 #
    with the special characters as (#).
    Sorry, if it post is not clear.
    Thanks.

  • Extract text file with HTML tags from JTextPane

    hello world
    I have a big problem !
    I am creating an applet with a JTextPane ...
    so I can write text, (bold, italic etc), i can insert images.
    Now i want to create a text file with all the HTML tags
    corresponding to what I wrote in my JTextPane.
    I want to have and save the HTML file corresponding to what i wrote ...
    Is it possible ? Help me please ....
    Jeremie

    writing to a file from an applet is going to take a fair amount of work on your part.
    in order to write to a file from your applet, you have to use servlets or jsp to write to a file on your server. if you wish to write locally, look into signing your applet or policy settings of your browser.
    for writing to a file to the server, i suggest you look into servlets and tomcat to run the servlets.
    i just finished a project that used servlets and they take some time to figure out, but its definitely worth your time.
    here are some websites...
    http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html
    http://jakarta.apache.org
    other websites have tutorials that you can look at too
    Andy

  • Reading dilimited input from a text file with tokenizer

    i am trying to read in a text file with the following structure: 2 integers on each line with comma as the delimitor.
    i am using the BufferedReader stream and Tokenizer to detect ",".
    try {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    //read in the data file
    while ((s = in.readLine())!= null) {
    int i = 0;
    for (i = 0; i < 100; i++) {
    t = new StringTokenizer(s,",");
    A1 = Integer.parseInt(t.nextToken());
    catch (IOException e) {System.err.println(e);}
    When i print out A1[i], it only reads the last line of the text file. Please tell me what's wrong.
    Also i'd really like A1[i] to store the integer before the comma and another array A2[i] to store the integer after the comma. Please help.
    Thanks.
    p.s. A1 and A2 are arrays...when i previewd message in Netscape 7 it left out the brackets and the index....

    What is the for i loop for? If it is to read the next line from the file, then the while loop has taken care of it. Other than this there should be no problem with the rest of the code.
    Just add another line to store the next token into A2.

  • Importing text file (with file names) into Automator.. is it possible?

    Hello all,
    I have been working with Windows Batch files for my line of work. I have a couple of file names in a text file (a column), which I want to copy from one folder of one hdd to another folder on a different hdd. I have been trying to do this kind of work with a Mac. I already know how you copy and rename files in automator (which isn't difficult, of course) but you have to 'select' the files in the finder first (with get specified items).
    But the only way i see that you can specify items is by selecting them... is there a way to import a text file with all the file names instead of selecting all the file names manually?
    or is there an AppleScript alternative which I can use to import the text file (or just copy into applescript) and run before the query's of copying and renaming the files? I am kind of new to Apple programming.
    The text file looks like this:
    image1.jpg
    image2.jpg
    etc..
    so there has to be a command to: 'goto' a specific folder as well.
    Thanks in advance!

    You can import text files, but if they are just names you will need an additional action to add the source folder path. A *Run AppleScript* action can be used, for example:
    Tested workflow:
    1) *Ask for Finder Items* {Type: files } -- choose the text file containing the names
    2) *Combine Text Files* -- this gets the text file contents
    3) *Filter Paragraphs* { return paragraphs that are not empty } -- skip blank lines
    4) *Run AppleScript* -- copy and paste the following script:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 680; height: 340px;
    color: #000000;
    background-color: #FFEE80;
    overflow: auto;"
    title="this text can be pasted into an Automator 'Run AppleScript' action">
    on run {input, parameters} -- add folder path
    add the specified folder path to a list of file names
    input: a list of text items (the file names)
    output: a list of file paths (aliases)
    set output to {}
    set SkippedItems to {} -- this will be a list of skipped items (errors)
    set SourceFolder to (choose folder with prompt "Choose the folder containing the file names") as text -- this is the folder containing the names
    repeat with AnItem in the input -- step through each name in the input
    try
    set AnItem to SourceFolder & AnItem -- add the prefix
    set the end of the output to (AnItem as alias) -- test
    on error number ErrorNumber -- oops
    set ErrorNumber to ("  (" & ErrorNumber as text) & ")" -- add the specific error number
    set the end of SkippedItems to (AnItem as text) & ErrorNumber
    end try
    end repeat
    ShowSkippedAlert for SkippedItems
    return the output -- pass the result(s) to the next action
    end run
    to ShowSkippedAlert for SkippedItems
    show an alert dialog for any items skipped, with the option to cancel the workflow
    parameters - SkippedItems [list]: the items skipped
    returns nothing
    if SkippedItems is not {} then
    set {AlertText, TheCount} to {"Error with AppleScript action", count SkippedItems}
    if TheCount is greater than 1 then
    set theMessage to (TheCount as text) & space & " items were skipped:"
    else
    set theMessage to "1 " & " item was skipped:"
    end if
    set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
    set {SkippedItems, AppleScript's text item delimiters} to {SkippedItems as text, TempTID}
    if button returned of (display alert AlertText message (theMessage & return & SkippedItems) ¬
    alternate button "Cancel" default button "OK") is "Cancel" then error number -128
    end if
    return
    end ShowSkippedAlert
    </pre>
    5) *Copy Finder Items* { To: _your external drive_ }

  • Importing text file with variable spaces

    Hi all
    I have a text file with a varying amount of spaces in it. Typical output from the file is attached.
    How can I separate the values into separate columns please?
    Thanks in advance.

    You're going to need some substrings:
    DECLARE @flatFileLine VARCHAR(MAX) = '2002 01118511 0.00 0 0.00 0.00 PENDING '
    SELECT
    SUBSTRING(@flatFileLine,1,4),SUBSTRING(@flatFileLine,5,17),SUBSTRING(@flatFileLine,22,17),SUBSTRING(@flatFileLine,39,17),SUBSTRING(@flatFileLine,56,17),SUBSTRING(@flatFileLine,73,17),SUBSTRING(@flatFileLine,90,17)

  • How copy just line in text file with cat? (SOLVED)

    Hi.
    How i make to copy just only line in text file with cat?
    For example:
    [:0.0]
    file=/home/Arch/./.wallpaper.png
    mode=0
    bgcolor=# 0 0 0
    I want copy just "/home/Arch/./.wallpaper.png" part.
    Actually i want create a shortcut for last wallpaper set from Nitroget, then i put this in SLim background.
    Recently i use hsetroot for wallpaper (~/.wallpaper.png) and i create a shortcut in /usr/share/slim/theme/MYTHEME whith ln -s ~/.wallpaper.png /usr/share/slim/theme/MYTHEME/background.png.
    I want make a same with Nitrogen.
    I now this looks like crazy, but...
    Sorry my English.
    Last edited by kramerxiita (2008-06-04 16:50:48)

    moljac024 wrote:
    kramerxiita wrote:
    moljac024 wrote:How can you make SliM change the background ? You link the theme background to another file ?
    Yes. In theme directory i put background.png shortcut for my wallpaper. So, when a change wallpaper, slim background change too.
    Example:
    ln -s mywallpaper.png /usr/share/slim/themes/default/background.png
    So, Slim background always is my wallpaper.
    So the wallpaper has to be a *.png ?
    No, jpg is possible. But when you create a symbolic link, remember put the extension too. If change png to jpg, change a symbolic link extension.
    But, remember if slim theme directory have background.png and background.jpg, Slim always choice .png. So, put only one this.

  • How to print a text file with pagebreak.......

    hi to all,
    i am new in java and i want to do print a text file with page break. that text file is converted from html view page with help of htmlconveter class and i want to set page break in the text file.ASCII 12 is not work properly.its not break a page in proper manner.plz reply soon.

    hi to all,
    i am new in java and i want to do print a text file with page break. that text file is converted from html view page with help of htmlconveter class and i want to set page break in the text file.ASCII 12 is not work properly.its not break a page in proper manner.plz reply soon.

Maybe you are looking for