5 Replies Latest reply on Sep 5, 2006 11:58 AM by Kirk_Holbrook

    FlashPaper 2 API calls in Flex 2?

    Kirk_Holbrook
      Does anyone know if you can access the FlashPaper 2 methods within a Flex 2 application?

      I can get it to display my FlashPaper file, but not resize it appropriately or get the current page, etc.

      Thanks,
      K___H
        • 1. Re: FlashPaper 2 API calls in Flex 2?
          inlineblue Level 1
          AFAIK, you can't. Flex 2 isn't able to script AS2 SWFs, which is basically what FlashPaper is. I think you're stuck until they update FlashPaper to AS3 (if they bother to, that is).
          • 2. Re: FlashPaper 2 API calls in Flex 2?
            refugeo
            <cfform name="myform" ....> Then do <cfoutput><pre><xmp>#myform#</xmp></pre></cfoutput> to get the generated MXML from Flash forms
            • 3. Re: FlashPaper 2 API calls in Flex 2?
              Kirk_Holbrook Level 1
              Got it! You use LocalConnection.

              LocalConnection will work when both SWFs are loaded in the same instance, so this works fine.

              I'm still working on the finer points, but if anyone needs some code, just post your reply here.

              Thanks,
              K___H
              • 4. Re: FlashPaper 2 API calls in Flex 2?
                flexdude
                Hi K____H

                Looks like you are further than anyone else regarding the integration of Flashpaper 2 into Flex2.
                Could you please post your code in the forum so I can give it a try?

                many thanks
                george
                • 5. FlashPaper 2 API calls in Flex 2?
                  Kirk_Holbrook Level 1
                  Hi FlexDude,

                  I haven't had a chance to clean things up much, as I've been sidetracked with other issues, but here's some code.

                  Create an FLA with Flash 8. Insert the following code in the first frame:
                  //begin Flash code
                  var fpClip = createEmptyMovieClip("flashpaper",1);
                  var fp;
                  _root.flashpaper._visible = false;
                  var receiving_lc:LocalConnection = new LocalConnection();
                  receiving_lc.loadFlashPaper = function(fpFile:String, width:Number, height:Number, loadedObj:Object) {
                  loadFP(fpFile, width, height, loadedObj);
                  };
                  receiving_lc.getCurrentPage = function() {
                  getCurrentFPPage();
                  }
                  receiving_lc.setCurrentPage = function(thePage:Number) {
                  setFPCurrentPage(thePage);
                  }

                  function loadFP(fpFile:String, width:Number, height:Number, loadedObj:Object) {
                  var intervalID = 0;
                  var loadFunc = function() {
                  _root.flashpaper._visible = false;
                  fp = _root.flashpaper.getIFlashPaper();
                  if (!fp)
                  return;
                  if (fp.setSize(width, height) == false)
                  return;
                  _root.flashpaper._visible = true;
                  clearInterval(intervalID);
                  loadedObj.onLoaded(fp);
                  };
                  intervalID = setInterval(loadFunc, 100);
                  _root.flashpaper.loadMovie(fpFile);
                  };

                  function getCurrentFPPage() {
                  var sending_lc:LocalConnection = new LocalConnection();
                  sending_lc.send("Flex2", "setCurrentFPPage", fp.getCurrentPage());
                  delete sending_lc;
                  }

                  function setFPCurrentPage(thePage:Number) {
                  fp.setCurrentPage(thePage);
                  }

                  receiving_lc.connect("FlashPaper2");
                  // end Flash code

                  Then create your Flex2 Application Add some buttons to trigger the following code. Sample code (but this is not a complete app):
                  private var receiving_lc:LocalConnection;
                  private var currentFPPage:int;

                  private function initApp():void {
                  receiving_lc = new LocalConnection("Flex2",this);
                  }

                  private function loadFlashPaper():void {
                  var sending_lc:LocalConnection = new LocalConnection();
                  sending_lc.send("FlashPaper2", "loadFlashPaper", "332ldstLNParaBreak.swf", draft.width, draft.height, null);
                  }

                  private function getFPPage():void {
                  var sending_lc:LocalConnection = new LocalConnection();
                  sending_lc.send("FlashPaper2", "getCurrentPage");
                  }

                  private function setFPCurrentPage(thePage:int):void {
                  var sending_lc:LocalConnection = new LocalConnection();
                  sending_lc.send("FlashPaper2", "setCurrentPage", thePage);
                  }

                  // the following function sets the current page in the Flex app, that is received from the Flash FlashPaper SWF.
                  public function setCurrentFPPage(theValue:int):int {
                  currentFPPage = theValue;
                  Alert.show("currentFPPage: " + currentFPPage);
                  }

                  I hope this helps. I chopped this up from my more thorough tests -- where I tested a lot of the FlashPaper 2 API methods. Hopefully I'll get a chance to elaborate on this a bit at some point.

                  Good luck,
                  K___H