Copy link to clipboard
Copied
I have a .swf that plays for a while then reaches the end of the timeline. If no one clicks on it for a minute or two how can I have it replay again? I have been looking at timers, but this will not be triggered by touch/click-but time. I am using FLASH Pro CC 2015.
Thanks
sleep898(60); // the timer already started here by calling the function sleep898
function sleep898(sec){
// Stops the script on the current frame
stop();
// The actual pause, and starter
setTimeout(this.gotoAndPlay, sec*1000, this.currentFrame + 1);
setTimeout(removeChild, sec * 1000, child_mc);
}
Copy link to clipboard
Copied
You'll still need the timer, that's what they're for. Does the user need to click on some specific part of the stage, a particular button for instance, or is it just anywhere on the stage? How will you know when to start counting off the time? Does the movie begin and you start timing from the start? Or is it something else?
Copy link to clipboard
Copied
The swf plays on a window of glass. Its function is to attract attention. Someone walks up to it and clicks around to some other swf files. When they are bored they leave. After 3 or 5 seconds I want the main swf attractor file to start playing again.
So the timer starts after the last click, and triggers the gotoAndPlay(1); function after 5 seconds of no activity.
Does that help?
Copy link to clipboard
Copied
the timer should be at the first frame and at last frame of the intro you need to put gotoAndPlay(2), if you used gotoAndPlay(1) the timer will start again at the first frame.. So.. the timer with its function on frame one then after 5 seconds of repeating leave to the main swf..
one more thing, you have to stop the timer at the click event..
Copy link to clipboard
Copied
Thanks Ned,
I will pay with this and see what I can do.
Randall
Copy link to clipboard
Copied
Ok, I got my timer to work and proceed to the next frame after X amount of time. But when it goes to the next frame it doesn't remove child. AND is there a way to get the timer to start after no clicking for 1 minute?
Thanks
Here is my code:
stop();
backBtn565.addEventListener(MouseEvent.CLICK, backHandler565);
function backHandler565(event:MouseEvent):void {
removeChild(loader565);
x = 0;
y = 0;
scaleX = 1;
scaleY = 1;
gotoAndPlay(1);
}
var loader565:Loader=new Loader();
var pacLink:MovieClip;
this.addChild(loader565);
x = 275; // move the loaded SWF 10 pixels to the right (from the left edge)
y = 35; // move the loaded SWF 175 pixels down from the top
scaleX = .65;
scaleY = .65;
loader565.load(new URLRequest("pacLink/pacLinkiOSDemo3.swf"));
// Call the function, time in seconds
sleep898(20);
function sleep898(sec){
// Stops the script on the current frame
stop();
// The actual pause, and starter
setTimeout(this.gotoAndPlay, sec*1000, this.currentFrame + 1);
}
Copy link to clipboard
Copied
sleep898(60); // the timer already started here by calling the function sleep898
function sleep898(sec){
// Stops the script on the current frame
stop();
// The actual pause, and starter
setTimeout(this.gotoAndPlay, sec*1000, this.currentFrame + 1);
setTimeout(removeChild, sec * 1000, child_mc);
}
Copy link to clipboard
Copied
Thanks you very much!
It worked great!
Copy link to clipboard
Copied
you're welcome
Copy link to clipboard
Copied
I think it's better to use a TimerEvent instead of "setTimeout" function.. cause the setTimeout function, will keep working even after the click event..
So.. Use this way if you want to stop the timer when the user click to leave:
stop();
var _timer:Timer = new Timer(60000, 1); // (delay, repeat)
_timer.addEventListener(TimerEvent.TIMER, _timerHandler);
function _timerHandler(e:TimerEvent):void
{
removeChild(child_mc);
gotoAndPlay(2);
}
_timer.start();
// now the timer has started and the Timer Event Listener will call the function above (_timerHandler) after 60 seconds of starting
//if the user clicked the leaving button during the 60 seconds, you have to stop the timer and leave..
userButton.addEventListener(MouseEvent.CLICK, _onClick);
function _onClick(e:MouseEvent):void
{
_timer.stop(); // now the timer has stopped before completing the delay ratio means the timer function will not be called..
removeChild(child_mc);
gotoAndPlay(2);
// if you don't need to start the timer again then you can remove the listener
_timer.removeEventListener(TimerEvent.TIMER, _timerHandler);
}
Copy link to clipboard
Copied
Thanks! I hadn't thought of that.