actionscript 3 - How to skip video if button is not pressed in AS3 Flash? -


i'm working on video ad self project in as3. length of video 10 seconds. have set timer on 5 seconds 'keep watching' button show , if interacted video continue playing. , if not, @ 7 seconds automatically end video. how prompt video stop playing if button not pressed? getting confused.

var basetimer:timer = new timer(5000,1) var isinteracted:boolean = false;  basetimer.addeventlistener(timerevent.timer, testtimer); btskip.addeventlistener(mouseevent.click, btskipvideo);  basetimer.start();  function btskipvideo(e:mouseevent)      {         if (!isinteracted)      {         btskip.visible = false;      }         else         trace("this testing");      } 

just create timer accomplish this. this:

var basetimer:timer; var timeouttimer:timer;  //assuming btskip button timeline object not visible btskip.addeventlistener(mouseevent.click, btskipvideo, false, 0, true);  function startvideo():void {     //do whatever start video      //create base timer show button after 5 seconds     basetimer = new timer(5000, 1);     basetimer.addeventlistener(timerevent.timer, showbtn, false, 0, true); //use weak listener timer doesn't stay in memory forever     basetimer.start(); }  function endvideo(e:event = null):void {     //do whatever stop video }  function showbtn(e:event):void {     btskip.visible = true; //or decide show button      //at point it's been 5 seconds since video started play     //create other timer end video after 2 additional seconds     timeouttimer = new timer(2000, 1);     timeouttimer.addeventlistener(timerevent.timer, endvideo, false, 0, true);     timeouttimer.start(); }  function btskipvideo(e:mouseevent){     if (timeouttimer) {         //stop timer doesn't end video         timeouttimer.stop();     }      btskip.visible = false; //or you'd hide button } 

Comments