Data::PageをActionScript2.0に移植
Data::PageをActionScript2.0に移植しました。
元のバージョンは1.03、「$」を「this.」に変えて、メソッドの後ろに「()」を付けただけ。これでものぐさできます。
class Data.Page { var TOTAL_ENTRIES:Number; var ENTRIES_PER_PAGE:Number; var CURRENT_PAGE:Number; function Page(total_entries:Number, entries_per_page:Number, current_page:Number) { this.TOTAL_ENTRIES = total_entries; this.ENTRIES_PER_PAGE = entries_per_page; this.CURRENT_PAGE = current_page; } /* total_entries */ function total_entries():Number { return this.TOTAL_ENTRIES; } /* entries_per_page */ function entries_per_page():Number { return this.ENTRIES_PER_PAGE; } /* entries_on_this_page */ function entries_on_this_page():Number { if (this.total_entries() == 0) { return 0; } else { return this.last()-this.first()+1; } } /* current_page */ function current_page():Number { return this.CURRENT_PAGE; } /* first_page */ function first_page():Number { return 1; } /* last_page */ function last_page():Number { var page:Number = this.total_entries()/this.entries_per_page(); if (page == Math.floor(page)) { return page; } else { return 1+Math.floor(page); } } /* first */ function first():Number { if (this.total_entries() == 0) { return 0; } else { return ((this.current_page()-1)*this.entries_per_page())+1; } } /* last */ function last():Number { if (this.current_page() == this.last_page()) { return this.total_entries(); } else { return (this.current_page()*this.entries_per_page()); } } /* previous_page */ function previous_page():Number { if (this.current_page()>1) { return this.current_page()-1; } else { return null; } } /* next_page */ function next_page():Number { if (this.current_page()<this.last_page()) { return this.current_page()+1; } else { return null; } } /* skipped */ function skipped():Number { return this.first()-1; } /* splice */ function splice(array:Array):Array { return array.slice(this.skipped(), this.last()); } } </pre>