Example of ActionScript pseudo classes using functions inside functions

package
 
{
    import flash.display.Sprite;
    import flash.events.*;
 
    /**
     * ...
     * @author Roger Clark
     */
    public class Main extends Sprite
    {
 
        public function Main():void
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
 
        private function init(e:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
 
            stage.addEventListener (MouseEvent.CLICK,mClick,false,0,true);
            // entry point
        }
 
        private function mClick (event:MouseEvent):void
        {
            for (var i:uint=0; i<200; i++)
            {
                particle ();
            }
        }
 
        private function particle ():void
        {
            var xVel:Number;
            var yVel:Number;
 
            xVel = (Math.random() * 20)-10;
            yVel = (Math.random() * 20)-10;
 
            var ball:Sprite=new Sprite();
            ball.graphics.beginFill (0xff0000);
            ball.graphics.drawCircle (0,0,10);
            addChild(ball);
 
            ball.x = mouseX;
            ball.y = mouseY;
 
            ball.scaleX=ball.scaleY=(Math.random()*.5)+.5;
 
            ball.addEventListener (Event.ENTER_FRAME, eFrameHandler, false, 0, true);
 
            // as this function is declared inside of the particle function, it has access to the xVel and yVel variables in the particle function.
            // i.e particle function is behaving like a class with the variables being properties of the class
            function eFrameHandler(event:Event):void
            {
                ball.x += xVel;
                ball.y += yVel;
 
                if (xPos<0||yPos<0||xPos>stage.stageWidth||yPos>stage.stageHeight)
                {
                    ball.removeEventListener (Event.ENTER_FRAME,eFrame);
                    removeChild (ball);
                    ball=null;// Tell garbage collector we are no longer using this variable.
                              // This will cause garbage collection of the variables in the particle() function as the event listener for
                }
            }
        }
    }
}