A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Writing the computer's time in a txt file everytime the user clicks a button

  1. #1
    Junior Member
    Join Date
    Sep 2015
    Posts
    2

    Red face Writing the computer's time in a txt file everytime the user clicks a button

    Hello everyone,

    I'm a research student and I want to run a point&click study when everytime the user clicks a specific button I can have the exactly time (milliseconds) it happened... How can I use actionscript 2 to create a txt file with this data?

    Could someone help me please? I think it's not that difficult but I can't figure it out

    Thanks!

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Try something like so,
    PHP Code:
    var thisDay:Date;
    var 
    thisTime:Number;

    function 
    getTime():Void
    {
        
    thisDay = new Date();
        
    thisTime thisDay.getTime();

        
    trace(thisTime);
    }

    var 
    keyListener = new Object();
    keyListener.onKeyDown = function()
    {
        if (
    Key.isDown(Key.SPACE))
        {
            
    getTime();
        }
    };
    Key.addListener(keyListener); 
    Create a new AS2 document paste the code and test, yuou will also need to look into saving to text file in AS2 using php (most likely, easiest).
    http://stackoverflow.com/questions/2...-file-from-as2
    It's a lot easier in AS3 to save to file.

  3. #3
    Junior Member
    Join Date
    Sep 2015
    Posts
    2
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Try something like so,
    PHP Code:
    var thisDay:Date;
    var 
    thisTime:Number;

    function 
    getTime():Void
    {
        
    thisDay = new Date();
        
    thisTime thisDay.getTime();

        
    trace(thisTime);
    }

    var 
    keyListener = new Object();
    keyListener.onKeyDown = function()
    {
        if (
    Key.isDown(Key.SPACE))
        {
            
    getTime();
        }
    };
    Key.addListener(keyListener); 
    Create a new AS2 document paste the code and test, yuou will also need to look into saving to text file in AS2 using php (most likely, easiest).
    http://stackoverflow.com/questions/2...-file-from-as2
    It's a lot easier in AS3 to save to file.
    Hello,

    Thanks for the reply! So do you think I should use AS3 instead? I was going to use AS2 because it's easier to insert the code within each button (movieclip)

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    hI,

    Not necesaarily, I'm just saving its a whole lot easier to save files using AS3.
    But saying that you will still need to use some sort of server language if you are saving to a server, saving locally is easier with AS3,

    You could also do the code likie so,

    PHP Code:
    var thisDay:Date;
    var 
    thisTime:Number;

    function 
    getTime(thisKey:String,thisCode:Number):Void
    {
        
    thisDay = new Date();
        
    thisTime thisDay.getTime();
        
        
    trace(thisTime " - key pressed: " thisKey " - " thisCode);
    }

    var 
    keyListener = new Object();
    keyListener.onKeyDown = function()
    {
        
    //if (Key.isDown(Key.SPACE))
        //{
            
    getTime(String.fromCharCode(Key.getAscii()), Key.getCode());
        
    //}
    };
    Key.addListener(keyListener); 
    Which will tell you what key has been pressd, rather than putting the code on every button / key

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center