FlashPaper 2.0 ActionScript API

发布于:
分类: Script

FlashPaper 2.0 文件公开一个根级别的方法

 
  1. 		function getIFlashPaper():FlashPaper.IFlashPaper; 

这将返回一个对象,实现IFlashPaper接口。如果该方法没有定义,显然这个SWF文件不是Flashpaper的2.0文件。如果这个方法存在,并返回 null 或者 undefined,说明他是的Flashpaper的2.0文件但是没有完全加载,所以访问不了API,所以你必须等它完全加载。更多的信息请访问Loading FlashPaper 2.0 documents into Flash.

The IFlashPaper 的接口 ActionScript 2.0 如下:

		interface FlashPaper.IFlashPaper  
		{  
		  function addListener(listener:Object):Void;  
		  function removeListener(listener:Object):Void;  
		  function getViewerType():String;  
		  function getViewerVersion():Number;  
		  function getCurrentPage():Number;  
		  function setCurrentPage(pageNumber:Number):Void;  
		  function getNumberOfPages():Number;  
		  function getLoadedPages():Number;  
		  function showUIElement(part:String, flag:Boolean):Void;  
		  function printTheDocument():Boolean;  
		  function setCurrentZoom(percent:Object):Void;  
		  function getCurrentZoom():Number;  
		  function setSize(w:Number, h:Number):Boolean;  
		  function goToLinkTarget(linktarget:String, window:Object):Void;  
		  function enableScrolling(flag:Boolean):Boolean  
		  function getCurrentTool():String;  
		  function setCurrentTool(tool:String):Boolean;  
		  function getTextSelectionRange():FlashPaper.SelectionRange;  
		      function setTextSelectionRange(sel:FlashPaper.SelectionRange,  
		                        skipBroadcast:Boolean):Void;  
		  function getSelectedText():String;  
		  function getSidebarWidth():Number;  
		  function setSidebarWidth(w:Number):Void;  
		  function getFindText():String;  
		  function setFindText(s:String):Void;  
		  function findNext():Boolean;  
		  function getVisibleArea():Object;  
		  function setVisibleArea(area:Object, skipBroadcast:Boolean):Void;  
		}; 

这是一个方法–让我们看每一段。

IFlashPaper接口支持下列功能: 

addListener(listener:Object):Void;添加或删除各种事件的侦听器。您的听众可以得到以下活动:

onPageChanged(newPageNumber:Number):Void; 当前页(如工具栏)发生改变时的事件.

onZoomChanged(percent:Number):Void;当前缩放级别(在工具栏上操作)发生变化时的事件。

onSelection():Void; Broadcast when the current text selection in the document changes. (For efficiency, the new selection is not passed as an argument; you should call getTextSelectionRange() to get the new selection.)

onToolChanged(newTool:String):Void; Broadcast when the currently active tool (as displayed in the toolbar) changes.

onEnableScrolling(enable:Boolean):Void; Broadcast when scrolling is enabled or disabled, typically by a call to enableScrolling().

onVisibleAreaChanged():Void; Broadcast when any aspect of the visible area of the document changes, including zoom level and scroll position.

Other events might be broadcast, but those events might not be in future versions of FlashPaper. You should not rely on undocumented events broadcast by this mechanism.

removeListener(listener:Object):Void; Removes a listener added by addListener(). If the given object is not a listener for this FlashPaper document, the call does nothing.

getViewerType():String; Returns a string describing the type of user interface that is included in the document. The standard Macromedia FlashPaper viewer always returns the string Macromedia FlashPaper Default Viewer.

getViewerVersion():Number; Returns an integer indicating the version of the user interface code in this particular document. The returned integers are arbitrary and not necessarily consecutive, but larger numbers indicate recent revisions to the viewer, and might indicate bug fixes or enhanced functionality. FlashPaper 2.01 shipped with a viewer version number of 218.

getCurrentPage():Number; Returns the current page number (as displayed in the toolbar). The first page is page 1.

setCurrentPage(pageNumber:Number):Void; Sets the current page. The view scrolls as necessary to ensure the page is visible, but does not adjust zoom.

getNumberOfPages():Number; Returns the total number of pages in the document.

Note: All of the pages may not be able to be displayed yet, depending on the connection speed.

getLoadedPages():Number; Returns the total number of pages loaded (and able to be displayed) so far. This value must be between zero and getNumberOfPages(), inclusive. When getLoadedPages() == getNumberOfPages(), the document is fully loaded.

showUIElement(part:String, flag:Boolean):Void; 隐藏或显示文档中的Flashpaper的用户界面的一部分。当前支持,为部分案例敏感值如下:

“PrevNext” The Previous Page and Next Page toolbar buttons are hidden or shown.

Note: 如果这些按钮被隐藏,当前页的文本框被禁用,但不隐藏.

“Print” The Print toolbar button is hidden or shown.

“Tool” All tool selection buttons on the toolbar are hidden or shown.

“Zoom” All zoom-related controls on the toolbar are hidden or shown.

“Find” All text-search-related controls on the toolbar are hidden or shown.

“Pop” The Open Document in New Browser Window toolbar button is hidden or shown.

“Sidebar” The sidebar (displaying the document outline) is hidden or shown.

Note: 如果该文件没有大纲,它将被省略,因为没有从侧边栏显示的内容。

“Page” The Current Page and Number of Pages fields in the toolbar are hidden or shown.

“Overflow” The Overflow menu on the toolbar is hidden or shown.

Note: This menu appears only when the toolbar is too narrow to display all controls; you cannot use this call to force the Overflow menu to be visible.

“ZoomKeys” This value doesn’t affect the user interface; it is used to enable or disable various keys used to zoom in or out of the document (for example, +, -, p, w).

printTheDocument():Boolean; Simulates a user clicking the Print button. The document must be fully loaded before you call this function. This function returns false if the document is not fully loaded.

setCurrentZoom(percent:Object):Void; Sets the current zoom level. You can pass a number indicating a zoom percentage (for example, 100 for a 100% view). You can also pass the string width to zoom to the current fit-to-width magnification for this document, or pass the string page for the fit-to-page magnification.

getCurrentZoom():Number; Returns the current zoom level.

Note: The zoom level always returns as a number; width and page are never returned.

setSize(w:Number, h:Number):Boolean; Sets the display size of the document, in pixels. This function returns true if resize was successful, false if resize was unsuccessful. Generally speaking, this function fails (returns false) if the document isn’t fully loaded.

goToLinkTarget(linktarget:String, window:Object):Void; Handles an anchor or URL link request.

If the given string is a string of the form anchor:foo, the current view shifts to that anchor with a logical name of foo. The window argument is ignored in this case. If foo is not a valid anchor name in the document, no action is taken.

For all other strings, getURL(linktarget, window) is called. (For more information, see the ActionScript documentation for this function.)

enableScrolling(flag:Boolean):Boolean Used to prevent the user from scrolling the document.

When scrolling is disabled, the following is true:

The scroll bar is disabled, but visible. Panning (using the pointing hand) is disabled. Scrolling using the mouse wheel is disabled. The return value is the previous value of this flag.

getCurrentTool():String; Returns the currently active tool. If no tool is active, an empty string is returned.

The following are currently supported values:

“” (no tool) “pan” (hand tool) “select” (text selection tool) setCurrentTool(tool:String):Boolean; Makes the given tool the active tool. This function returns false if the argument is invalid or the given tool is disabled.

The following are currently supported values:

“” (no tool) “pan” (hand tool) “select” (text selection tool) getTextSelectionRange():FlashPaper.SelectionRange; Returns an object describing the current text selection. If no text is selected, this function returns null.

Note: Unlike the object returned by getVisibleArea(), this call always returns a FlashPaper.SelectionRange, which is a well-defined object that you can examine, decompose, or construct new instances of.

setTextSelectionRange(sel:SelectionRange, skipBroadcast:Boolean):Void; Selects the given range of text. You may pass null to deselect all text. Invalid ranges are clipped to document ranges (this allows you to set a range that begins with zero and ends with a large number, such as 999999, to select the entire document).

If skipBroadcast is false (or omitted), onVisibleAreaChanged() is broadcast to listeners as necessary. If skipBroadcast is true, onVisibleAreaChanged() is never broadcast to listeners.

Note: Unlike the object expected by setVisibleArea(), this call always expects a FlashPaper.SelectionRange, which is a well-defined object that you can examine, decompose, or construct new instances of.

getSelectedText():String; Returns the selected text as a Unicode string. If no text is selected, an empty string is returned.

getSidebarWidth():Number; Returns the width of the sidebar. A document with no outline always returns zero.

setSidebarWidth(w:Number):Void; Sets the width of the sidebar. Pass zero to hide the sidebar completely. A document with no outline ignores this call.

getFindText():String; Returns any text in the Find text box as a Unicode string.

setFindText(s:String):Void; Sets the text in the Find text box to a Unicode string value. This call does not perform a find operation or alter the current selection.

findNext():Boolean; Searches for the text in the Find text box. The search begins from the end of the current selection. To start from the beginning of the document, call setSelectionRange(null) first. Returns true if text is found, false if not. If text is found, the specific range can be found by calling getTextSelectionRange().

getVisibleArea():Object; 返回一个 描述了文档的当前可见区域的对象。

你可以使用返回值来执行下列操作之一:

如果同一个文件在多台计算机显示,并且你要保持显示区域同步。通过setVisibleArea()可能是很有用的.

通过比较以前的返回值和getVisibleArea()以确定可视区域是否发生了变化。 返回的对象应被视为一个不透明的数据类型。不要试图分解返回的对象,因为它的内容和形式可能会在将来版本中改变。

 唯一的公共成员对象,我们保证将来版本中该方法的保证是:

function equals(that:Object):Boolean;

你可以用它来比较两个显示的领域,确定他们是否是相同的。

setVisibleArea(area:Object, skipBroadcast:Boolean):Void; 调整当前可见页面/缩放/滚动到匹配的显示区域的对象描述。

如果 skipBroadcast 为假 (或者省略), onVisibleAreaChanged() 是监听的必要条件。反之, onVisibleAreaChanged()不会监听。

这个对象必须是前一个getVisibleArea()返回的。 不要试图建立自己的对象,因为内容和形式可能会在将来版本中改变。

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注