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

  • SEARCH
  • Home
  • 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 6383701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:40:56+00:00 2026-05-25T02:40:56+00:00

Lets say we have a movieclip Enemy in the Flash library and a class

  • 0

Lets say we have a movieclip “Enemy” in the Flash library and a class “Enemy.as” is associated with it which listens to ENTER_FRAME event as follows,

public function Enemy():void
{
    //constructor of this "Enemy.as" class
    addEventListener(Event.ENTER_FRAME, move);
}

private function move(evt:Event):void
{
    x += 5;
}

Now my question is if this “Enemy.as” is instantiated in other class say “Main.as” which again uses ENTER_FRAME event on the same instantiated Enemy object as follows,

public function Main():void
{
    //constructor of this "Main.as" class
    enemy1 = new Enemy();
    enemy1.addEventListener(Event.ENTER_FRAME, checkCollision);
}

private function checkCollision(evt:Event):void
{
    if(enemy1.x == mainObj.x)
    {
        //do something
    }        
}

Is this the good approach in terms of optimization? Or should not use this approach at all?

  • 1 1 Answer
  • 0 Views
  • 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-25T02:40:57+00:00Added an answer on May 25, 2026 at 2:40 am

    From a performance point of view, it’s always best to only listen for ENTER_FRAME in a single location (e.g. in your main application class) and to then invoke custom update() methods on all the objects that need to be updated. That’s a very common approach for games for instance.

    One reason why this is greatly superior from a performance point of view is that no new instances of Event need to be created. If you have 100 listeners (which is not uncommon when using the approach you outline) that means 100 new instances of the Event class every frame, and instantiating classes is among the heaviest things that you can do in Flash.

    You rarely actually need the Event object in ENTER_FRAME handlers, so using the update() approach instead makes a lot of sense. If you can, try centralizing other events as well in performance critical applications like games.

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

Sidebar

Related Questions

Lets say have this immutable record type: public class Record { public Record(int x,
Lets say we have a program which contains such classes: public interface AbstractItem {
Lets say I have object Tom which has class Person. Class Person String Name
Lets say I have the following class public class Test { public int prop1
Lets say I have a class as follows: case class Person( name:String, age:Int, dependents:List[Person]
Lets say I have a class A that is fairly simple like this -
Lets say I have multiple commands like 5000 which updates some column and row
Lets say I have a div like this: <div id=test class=sourcecode> Some String </div>
Lets say I have an ActionScript class: MyClass and that class has data in
Lets say we have the following code: class C t where g :: t

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.