Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:18:55+00:00 2026-05-30T02:18:55+00:00

I am working on a very simple game in Flash. I want to make

  • 0

I am working on a very simple game in Flash. I want to make all the animations framerate agnostic, so that I can change the framerate without affecting the flow and speed of the game.
I read somewhere that if you want to do that, you simply create a Timer object and attach an event listener to this timer.

What if I have many objects that have to listen to the same timer? See the code to understand what I am trying to do. At this stage nothing breaks, but the event does not fire.

Here is the Main class, the one that runs on swf execution:

public class Main extends MovieClip {

    private static var _stage:Stage;
    private static var _timer:Timer;

    public function Main() {            
        trace("STARTING_GAME");         
        init();
    }

    private function init(){
        var player:Player = new Player(100);
        this.addChild(player);

        _stage = this.stage
        _timer = new Timer(30);

    }

    public static function get stage():Stage{
        return _stage;
    }

    public static function get timer():Timer{
        return _timer;
    }


}

And here is the Player class, one of the objects that will be needing the Timer:

public class Player extends MovieClip {

    private var playerHealth:int;       


    public function Player(_health:int=100) {           
        init(_health);
    }       
    private function init(_health:int){
        trace("creating player object");            
        playerHealth = _health;
        addEventListeners();


        trace(Main.timer); //this returns [object timer] - so it's supposed to work?

    }

    private function addEventListeners(){           

        Main.timer.addEventListener(TimerEvent.TIMER, ef_Repaint);
        //this.addEventListener(Event.ENTER_FRAME, ef_Repaint);         

    }

    private function ef_Repaint(e:Event):void{

        trace("timer event firing");        

    }

}

Thanks in advance!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:18:57+00:00Added an answer on May 30, 2026 at 2:18 am

    You should start the timer.

    private function addEventListeners(){           
        Main.timer.addEventListener(TimerEvent.TIMER, ef_Repaint);
        Main.timer.Start(); 
    }
    

    The Timer class documentation says:

    The timer does not start automatically; you must call the start() method to start it.

    Also note that using a timer is not really the best approach. It is better to continue using Event.ENTER_FRAME and only execute the code if the delay you want has been elapsed:

    private function ef_Repaint(e:Event):void{ // Event.ENTER_FRAME 
    
        var timeNow = getTimer();
        if (timeNow - previousTime > 30) { // you can replace 30 with any delay you want
             previousTime = timeNow;
             // your code here
        }
    }
       
    

    Finally, if you use either approach, you should not be really listening to TimerEvent.TIMER or TimerEvent.TIMER in every object separately. You should have your event handler in Main
    and loop on your objects there and ask them to update. Having multiple event listeners is not good for performance, and they may get called in an order that you don’t expect, and you may end up with bugs that you can’t understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a very simple iPhone app, that in the end will have
I'm working with Cocos2D and I've made a very simple class that inherits from
I'm trying to make a very simple game. In it I have objects (
I am working on a simple platform game in HTML5/Canvas/Javascript/jQuery. You can see it
I'm working on very, very simple jQuery plugin that simply changes position of element
i'm working on a very simple server that uses ssl (in netbeans) - to
I'm working on a very simple lobby system for a game. Each client broadcasts
I'm working on a game where the physics are very simple. I just need
I'm working on a simple JavaScript game using HTML5 canvas. It's a very typical
I'm working on a very simple game (essentially an ice sliding puzzle), for now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.