# Optimizing a AS3 Class for Better Performance

**URL:** <https://forum.kirupa.com/t/optimizing-a-as3-class-for-better-performance/294071>\
**Category:** flash\
**Created:** [August 7, 2009, 8:53pm UTC](https://forum.kirupa.com/t/optimizing-a-as3-class-for-better-performance/294071 "2009-08-07T20:53:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FPG](https://avatars.discourse-cdn.com/v4/letter/f/8797f3/32.png) [@FPG](https://forum.kirupa.com/u/FPG)\
**Post date:** [August 7, 2009, 8:53pm UTC](https://forum.kirupa.com/t/optimizing-a-as3-class-for-better-performance/294071/1 "2009-08-07T20:53:58Z")

</div>

I’ve been working with AS3 now for a few months and am making good progress in it (I’m a AS2 transfer student). However, on a project I’m working on I’m having a little issue with performance within the browser. I was wondering if anyone had some tips on how to optimize the following code as I include this object about 600 times in my flash to make a waterfall (which causes resource drain in the browser)?

```auto

package{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    
    public class waterfall extends MovieClip{
        var myBlur:BlurFilter = new BlurFilter();
        public function waterfall(){
            this.y = findXY(0,160);
            this.x = findXY(141,443);
            this.blendMode = BlendMode.OVERLAY;
            this.alpha = 0.55;
            myBlur.quality = 3;
            myBlur.blurX = 2;
            myBlur.blurY = 2;
            this.filters = [myBlur];
            this.addEventListener(Event.ENTER_FRAME, moveWaterfall);
        }
        function moveWaterfall(e:Event):void{
            this.y += 3;
            if(this.y > 165){
                this.y = -(findXY(0,165));
                this.x = findXY(141,443);
            }
        }
        function findXY(W:int, Z:int):int{
            return Math.round(Math.random()*(Z-W))+W;
        }
    }
}

```
