Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 - Recording a click with playHeadTime and using the time

I am fairly new to AS3 so any help would be appriciated.

Basically I am trying to make something similar to the Hazard Perception test, where you click and it records weather you clicked at the right time or not.

What I have so far is this:

import flash.events.Event;

videoOverlay.addEventListener(MouseEvent.CLICK,doClick)
function doClick(e:Event):void
{
    trace(myVideo.playheadTime)
}

I have managed to make a clickable area and then display click times, what I now need to do is to be able to tell if a click was in a certain time frame then add 1 point, and then at the end of the video clip I want to display a score.

I am not after just code, if anyone could maybe suggest a way of doing this it would be appriciated.

like image 312
jjhilly Avatar asked Dec 29 '25 14:12

jjhilly


1 Answers

You can store the 'right moments' in an array, xml, whatever. Let's say something like this:

var moments:Array = [{start: "1:01", end: "1:16"}, {start: "1:25", end: "1:26"}, {start: "1:39", end: "1:51"}];
//time is in minutes, so you need to convert it to seconds
function doClick(e:Event):void
{
    for (var i:int = 0; i < moments.lenght; i++)
    {
        var moment:Object = moments[i];
        if (myVideo.playheadTime => toSeconds(moment.start) && myVideo.playheadTime <= toSeconds(moment.end))
        {
            trace("that's the right moment");
            break; //we do not need to check further
        }
    }
}
like image 194
strah Avatar answered Dec 31 '25 08:12

strah