Sunday, 4 January 2015

FLASH TIMER IN AS2 AS3

FLASH TIMER IN AS3


FLASH TIMER IN AS3

--------------------------------------------------------------------------------------------------------------
1- CREATE TEXT BOX AND GIVE NAME txt
COPY AND PASTE BELOW CODE

COUNTDOWN TIMER 1 TO 10 IN JAVASCRIPT

https://www.youtube.com/watch?v=iIwrMbERWI8
http://www.hknksy.com/flash-timer-as3/
http://www.hongkiat.com/blog/10-killer-flash-tips-for-beginners/
http://html-tuts.com/count-up-timer-in-flash-actionscript-2/
https://www.video2brain.com/en/lessons/the-welcome-screen-6
http://www.republicofcode.com/tutorials/flash/as3timer/
http://www.flashandmath.com/howtos/eztimer/
http://flashvideotrainingsource.com/tag/custom
http://www.emanueleferonato.com/2008/11/18/understanding-as3-timer-class/
http://v2.scriptplayground.com/tutorials/as/Basic-Timer-in-AS3/
http://www.ilike2flash.com/2009/06/countdown-timer-in-actionscript-3.html
http://www.ilike2flash.com/2009_07_01_archive.html

------------------------------------------------------------------------------------------------------------------

var timer:Timer = new Timer(1000);
timer.addEventListener (TimerEvent.TIMER, onTimer);
var num:uint = 1;
function onTimer (e:TimerEvent):void
{
num++;
txt.text = num.toString();
if (num == 10)
{
num = 0;
}
}
timer.start ();
SIMPLE TIMER IN AS2
http://stackoverflow.com/questions/8052221/how-to-wait-for-3-seconds-in-actionscript-2-or-3
this.onEnterFrame = TimerFunction;
function TimerFunction(){   
var TimerFunction:Number = setInterval(TimerFunction,1000);
txt1.text = TimerFunction;
}
SLOW TIMER IN AS2
http://digitfreak.com/tutorial/937-how-to-make-a-timer-in-flash-as2-tips
=============================================================================================
FIRST WRITE timer IN VARIABLE BOX
timer = 0;
countup = function(){
timer++;
}
countupInterval = setInterval(countup,1000);
===========================================
AS2 TIMER STARTS 0 TO 10 

var count:Number = 0;
countdown=function(){
count++;
if(count==10){
clearInterval(doCountdown);
}
txt1.text=String(count);
}
doCountdown = setInterval(countdown,1000);
AS2 TIMER STARTS 10 TO 0 
var count:Number = 10;
countdown=function(){
count--;
if(count==0){
clearInterval(doCountdown);
}
txt1.text=String(count);
}
doCountdown = setInterval(countdown,1000);


Basic Usage of the Timer Class

The Timer Class is used to execute any code repeatedly after certain time periods. For example, in the movie shown above we are using the Timer Class to make the movie clip rotate a little bit more every second. In code terms, this is done by the Timer Class by triggering an event called TIMER at the specified interval which are then caught using an event listener.
In order to use the Timer Class the following procedure must be followed:
  1. Create an instance of the Timer Class and set the delay period and the repeat count when as you create the new instance.
  2. Listen to the TimerEvent.TIMER using the .addEventListener method.
  3. Create your event listener function to execute the code you wish to run repeatedly.
  4. Start your timer using the .start() method.
The generalized code below illustrates this whole procedure.
var myIndetifier:Timer = new Timer(delay, repeat-count); myIdentifier.addEventListener(TimerEvent.TIMER, timerListener); function timerListener (e:TimerEvent):void{ //commands } myIdentifier.start();
An actual code example illustrating the same thing is as follows:
var myTimer:Timer = new Timer(2000,8); myTimer.addEventListener(TimerEvent.TIMER, timerListener); function timerListener (e:TimerEvent):void{ trace("Timer is Triggered"); } myTimer.start();
We are going to explain this code step by step. The first step for using the Timer Class is by creating an instance of it (instantiation), this is a regular procedure required for using the majority of AS classes which simply requires using the new operator. The Timer Class can be configured at the instance of creation by settings its two main properties delay and repeat count at instantiation. The delay property is the time interval in milliseconds at which the Timer Class is to be triggered. For example, if we want our box to rotate once every 3 seconds we would set the delay property to 3000 milliseconds. If we want this rotation to be triggered once every half a second, we would set this property to 500.
The repeat count property on the other hand is the number of times the Timer Class is triggered. If you want to have only 5 repeat counts simply set this property to true. If you want your Timer to run infinitely then omit this property altogether.
So if we want to create a new instance of the Timer Class named myTimer and let it execute our code 8 times at 1 second intervals we would do that this way:
var myTimer:Timer = new Timer(2000,8);
A 1000 milliseconds equal 1 second.
The second step for using the Timer Class involves using an event listener to track the special event TimerEvent.TIMER. We are simply going to use the.addEventListener method to listen to this event and attach an event listener function that we will define later. Note that the Timer Event must be listened to by an instance of the Timer Class:
var myTimer:Timer = new Timer(2000,8); myTimer.addEventListener(TimerEvent.TIMER, timerListener);
Please review our AS3 Event Handling Tutorial to learn about adding interactivity to your ActionScript projects.
The third step is to define the event listener function. There is no difference at all between this listener function and listener functions created to track other events. Our function will have the simple task of outputting the phrase "Timer is Triggered" on the screen using the trace() command.
var myTimer:Timer = new Timer(2000,8); myTimer.addEventListener(TimerEvent.TIMER, timerListener); function timerListener (e:TimerEvent):void{ trace("Timer is Triggered"); }
The final step simply requires us to start the timer using the .start() method:
var myTimer:Timer = new Timer(2000,8); myTimer.addEventListener(TimerEvent.TIMER, timerListener); function timerListener (e:TimerEvent):void{ trace("Timer is Triggered"); } myTimer.start();
You can paste this on the timeline of your movie and test it to see the message "Timer is Triggered" in the output pop up each two seconds eight times.
Timer is Triggered 8 Times
You can use this process to repeat any amount of code over a period of time. Simply change the parameters you've used when instantiating the Timer Class and change the content of the timerListener to execute a different code.
That was the basic usage of the Timer Class. It is possible to stop the timer manually at any time using the .stop() method and it is also possible to react the natural termination of the timer sequence by listening to the TimerEvent.TIMER_COMPLETE event. We will discuss this two points next.

Stopping the Timer Manually

It is possible to stop the timer at any time before the expiry of the repeat count by using the .stop() method. The usage of this in practice will depend on the needs of your project. To use the .stop() method you will have to apply it directly to your instance of the Timer Class instance this way:
myTimer.stop();
This will usually be done through a conditional or another event listener triggered by a click over a button. To create such a button you will need to create the button and then use the addEventListener method to attach the function to it:
my_btn.addEventListener(MouseEvent.CLICK, stopTimer); function stopTimer(e:MouseEvent):void{ myTimer.stop(); }
Please review our AS3 Event Handling Tutorial to learn about adding interactivity to your ActionScript projects.
Using the .stop() method and the .start() method it is possible to create control buttons for a timer that let's you start and stop it at any time. Here is the code for creating such a project:
var myTimer:Timer = new Timer(1000); myTimer.addEventListener(TimerEvent.TIMER, timerListener); function timerListener (e:TimerEvent):void{ logo_mc.rotation+=20; } start_btn.addEventListener(MouseEvent.CLICK, onStart); function onStart(e:MouseEvent):void{ myTimer.start(); } stop_btn.addEventListener(MouseEvent.CLICK, onStop); function onStop(e:MouseEvent):void{ myTimer.stop(); }
And here is a movie showing the example above:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.utils.getTimer;
import flash.events.TimerEvent;
import flash.text.TextField;
public class as3timer extends Sprite {
var interval_timer = new timetext;
var frame_timer = new timetext;
public function as3timer() {
addChild(interval_timer);
addChild(frame_timer);
frame_timer.y = 50;
var time_count:Timer = new Timer(1000);
time_count.addEventListener(TimerEvent.TIMER, show_time);
stage.addEventListener(Event.ENTER_FRAME,on_enter_frame);
time_count.start();
}
function show_time(event:TimerEvent) {
interval_timer.txt.text = event.target.currentCount;
}
function on_enter_frame(event:Event) {
var elapsed = getTimer();
frame_timer.txt.text = Math.floor(elapsed/1000)+"."+(elapsed%1000);
}
}
}
// Requires a movieclip with the instance name "objectMC" to be on the stage

var myTimer:Timer = new Timer(1000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();

function timerHandler(evt:TimerEvent):void
{
  objectMC.x = 200;
  objectMC.y = 200;
}

Countdown Timer in Actionscript 3

In this tutorial you will learn how to create a countdown timer in Actionscript 3.0. This is an update from the previous countdown in timer in AS2. The AS2 version used the setInterval function, but this has now been removed and been replaced with the Timer Class in AS3. I have used a Flash CS4 for this tutorial and start the countdown at 60 seconds, but this can easily be changed. Countdown Timer in Actionscript 3 Step 1 Create a new Flash AS3 file. Select the static text tool and type a message on the stage. I have used impact font type, but you can use whatever font you wish. Step 2 Select the dynamic text tool and drag a rectangle shape like below: Step 3 Select your dynamic text and give the instance name “myText_txt” like below: Step 4 On the timeline insert a new layer called “Actions”. Right click on the 1st frame and select Actions then enter the following code:
//1.
var count:Number = 60;

//2.
var myTimer:Timer = new Timer(1000,count);

//3.
myTimer.addEventListener(TimerEvent.TIMER, countdown);

//4.
myTimer.start();

//5.
function countdown(event:TimerEvent):void {
myText_txt.text = String((count)-myTimer.currentCount);
}
Code: 1. This is the starting number of the countdown. I have used 60, but you can change this number to whatever you wish. 2. This creates a new timer with the instance name “myTimer”. The first parameter is the interval value in milliseconds, so an interval of 1000 would be equally to a one second interval. The second parameter is the count, which is the number of times, the timer will countdown before it stops. 3. This is an event listener for the timer. The “Timer.event.Timer” is the event and countdown is the function which is called every time for the event. 4. This is needed to starts the timer. 5. This is the countdown function which converts a number into a string and subtracts the count from the “currentCount”. The “currentCount” actually counts from 1 – 60, but subtracting the count allows you to go from 60 – 0.
==============================================================================
TIMER EXAMPLES IN AS3
http://www.krolldesign.net/tech/flash/as3_timer_event1.php
http://www.gavinsim.com/games/ninja.html
===============================================================================

var horizontalSpeed:int = 10;
var verticalSpeed:int = 8;

var ballRadius:Number = ball_mc.width / 2;

var myTimer:Timer = new Timer(20);
myTimer.addEventListener(TimerEvent.TIMER, moveBall);
myTimer.start();

function moveBall(myEvent:Event):void
{
 if (ball_mc.x + ballRadius > stage.stageWidth)
 {
  horizontalSpeed *= -1;
 }
 else if (ball_mc.x - ballRadius < 0)
 {
  horizontalSpeed *= -1;
 }
 
 if (ball_mc.y + ballRadius > stage.stageHeight)
 {
  verticalSpeed *= -1;
 }
 else if (ball_mc.y - ballRadius < 0)
 {
  verticalSpeed *= -1;
 } 
 
 ball_mc.x += horizontalSpeed;
 ball_mc.y += verticalSpeed; 
}
==================================================================
RANDOM COUNTER IN AS2 1 TO 10
https://www.youtube.com/watch?v=rchwTFxid58
==================================================================
http://flashcollege.blogspot.co.uk/2015/01/flash-timer-in-as3.html
https://www.youtube.com/watch?v=CUHZ-2my2yI
==================================================================
//https://www.kirupa.com/developer/actionscript/tricks/random.htm
//http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001220.html
function RandomNumberAs2(){
var ZERO:Number = 0;
ZERO = Math.floor(Math.random() * 11);
txt1.text = ZERO;
}
ZERO = 0;
RandomNumberAs2();

btn1.onPress = function () { 
var ZERO:Number = 0;
// HERE 11 NUMBER SHOW COUNTER PLAY BETWEEN 0 TO 10
ZERO = Math.floor(Math.random() * 11);
txt1.text = ZERO;
}
---------------------------------------------------------------------------------------
TIMER GOES TO ZERO
http://www.flashandmath.com/howtos/eztimer/

var startTime:Number;
var timeElapsed:Number;
/* We enable tabbing for the two input textboxes and disable it for the button. This gives us the correct keyboard interface.  */
txtRepeatCount.tabEnabled = true;
txtMilliseconds.tabEnabled = true;
btnGo.tabEnabled = false;
/* We restrict the characters that can be entered in the input boxes. (We also set on the stage the maximum of 4 characters for each box by entering 4 in the 'Maximum characters' field.)  */
txtRepeatCount.restrict="0123456789";
txtMilliseconds.restrict="0123456789";
/* We create an instance of the Timer class and store it in a variable 'tm'. The constructor requires one parameter: delay. delay is, the time interval (in milliseconds) bewteen ticks of the Timer. The second, optional, parameter stands for repeatCount; that is, the number of times you want the Timer to fire. (The default, 0, makes the Timer repeat for ever, or until the .stop() method is invoked.) We set delay to 100 initially - our Timer will "fire once every 100 milliseconds." We will be getting other values for delay from the user at runtime.  */
var tm:Timer = new Timer(100);
/* Each time the TimerEvent.TIMER event is dispatched, the .currentCount property of 'tm' increases by 1 automatically, and the handler, timerFires, is called. Initially, and after any call to the tm.reset() method, the value of tm.currentCount is 0.  */
tm.addEventListener(TimerEvent.TIMER, timerFires);
/* The timerFires function updates the contents of the dynamic textbox, txtCounter. Note that .currentCount starts with the value 0, and fires for the first time after one "tick" of the delay amount. Hence, the first value we see in this applet is 1.  */
/* The function also measures the time from when count began and updates txtElapsed. The time elapsed equals getTimer()-startTime. The function 'getTimer' (a method in flash.utils package) measures the time since the applet started, in milliseconds. The value for startTime was recorded when the button GO TIMER was clicked. (See the function startCounting below.)  */
/* Incidentally, the function getTimer has nothing to do with the Timer class. A better name for it would be: 'getTime'.  */
/* te.updateAfterEvent() forces a screen update after tm fires rather than wait for next scheduled screen update.  */
function timerFires(te:TimerEvent):void {
txtCounter.text = String(tm.currentCount);
txtElapsed.text=String(getTimer()-startTime);
te.updateAfterEvent();
}
/* When the value of the .currentCount property reaches the value of the .repeatCount property, the TIMER_COMPLETE event is dispatched. In our example, the handler function timerFinishes is called to signal the Timer object has finished. Note that if the value of .repeatCount property of tm is set to 0, then the TIMER_COMPLETE event will never fire, creating a timer that runs forever unless the .stop() method is invoked. (Indeed, after a Timer starts its currentCount will never equal 0 again, not until the Timer is reset.)  */
tm.addEventListener(TimerEvent.TIMER_COMPLETE, timerFinishes);
/* The background of the txtCounter textbox changes color to show precisely when the TIMER_COMPLETE event is dispatched. You will notice that it is concurrent with the final occurrence of the TIMER event.  */
function timerFinishes(te:TimerEvent):void {
txtCounter.backgroundColor = 0xFFFFAA;
timeElapsed=getTimer()-startTime;
txtElapsed.text=String(timeElapsed);
}
/* In our applet, pressing the btnGo button will call the startCounting function. This clears the txtCounter and txtElapsed text fields and resets txtCounter's background color to white. The function also sets the .delay and .repeatCount properties (based on the user's input), and resets the tm timer before starting it. Without calling the .reset() method, the .currentCount property would not be reset to 0 before being started.  */
btnGo.addEventListener(MouseEvent.CLICK, startCounting);
function startCounting(e:MouseEvent):void {
var rc:int;
var d:Number;
txtCounter.text = "";
txtElapsed.text="";
txtCounter.backgroundColor = 0xFFFFFF;
rc=int(txtRepeatCount.text);
if(txtRepeatCount.text=="" || rc==0){
rc=10;
txtRepeatCount.text="10";
}
tm.repeatCount = rc;
d=Number(txtMilliseconds.text);
if(txtMilliseconds.text=="" || d==0 || isNaN(d)){
d=500;
txtMilliseconds.text="500";
}
tm.delay = d;
tm.reset();
startTime=getTimer();
tm.start();
}
---------------------------------------------------------------------------------------
TIMER GOES TO ZERO 
CREATE 4 BUTTONS AND ON BLUE EMPTY BOX MOVIE CLIP
WHICH MOVES WITH TIMER AND ONE TEXT BOX FOR TIMER
GIVE INSTANCE NAME
BlueBox,MyCount,APPLE,BOY,A,B


----------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE
DOWNLOAD SOURCE FILE:
http://bit.ly/1L3ITom
//BELOW TEXT LINE TIMER GOES TO ZERO
MyCount.text = String(Count * 0);
----------------------------------------------------------------------------------------

var Count:uint = 0;
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER,CountDown);
myTimer.start();
function CountDown(event:TimerEvent):void {
Count += 1; 
MyCount.text = Count.toString()
if (Count > 10){
BlueBox.x = 160 , BlueBox.y = 123
myTimer.stop();
A.addEventListener(MouseEvent.CLICK,AppleHide);
B.addEventListener(MouseEvent.CLICK,BoyHide);
//BELOW TEXT LINE TIMER GOES TO ZERO
MyCount.text = String(Count * 0);
}}

function AppleHide(e:MouseEvent):void{
if (Count> 10) {
APPLE.visible=false;
A.visible=false;
myTimer.reset();
BlueBox.x = 386.95 ,BlueBox.y = 127
}
if(Count == 11 ) {Count  = Count  - 11}
else{
APPLE.visible=true;
A.visible=true;
}
}
function BoyHide(e:MouseEvent):void{
if (BlueBox.x = 386.95 , BlueBox.y = 127) {
B.visible=false;
BOY.visible=false;
BlueBox.visible=false;
MyCount.text ="YOU WIN "
}
}

----------------------------------------------------------------------------------------
CLICK GAME WITH BUTTON WITHOUT TIMER AS3

WHEN BOTH BUTTON CLICK THEN  VISIBLE FALSE
---------------------------------------------------------------------------------------

bn1.addEventListener(MouseEvent.CLICK,fn1)
function fn1(e:MouseEvent):void{
bn1.label = " OFF "
}
bn2.addEventListener(MouseEvent.CLICK,fn2)
function fn2(e:MouseEvent):void{
bn2.label = " OFF "
}
addEventListener(Event.ENTER_FRAME, fn3);
function fn3(e:Event):void{
if (bn1.label ==  " OFF "  && bn2.label == " OFF " ) {
bn1.visible=false;
bn2.visible=false;
}
}
http://www.webwasp.co.uk/tutorials/b56-setInterval/04.php
Timer with Reset: The Stage
On stage the text box with the word 'seconds' has been removed and replaced with a blank Dynamic text box called: myLabel
Otherwise it is the same as the previous example - except for the Reset button which I will come back to.
Timer with Reset: The ActionScript
Place the following ActionScript in Frame 1:
myLabel = "seconds"; myTimer = setInterval(wait, 1000); function wait() {     mySeconds++;     if (mySeconds == 1) {         myLabel = "second";     } else {         myLabel = "seconds";     } }
Timer with Reset: ActionScript Line by Line
myLabel = "seconds"; Sets the Dynamic text box myLabel to display the word seconds at the start.
myTimer = setInterval(wait, 1000); Calls the function every 1 second.
function wait() { The start of the function
mySeconds++; Adds 1 to the Dynamic text box mySeconds every time the function is called.
if (mySeconds == 1) { If mySeconds equals 1 then...
myLabel = "second"; myLabel displays the word second
} else { If mySeconds does not equal 1 then...
myLabel = "seconds"; myLabel displays the word seconds
Timer with Reset: The Reset Button
The Reset Button ActionScript is very simple:
on (release) {     _root.mySeconds = 0; }
          


























1 comments:

Flash Timer In As2 As3 - Flash College >>>>> Download Now

>>>>> Download Full

Flash Timer In As2 As3 - Flash College >>>>> Download LINK

>>>>> Download Now

Flash Timer In As2 As3 - Flash College >>>>> Download Full

>>>>> Download LINK 1q


EmoticonEmoticon