package { import flash.utils.getDefinitionByName; public class BookAPI { private static var theBook:*; private static var once:Boolean = false; public function BookAPI() { } private static function bookRef():* { if (!once) { theBook = getDefinitionByName("com.oxylusflash.book.Global")["theBook"]; once = true; } return theBook; } /** * Jump to page index. * @param pageIndex Page index starting from 1. */ public static function jumpToPageIndex(pageIndex:int):void { if (bookRef()) bookRef().jumpTo(pageIndex - 1); } /** * Jump to page id. * @param pageId Page id. */ public static function jumpToPageId(pageId:String):void { if (bookRef()) bookRef().jumpTo(bookRef().pageIdToIndex(pageId)); } /** * Jump to next page. */ public static function nextPage():void { if (bookRef()) bookRef().nextPage(); } /** * Jump to previous page. */ public static function prevPage():void { if (bookRef()) bookRef().prevPage(); } /** * Jump to first page. */ public static function firstPage():void { if (bookRef()) bookRef().jumpToFirst(); } /** * Jump to last page. */ public static function lastPage():void { if (bookRef()) bookRef().jumpToLast(); } /** * Total pages. */ public static function get totalPages():int { if (bookRef()) return bookRef().numPages; return 0; } /** * Current left page index, starting from -1. */ public static function get currentLeftPage():int { if (bookRef()) return bookRef().leftPageIndex; return -2; } } }