Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Time out function on timeline...

New Here ,
Mar 08, 2010 Mar 08, 2010

Hi all!

can someone help me out with script for a time-out feature on my timeline?

I have certain spots in my timeline where i want a time-out to occur after 5 seconds of the user not clicking anywhere or doing anything.

I am familiar with mouse-listener functions... but only used them for something that i was going to make time-out after an already pre-determined time...

thanks for any help.

Pat

TOPICS
ActionScript
2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 09, 2010 Mar 09, 2010

imports should be placed at the top of your codes. Sorry also forgot to tell you that you need to activate the timer by calling setUserActivityTimeout function whenever you intend to start checking for user activity. Then every mouse click will reset the timer. If no more clicks are detected after the last click (in 5 sec), it will call onUserInactivity which will delete the handler _root.onMouseDown so that the timer will not be called again when one clicks. But you can re-enable the timer by d

...
Translate
LEGEND ,
Mar 08, 2010 Mar 08, 2010

You should look in the Help documents regarding the following...

First look into the Mouse class and see the various events that can be monitored, such as onMouseWheel, onMouseDown, onMouseMove.  There is sample code you can use there to build from.  You'll probably want to look into the Key class as well to cover keyboard related activity

Then look into the setTimeout() function along with its archrival clearTimeout().  Again, there is sample code in the help documents to get you started.

Essentially, you want to start your setTimeout immediately, and anytime a mouse event or keyboard event occurs, you want to clear it and then start a new one.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2010 Mar 08, 2010

thanks NED.  which Help Documents are you refering to? the ones that go along with Flash or are there some on Adobe's site/? i tried to find them but havent had the best luck finding what i am looking for...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 09, 2010 Mar 09, 2010

Yes, the ones that normally would come with Flash.  You can access them by pressing F1 or by selecting Help in the top menubar and then Flash Help.  If you have Flash CS4, these documents are primarily only available online.  You can also find pdf files such as the following which have clickable index listings....

http://livedocs.adobe.com/flash/9.0/main/flash_as2_language_reference.pdf
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 09, 2010 Mar 09, 2010

You can predefine a function that triggers a timeout like the code below. Then in the frames where you want a user activity timeout to start you can trigger it by assigning the setUserActivityTimeout to a onMouseDown event by for example _root.onMouseDown = Delegate.create(this, setUserActivityTimeout) and you can stop the timer with stopTimer.

import mx.utils.Delegate;

var nTimeoutId:Number;

var nTimeTolerance:Number = 5000; // 5 seconds timeout

function setUserActivityTimeout( ):Void

{

    clearTimeout(nTimeoutId)

    nTimeoutId = setTimeout(Delegate.create(this, onUserInactivity), nTimeTolerance);

}

function stopTimer( ):Void

{

    clearTimeout(nTimeoutId)

}

function onUserInactivity( ):Void

{

    //Code to handle User Inactivity

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 09, 2010 Mar 09, 2010

Thanks Harry,

I tried added this code exactly as follows:

_root.onMouseDown = Delegate.create(this, setUserActivityTimeout)

import mx.utils.Delegate;

var nTimeoutId:Number;

var nTimeTolerance:Number = 5000; // 5 seconds timeout

function setUserActivityTimeout( ):Void

{

    clearTimeout(nTimeoutId)

    nTimeoutId = setTimeout(Delegate.create(this, onUserInactivity), nTimeTolerance);

}

function stopTimer( ):Void

{

    clearTimeout(nTimeoutId)

}

function onUserInactivity( ):Void

{

    gotoAndStop("exit_no");

}

Unfortunately no luck yet...

all i really want is for if there are no mouse clicks detected after a 5 second period of time to gotoAndStop("exit_no");

if the user does click the mouse at any time the timer resets and starts over counting to 5 again.

thank you for your help!

-pat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 09, 2010 Mar 09, 2010

imports should be placed at the top of your codes. Sorry also forgot to tell you that you need to activate the timer by calling setUserActivityTimeout function whenever you intend to start checking for user activity. Then every mouse click will reset the timer. If no more clicks are detected after the last click (in 5 sec), it will call onUserInactivity which will delete the handler _root.onMouseDown so that the timer will not be called again when one clicks. But you can re-enable the timer by defining its handler again with setUserActivityTimeout.

import mx.utils.Delegate; //Should be at top of code

var nTimeoutId:Number;

var nTimeTolerance:Number = 5000; // 5 seconds timeout

_root.onMouseDown = Delegate.create(this, setUserActivityTimeout);

setUserActivityTimeout( ); //Activate the timer

function setUserActivityTimeout( ):Void

{

    clearTimeout(nTimeoutId);

    nTimeoutId = setTimeout(Delegate.create(this, onUserInactivity), nTimeTolerance);

}

function stopTimer( ):Void

{

    clearTimeout(nTimeoutId);

}

function onUserInactivity( ):Void

{

    //Delete then redefine it again if you want to activate again

    delete _root.onMouseDown;

    gotoAndStop("exit_no");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 10, 2010 Mar 10, 2010

thanks Harry! youre awesome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 10, 2010 Mar 10, 2010

No problem you're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 13, 2010 Mar 13, 2010

Harry, i have a tough problem that i am trying to figure out with my project...

I am using the attachmove function and am trying to attach a movie with the identifier name "counter2" into another movie clip with instance name

"mc_LCD_text_selected_loader".  I want the movie with identifier name "counter2" containing dynamic text box instance "counter2_text"  to increment using the code below... but it is not working right now.

i had it working before when it was its own movie clip, but now i must not be doing something right...

i am using movie clip buttons to increment / decrement the numbers.


can you please help me out?  below is my code.

mc_LCD_text_selected_loader.attachMovie("counter2", "g"+2, 2);

var Counter:Number;
var p_m:Boolean;
var Cal_Speedo1:Number;


Counter=0;
Cal_Speedo1=0;

mc_LCD_text_selected_loader["g"+2].counter2_text.text = Cal_Speedo1;

btn1.change = 1;
btn1.onPress = function() {
    p_m=true;
    this.onEnterFrame = editTF;

};
btn1.onRelease = function() {
    delete this.onEnterFrame;
    Counter=0;
};
btn2.change = -1;
btn2.onPress = function() {
    p_m=false;
    this.onEnterFrame = editTF;
};
btn2.onRelease = function() {
    delete this.onEnterFrame;
    Counter=0;
};

function editTF(){
    Counter+=1;
        if (Counter<10){
            btn1.change=1;
        }
        else if (Counter >10 and Counter<30){
            btn1.change=1;
        }
        else if (Counter>30){
            btn1.change=10;
        }
        if (Counter<10){
            btn2.change=-1;
        }
        else if (Counter >10 and Counter<30){
            btn2.change=-1;
        }
        else if (Counter>30){
            btn2.change=-1;
        }
   
   
    mc_LCD_text_selected_loader["g"+2].counter2_text.text = this.change+Number(mc_LCD_text_selected_loader["g"+2].counter2_text.text);
    if (mc_LCD_text_selected_loader["g"+2].counter2_text.text<-15){
        mc_LCD_text_selected_loader["g"+2].counter2_text.text=-15;
    }
    else if(mc_LCD_text_selected_loader["g"+2].counter2_text.text>15){
        mc_LCD_text_selected_loader["g"+2].counter2_text.text=15;
    }
}

thank you so much.

Pat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 13, 2010 Mar 13, 2010

I tried your code and it works perfectly on my setup. The text box increments/decrements. Did you figure it out?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 14, 2010 Mar 14, 2010

not yet... i think somethings wrong with my movie clip buttons... before when they were incrementing the text box you could not see the "down" state working at all... now nothing is happening to the dynamic text box, but the buttons down state are showing...

do they have to be on a particular layer heirarchy?

- pat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 14, 2010 Mar 14, 2010

There was a thread not so long ago by someone who had a problem with buttons. We were able to figure out there was a bug when you create a movieclip and would convert it to a button later in the library. The scope of "this" within the function would turn out to behave like that of the movieclip instead of the button since it was previously a movieclip. Did you attempt to switch from a movieclip to a button or vice versa? I suggest you delete them and re-create them as buttons or movieclip or what you intend them to be.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 15, 2010 Mar 15, 2010

I tried creating the movie clip "btn1" and "btn2" from scratch and still no luck... i think it has something to do with the attach movie property that i am trying to use...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 15, 2010 Mar 15, 2010

Hi Harry,

I decided not to mess with attach movie commands to incrementing / decrementing values with counters and button hold functions... might be more work for me in the long run - meaning more movie clips and shit, but at least its working without the attach movie function...

i have a totally hard question, though that is really hitting me hard...

i have a part in my flash file where if the user chooses a number of display screens to set up, they should be allowed only to set up that number of display screens and choose a predifined variable for "information 1" and "information 2" on each screen... "information 1" would contain the top 2 lines of the screen and "information 2" would contain the bottom 2 lines of the screen... My LCD screen only uses 4 lines.

For instance:

Page 1:

Line1 = CLOCK

Line2 = 3:56

Line3 = FUEL TANK 1

Line4 = ( this would contain another movie clip with a graphic representing its volume )

this dude that i work with who is way better than me at programming, but not experienced in flash told me to start like this:::

var AvailDataName:Array = ["CLOCK", "FUEL TANK 1", "EST RANGE", "WATER TEMP", "AIR TEMP", "HEADING", "LAT LONG", "COG", "RPM", "BAROMETER", "MAX SPEED", "ODOMETER"]


mc_LCD_text_loader["g"+2].line1_text.text = Pg1Line1;
mc_LCD_text_loader["g"+2].line1_text.index = 0;

var AvailDataValue:Array= ["\n3:56 PM", "\n", "\n15.6 MILES", "\n72.2 F", "\n86.2 F", "\n128.8 MAG", "\n41 21N 072 33W", "\n110.5 MILES", "\n3500 RPM", "\n14.7 PSI", "\n33.4 MPH", "\n108 MILES"]


var indexPg1Line1:Number

Pg1Line1 = AvailDataName[0]+AvailDataValue[0];
indexPg1Line1=0;

Pg1Line2 = AvailDataName[1]+AvailDataValue[1];
indexPg1Line1=1;

Pg2Line1 = AvailDataName[2]+AvailDataValue[2];
indexPg1Line1=2;

Pg2Line2 = AvailDataName[3]+AvailDataValue[3];
indexPg1Line1=3;

Pg3Line1 = AvailDataName[4]+AvailDataValue[4];
indexPg1Line1=4;

Pg3Line2 = AvailDataName[5]+AvailDataValue[5];
indexPg1Line1=5;

Pg4Line1 = AvailDataName[6]+AvailDataValue[6];
indexPg1Line1=6;

Pg4Line2 = AvailDataName[7]+AvailDataValue[7];
indexPg1Line1=7;

Pg5Line1 = AvailDataName[8]+AvailDataValue[8];
indexPg1Line1=8;

Pg5Line2 = AvailDataName[9]+AvailDataValue[9];
indexPg1Line1=9;

Pg6Line1 = AvailDataName[10]+AvailDataValue[10];
indexPg1Line1=10;

Pg6Line2 = AvailDataName[11]+AvailDataValue[11];
indexPg1Line1=11;

btn_test.onRelease = function()
{
indexPg1Line1=0;
indexPg1Line1 +=1;
mc_LCD_text_loader["g"+2].line1_text.index = 0;

mc_LCD_text_loader["g"+2].line1_text.text = AvailDataName[indexPg1Line1];
mc_LCD_text_loader["g"+2].line1_text.text = AvailDataValue[indexPg1Line1];
}

i am sorry Harry... this shit looks like garbage to you i am sure... but any input would be helpful...

I am using the attach movie function, and would like to just be able to switch the corresponding "AVAIL DATA NAME" and "AVAIL DATA VALUE" simutaneously while stayin on the same frame...

i attached my file just incase you felt like helping me out more...

thanks bro.

Pat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 15, 2010 Mar 15, 2010

its not letting me attach any files right now...

i will try later.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 15, 2010 Mar 15, 2010

nog

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 17, 2010 Mar 17, 2010

Adobe disabled the file attachment feature, probably because many are uploading large files. Can you try upload the file somewhere else? Sorry i was slack on this. I hope though you were able to come up with a solution... Or maybe you wanna post this on a new thread so that the other forumers can help too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 22, 2010 Mar 22, 2010

thanks Harry... no worries... i will try to find a better spot to upload. or maybe i can send it to your email???

on another note, i will be adding some sound "beeps" (most likely 2 second audibles) that will play when a user hits a button etc.

is there a better way to have them load/play or should i just plop the .aiff file right onto the  timeline?

only thing i can think of is if the user moves backward on the timeline i wont want the sound to play... so more like when they press a button i will need it to play...

do you have any suggestions on this?

thanks man.

Pat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 29, 2010 Mar 29, 2010

Harry,

is there a way to do the same timeout function that you helped me with in AS3???

I wish AS 3 was more compatible with AS 1 and 2... i tried exact same code with no luck..

thanks.

Pat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 29, 2010 Mar 29, 2010

Hi Pat,

I've been really busy at work so i don't have much time on the forum... You can try to place your questions on a new thread so that other forumers will also be able to help.

import flash.utils.Timer;

import flash.events.TimerEvent;

var nTime:uint = 1000;

var cTimer:Timer = new Timer(nTime, 1); //for infinite calls, remove 2nd param)

cTimer.addEventListener(TimerEvent.TIMER, onTimeout);

cTimer.start();

function onTimeout(oEvent:TimerEvent):void

{

    trace("Timeout occured on: " + oEvent.target);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 29, 2010 Mar 29, 2010
LATEST

thanks, Harry... ill try your help. youre a good man my friend.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines