Welcome, Guest
  • Author Topic: Saving "button pressed" data to outside source  (Read 744 times)

    mike

    • Server what's that
    • *
    • Posts: 6
      • View Profile
      • Email
    I am working on a program in flash where the user can click a button and that button saves a unique string (or something to identify which button was pushed) into an outside txt (or any common type) file. I have looked into the saving information tutorials here and have not been able to create it my way (without typing or selecting something). I hope that is not confusing, I am pretty new to flash scripting, any help is much appriciated. Thanks. :)

    -Mike

    MSN IM:
    drakefulter@hotmail.com

    bpat1434

    • Moderator
    • Senior Programmer
    • *****
    • Posts: 419
    • Never Miss An Opportunity To Be Great.
      • MSN Messenger - bpat1434@hotmail.com
      • AOL Instant Messenger - bpat1434
      • Yahoo Instant Messenger - bpat1434
      • View Profile
      • bPatterson
    Re:Saving "button pressed" data to outside source
    « Reply #1 on: 05/11/04, 20:48 »
    Ok.  How about defining the variables for the button strings:

    [script]
    button1var = new String("001100011100110101010010011");
    button2var = new String("010100100111001101010011101");
    button3var = new String("Whatever information you want....");
    button4var = new String("More information about stuff.........");[/script]

    Then when the button is pressed, use what the tutorial says to save the information to a text file:

    [script]on(release){
        myData.buttonString = buttonXvar;
        myData.sendAndLoad("save.php", myData, "POST");
    }[/script]

    In a general area:

    [script]myData = new LoadVars();
    myData.onLoad = function(){
        if(this.writing=="OK"){
            gotoAndStop(SomeFrameNumber);
            status.text = "Saved Successfully";
        }else status.text = "Not Saved";
    }[/script]

    Then as your PHP script:

    <?php
     
    //Capture data from $_POST array
    $string $_POST['buttonString'];

    //Make one big string in a format Flash understand
    $toSave ="UniqueString=$string";

    //Open a file in write mode
    $fp fopen("new.txt""w");

    if(
    fwrite($fp$toSave)) echo "writing=Ok&";
    else echo 
    "writing=Error&"
    fclose($fp);
    ?>


    That should work.  Hope it helps.

    ~Brett
    « Last Edit: 05/11/04, 20:49 by Brett.Patterson »

    mike

    • Server what's that
    • *
    • Posts: 6
      • View Profile
      • Email
    Re:Saving "button pressed" data to outside source
    « Reply #2 on: 05/12/04, 10:25 »
    that seems to work well, thanks brett. I also have the flash file to read outside images and display them. However it only refreshes when someone clicks a button, is there anyone to have flash read the script again and again to keep the images up to date, or possibly have it refresh after a user selected amount, say 5 seconds?

    bpat1434

    • Moderator
    • Senior Programmer
    • *****
    • Posts: 419
    • Never Miss An Opportunity To Be Great.
      • MSN Messenger - bpat1434@hotmail.com
      • AOL Instant Messenger - bpat1434
      • Yahoo Instant Messenger - bpat1434
      • View Profile
      • bPatterson
    Re:Saving "button pressed" data to outside source
    « Reply #3 on: 05/12/04, 11:14 »
    you could define a function to read the images (like you already have set-up) and at the top add this code:

    [script]function refreshImages(){
         whatever code to refresh the images
        loopmc.play(); // Play the timer loop movie again
    }[/script]

    Add that function and whatever code youhave to initially read the images.  Then create an empty movie clip (with nothing in it except action frames) and add something like this:

    loopmc
    frame 1
    [script]i = 30; // Amount of seconds/loops to do
    cl = 1; // Current Loop Number[/script]

    frame 2
    [script]if (cl == i){
        _parent.refreshImages(); // call the function if cl & i are the same
        gotoAndStop(1); // Go to beginning of loop
    } else {
        gotoAndPlay(3); // Otherwise, keep looping through
    }[/script]

    frame 13
    [script]cl++; // Add 1 to the current loop count
    gotoAndPlay(2); // Make another loop[/script]

    That loops through for every second.  Now, if you wanted to do it at a user defined interval, you would write to a variable, and call that from the loops action script.  So, you could write:

    _global.i = userInputText.text;

    Then, i would be whatever the user inputs, and any movie can read the i variable.

    Hope that helps.  I'm sure there are easier ways to do it, but this is a way that works for me.

    ~Brett
    « Last Edit: 05/12/04, 11:15 by Brett.Patterson »