forked from: flash on 2009-9-7

by nausicaa forked from flash on 2009-9-7 (diff: 40)
♥0 | Line 70 | Modified 2010-01-19 17:38:18 | MIT License
play

ActionScript3 source code

/**
 * Copyright nausicaa ( http://wonderfl.net/user/nausicaa )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/n7nj
 */

// forked from yd_niku's flash on 2009-9-7
package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    public class PagerSample extends Sprite{

        //private var _currentPage:int;
        //private var _totalPages:int;
        private var _pager:Pager;
        private var _numField:TextField;
        

        public function PagerSample () {
            //_currentPage = 0;
            //_totalPages= 10;
            
            _pager=new Pager(60);
            
            _numField = new TextField();
            _numField.width = 60;
            _numField.height= 24;
            addChild( _numField );
            
            var btnPrev:Sprite = new PageButton("PREV");
            var btnNext:Sprite  = new PageButton("NEXT");
            
            btnPrev.x = 70;
            btnNext.x = 110;
            
            addChild( btnPrev );
            addChild( btnNext );
            
            btnPrev.addEventListener( MouseEvent.CLICK, prevPage );
            btnNext.addEventListener( MouseEvent.CLICK, nextPage );
            
            updatePager();
        }
        
        private function nextPage( e:MouseEvent ) :void {
            //_currentPage = Math.min( _totalPages -1, _currentPage +1 );
            _pager.next();
            updatePager();
        }
        
        private function prevPage( e:MouseEvent ) :void {
            //_currentPage = Math.max( 0, _currentPage -1 );
            _pager.prev();
            updatePager();
        }
        
        
        private function updatePager():void {
            _numField.text = String( _pager.currentPage)+ "/" + _pager.totalPages + " Page";
        }

    }

}

import flash.display.Sprite;
import flash.text.TextField;

class PageButton extends Sprite {
    public function PageButton ( label:String ) {
        var textField: TextField = new TextField();
        textField.width = 36;
        textField.height= 24;
        textField.text = label;
        addChild( textField );
        mouseChildren = false;
        buttonMode = true;
    }
}
class Pager{
	 private var _currentPage:int;
     private var _totalPages:int;
     
     private var _numField:TextField;
     
     public function Pager(totalPages:int){
     	_currentPage = 0;
     	_totalPages= totalPages;
     }
     public function next():void{
     	_currentPage = Math.min( _totalPages -1, _currentPage +1 );
     }
     public function prev():void{
     	_currentPage = Math.max( 0, _currentPage -1 );
     }
     public function get currentPage():int{
     	return _currentPage+1;
     }
     public function get totalPages():int{
     	return _totalPages;
     }
     

}