Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Set actionsEnabled Property of a Flash Member
Compound Interest
Importing Externally Linked Flash members
MMX
Macromedia Director 7: Creating Powerful Multimedia
DirectOS Xtra
True Lingo Color Wheel 1.0
Get the computer name of user
Update QT3 movies
Indeo Video
 

 

 

Behavior Flash Paper 1.01 Controller

Added on 11/25/2003

 

Compatibilities:
behavior D8 D8_5 D9 Mac PC Shockwave

Rating:

Author: MediaMacros (website)

This behavior controls Flash Paper 1.01 and later. The full API is available online at http://www.macromedia.com/support/documentation/en/contribute/2/flashpaper_api/flashpaper_api03.html This will not function with Flash paper 1.0. You need to install the FP/Contribute 2.01 patch.

Download PC Source
--Copyright 2003 MediaMacros, Inc.
--Special thanks to Steven Johnson at Macromedia for work on initial scaling
--Works with Flash Paper 1.1 and higher

property spriteNum
property pRoot
property pFlashPaper
property pInitialize
property pSize
property pDisplayUI
property pZoomCallback
property pPageCallback

--##Private Methods##--
on getPropertyDescriptionList me
  p = [:]
  p.addProp(#pDisplayUI, [#format : #boolean, #comment : "Show default UI?" , #default : 1])
  p.addProp(#pZoomCallback, [#format : #string, #comment : "Global Handler to call on Zoom" , #default : "zoom"])
  p.addProp(#pPageCallback, [#format : #string, #comment : "Global Handler to call on Page Change" , #default : "page"])
  return p
end

on isOkToAttach me, vSpriteType, vSpriteNumber
  --only use on a flash sprite
  if sprite(vSpriteNumber).type <> #flash then
    return false
  else
    return true
  end if    
end

on beginSprite me
  if sprite(spriteNum).member.type = #flash then
    pSize = [sprite(spriteNum).width, sprite(spriteNum).height]
    pInitialize = 1
    --use a point for center
    sprite(spriteNum).originMode = #point
    --set the origin
    sprite(spriteNum).originH = sprite(spriteNum).width/2
    sprite(spriteNum).originV = sprite(spriteNum).height/2
    --set the scale mode to none (scales itself)
    sprite(spriteNum).scaleMode = #noScale    
  end if
end

on exitFrame me
  if pInitialize then
    --initialize after 1 frame for best playback
    pRoot = sprite(spriteNum).getVariable("_root", 0)    
    pFlashPaper = pRoot.isFlashPaperDocument()
    --validate flash paper
    if pFlashPaper <> 1 then exit
    --check the ui
    if pDisplayUI then
      me.showAllUI()
    else  
      me.hideAllUI()
    end if
    
    --set up the callbacks
    sprite(spriteNum).setCallback(pRoot, "onPageChanged", #pageChanged, me)
    sprite(spriteNum).setCallback(pRoot, "onZoomChanged", #zoomChanged, me)
    pInitialize = 0    
  end if
end

--##Callbacks##--
on zoomChanged me,  vZoom
  if not pFlashPaper then return 0
  if pZoomCallback = "" then
    put me.getCurrentZoom()
  else
    do pZoomCallback && me.getCurrentZoom()
  end if
end


on pageChanged me, vPage
  if not pFlashPaper then return 0
  if pPageCallback = "" then
    put me.getCurrentPage()
  else
    do pPageCallback && me.getCurrentPage()
  end if
end


--##Public Methods##--
----Page Methods----
on getCurrentPage me
  if not pFlashPaper then return 0
  --returns the current page number
  return pRoot.getCurrentPage()
end

on setCurrentPage me, vPage
  if not pFlashPaper then return 0
  --sets the current page so that its at least partially visible
  vPage = integer(vPage)
  if ilk(vPage) <> #integer then exit
  if vPage > me.getLoadedPages() then
    alert "Please wait for the document to finish loading."
    exit
  end if
  pRoot.setCurrentPage(vPage)
  return 1
end

on goFirstPage me
  --goes to the first page in the document
  me.setCurrentPage(1)
end

on goNextPage me
  me.setCurrentPage(min(me.getNumberOfPages(), me.getCurrentPage() + 1))
end

on goLastPage me
  me.setCurrentPage(me.getNumberOfPages())
end

on goPreviousPage me
  me.setCurrentPage(max(1, me.getCurrentPage() - 1))
end


on getNumberOfPages me
  if not pFlashPaper then return 0
  --Returns the total number of pages
  return pRoot.getNumberOfPages()
end

on getViewerType me
  if not pFlashPaper then return 0
  --Returns a string describing the type of the viewer. The standard Macromedia-provided Viewer will always return "Macromedia FlashPaper Default Viewer".
  return pRoot.getViewerType()
end

on getViewerVersion me
  if not pFlashPaper then return 0
  --Returns an integer indicating the revision of this particular viewer type. Viewer 1.0 did not implement this function. Viewer 1.01 returns the integer 2.
  return pRoot.getViewerVersion()
end

on getLoadedPages me
  if not pFlashPaper then return 0
  --Return the number of pages loaded so far. This will always be an integer between 0 and getNumberOfPages(), inclusive.
  return pRoot.getLoadedPages()
end


----Customize the UI Methods----
on showAllUI me
  if not pFlashPaper then return 0
  me.showPrevNextUI()  
  me.showPrintUI()
  me.showZoomUI()
  return 1
end

on hideAllUI me
  if not pFlashPaper then return 0
  me.hidePrevNextUI()
  me.hidePrintUI()
  me.hideZoomUI()
  return 1
end

on showPrevNextUI me
  if not pFlashPaper then return 0
  --Displays the "previous-page/next-page" user interface.
  pRoot.showPrevNextUI( true )
  return 1
end

on hidePrevNextUI me
  if not pFlashPaper then return 0
  --Hides the "previous-page/next-page" user interface.
  pRoot.showPrevNextUI( false )
  return 1
end

on showPrintUI me
  if not pFlashPaper then return 0
  --Displays the "print" user interface.
  pRoot.showPrintUI( true )
  return 1
end

on hidePrintUi me
  if not pFlashPaper then return 0
  --Hides the "print" user interface.
  pRoot.showPrintUI( false )
  return 1
end

on showZoomUI me
  if not pFlashPaper then return 0
  --Displays all magnification-related user interface controls.
  pRoot.showZoomUI( true )
  return 1
end

on hideZoomUI me
  if not pFlashPaper then return 0
  --Hides all magnification-related user interface controls.
  pRoot.showZoomUI( false )
  return 1
end

----Zoom/Size Methods----
on setCurrentZoom me, vPercent
  if not pFlashPaper then return 0
  vPercent = float(vPercent)
  if ilk(vPercent) = void then
    alert "Not a valid percent zoom value."
    exit
  end if
  --Set the current zoom to the given percentage. In addition to numeric values, you may pass "width" to fit the width into the view, and "page" to fit the page into the view.
  ok = pRoot.setCurrentZoom(vPercent)
  if ok = 0 then
    alert "Unsuported zoom value"
  end if
  return 1
end

on getCurrentZoom me
  if not pFlashPaper then return 0
  --Return the current zoom level. Only numeric values will be returned (never "width" or "page"). If the viewer doesn't support varying zoom levels, this function will return zero.
  return pRoot.getCurrentZoom()
end

on zoomIn me
  --simple zoom using 2X
  z = me.getCurrentZoom()
  me.setCurrentZoom(z * 2)
end

on zoomOut me
  --simple zoom out based on 1/2
  z = me.getCurrentZoom()
  me.setCurrentZoom(z / 2)
end

on setSize me, vWidth, vHeight
  if not pFlashPaper then return 0
  --Set the display size of the SWF, in pixels. Returns true if resize was successful, false if not.
  --Note that this call will return false until (at least) the first page of the document has loaded, so you may need to call it repeatedly until true is returned.
  ok = pRoot.setSize(vWidth, vHeight)
  if ok = false then
    alert "Unable to set size"
  else
    pSize = [vWidth, vHeight]
  end if
  return 1
end

on getSize me
  if not pFlashPaper then return 0
  --returns the size of the current sprite
  return pSize
end

----Print Methods----
on print me
  if not pFlashPaper then return 0
  --Open the print dialog. (Basically, behave exactly as though the user had clicked the "print" button.) Returns true if successful, false if not.
  ok = pRoot.printTheDocument()
  if ok = false then
    alert "There was an error printing the document."
    return 0
  end if
  return 1
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail