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 4610904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:11:47+00:00 2026-05-22T01:11:47+00:00

I’m animating a bunch of words in AS3. Because I’m going to be using

  • 0

I’m animating a bunch of words in AS3. Because I’m going to be using this on a mobile device, I want to use bitmaps rather than Sprites. So I’ve created WordObjects, which have a .bitmap property that I can access.

I have the following code, which fires on the click event and loops through an array inside an enterframe event. This is probably a bad idea, but I’m not sure how to do it better. (What is surprising is that it runs just fine in Flashbuilder, but slows to a crawl in Flash CS5.)

Is there some better way to do this? I just want an efficient way to animate the array of bitmaps.

    private function clickhandler (e:MouseEvent){

        this.addEventListener(Event.ENTER_FRAME, blowemup);
    }
    private function blowemup(e:Event){
        var newPosition:Number;
        for(var i:int=0; i<arrWordObjects.length; i++)
        {
            newPosition = updatePosition(arrWordObjects[i].bitmap);
            arrWordObjects[i].bitmap.x += newPosition;
            arrWordObjects[i].bitmap.y += getRandomNumber();

        }
    }
  • 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-22T01:11:47+00:00Added an answer on May 22, 2026 at 1:11 am

    Something that will make a huge difference is using for each(Object in Array) rather than the standard for loop.

    private function blowemup(e:Event):void
    {
        var newPosition:Number;
    
        var i:ArrWordsObjectClass; // <-- don't know what the class for this is, just replace
        for each(i in arrWordObjects)
        {
            newPosition = updatePosition(i.bitmap);
            i.bitmap.x += newPosition;
            i.bitmap.y += getRandomNumber();
        }
    }
    

    A for each loop is typed, meaning a lot of time is saved where normally it’d be trying to work out what arrWordObjects[i] is every iteration.

    Also, side note: using one ENTER_FRAME driven function and looping through everything in your application that you want to handle each frame is much more efficient than applying hundreds of listeners for objects.

    I normally create a handler class that contains the ENTER_FRAME and an array storing my objects, like so:

    package
    {
        import flash.events.Event;
        import flash.display.Sprite;
    
        public class Handler extends Sprite
        {
            // vars
            public var elements:Array = [];
    
            /**
             * Constructor
             */
            public function Handler()
            {
                addEventListener(Event.ENTER_FRAME, _handle);
            }
    
            /**
             * Called on each dispatch of Event.ENTER_FRAME
             */
            private function _handle(e:Event):void
            {
                var i:Element;
                for each(i in elements)
                {
                    i.step();
                }
            }
        }
    }
    

    Then I create a base class for all the objects that I want to handle, containing the step() function called above.

    package
    {
        import flash.display.DisplayObject;
    
        public class Element extends Object
        {
            // vars
            public var skin:DisplayObject;
    
            /**
             * Called on each dispatch of Event.ENTER_FRAME at Handler
             */
            public function step():void
            {
                // override me
            }
        }
    }
    

    Now just extend Element with your objects:

    package
    {
        import flash.display.Sprite;
    
        public class MyThing extends Element
        {
            /**
             * Constructor
             */
            public function MyThing()
            {
                skin = new Sprite();
    
                skin.graphics.beginFill(0);
                skin.graphics.drawCircle(0,0,40);
                skin.graphics.endFill();
            }
    
            /**
             * Override step
             */
            override public function step():void
            {
                skin.x += 4;
            }
        }
    }
    

    And get it all going!:

    var handler:Handler = new Handler();
    
    var m:MyThing;
    var i:uint = 0;
    for(i; i<10; i++)
    {
        m = new MyThing();
        m.y = Math.random()*stage.stageHeight;
    
        handler.elements.push(m);
        addChild(m.skin);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.