3 Replies Latest reply on Aug 9, 2009 4:50 PM by Ned Murphy

    Trouble referencing instance name from different frame

    tonyromo

      Newbie here. All my code is in frame 1 and is working fine except for one onRelease event. In frame 20 (labeled "gameOver") there is a button which has an instance name of btnQuit. I want that button to do something onRelease. The code works fine if I put it inside the button like so: on (release) {......etc. But I would like to have all my code in frame 1 in a timeline called "scripts".

       

      I think I'm missing something to reference the button's instance name (maybe a "_root", or "this", or some of those things that I don't fully understand).

       

      Here's the code that works when put in frame 20 inside the button, but not in frame 1 in a different timeline:

       

      btnQuit.onRelease = function () {

       

        // Calculate elapsed time
        var now = new Date()
        var elapsedTime = now - startTime; // startTime set beforehand

       

        var strTime:String = Math.floor(elapsedTime / (1000 * 60 * 60)) + ":" +
         (Math.floor(elapsedTime / (1000 * 60)) % 60) + ":" +
         (Math.floor(elapsedTime / (1000)) % 60);

        // Send data to PHP
        dataOut = new LoadVars();
        if ( finalScore > 89 ) {
          dataOut.passed = '1';
        } else {
          dataOut.passed = '0';
        }
        dataOut.score = finalScore;
        dataOut.time_spent = strTime;
        dataOut.send("lesson.php","_self","POST");

       

      }