Skip to main content
Known Participant
May 1, 2013
Answered

How to display elapsed/current time of a song in Actionscript.

  • May 1, 2013
  • 1 reply
  • 1712 views

Hi I have a question on how I can make my code display a total time for a song from a media player I created with Actionscript 3.0, using XML to load the song track.

This is my current function which I have done and I am unsure on what the problem is that is not allowing the elapsed time to display in a textfield on my stage.

stage.addEventListener(Event.ENTER_FRAME, timeElapsed);

function timeElapsed(e:Event):void

{

                    var minutesCurr:Number = Math.floor((my_channel.position /1000) /60);

                    var secondsCurr = Math.floor((my_channel.position /1000) % 60);

        if (secondsCurr < 10)

                    {

            secondsCurr = "0" + secondsCurr;

        }

        var minutesTot:Number = Math.floor((my_sound.length /1000) /60);

        var secondsTot = Math.floor((my_sound.length /1000) % 60);

        if (secondsTot < 10)

                    {

            secondsTot = "0" + secondsTot;

        }

        completeText_txt.text = minutesCurr + ":" + secondsCurr + "/" + minutesTot + ":" + secondsTot;

}

I tried adding to the stage and I am getting a null object reference.

Thanks Casey

This topic has been closed for replies.
Correct answer Ned Murphy

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 1, 2013

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

CaseyCCAuthor
Known Participant
May 2, 2013

Thanks fixed it.

Ned Murphy
Legend
May 2, 2013

You're welcome