Pageing system OOP

Hello,

im trying to create good OOP reusable pageing system, so i created 2 simple classes, but i know it can be done much better, and i wanna learn how.

I have few buttons on stage. Each opens a different Page and closes others. All the buttons are assigned to PageSystem object, and pages PageFirst, PageSecond … are assigned to Buttons in main. Like this:


a = new Button (0, 0);   
b = new Button (0, 100); 
c = new Button (0, 200);                                         
  
a.AttachPage (PageFirst, this, 200, 0);                                   
b.AttachPage (PageSecond, this, 200, 250);                                       
c.AttachPage (PageThird, this, 200, 500);                                                        
addChild (a);addChild (b);addChild (c);      
  
pageingSystem.subscribe(a);
pageingSystem.subscribe(b);
pageingSystem.subscribe(c);


So, PageSystem object should take all buttons and put then in array, and listen for each button clicks from array. When the current button is clicked, it iterates through array and calls Button.ClosePage(); to all except on currently clicked.


public class PageingSystem
{        
        private var buttonArr:Array;        
                
        public function PageingSystem()
        {
            buttonArr = new Array ();            
        }        
        public function subscribe (button:Button):void
       {
            buttonArr.push (button);        
            button.addEventListener (MouseEvent.CLICK, CloseOthers );
        }                            
        public function CloseOthers (e:Event):void
        {            
            for (var i:int = 0; i < buttonArr.length; i++ )
            {
                if ( (e.currentTarget as Button) != buttonArr* as Button) )
                {                
                    (buttonArr* as Button).RemovePage();
                }                            
            }
        }                 
    }

Button class also has MouseEvent.CLICK, and AddPage to show and RemovePage to “free memory”.


public class Button extends BaseNavButton
    {             
        public var _Parent:Object;
        private var _type:Class;
        private var _page:Page;  
            
        public function Button (x:int = 0, y:int =0 )
        {  
            this.addEventListener (MouseEvent.CLICK, click);            
        }
        private function click (e:Event):void
        {
            AddPage ();
        }        
        public function AttachPage(type:Class, thisParent:Object, xPosition:int, yPosition:int)
        {
            _xPage = xPosition;
            _yPage = yPosition;
            _type = type;
            _Parent = thisParent;
        }                 
        public function AddPage():void
        {
            if (_page == null)
            {                
                _page = new _type ();
                _page.SetPage (_xPage, _yPage);            
                _Parent.addChild (_page);
            }        
        } 
        public function RemovePage():void
        {
            if (_page != null)
            {
                _Parent.removeChild (_page);
                _page = null;
            }
        }

And that’s it, I did try to implement Observer pattern, but its to confusing for a OOP begginer.

So if you have an idea how to make this PageingSystem in other more elegant way, please share.

It would be nice for start that PageSystem doesnt hold mouse click events,
cause button already does.