1 Reply Latest reply on Sep 8, 2009 4:24 PM by _The Madness_

    problems with printJob() class

    Level 7

      I am quite certain I am fighting with a bug here, but I need some comment
      from officials...

      My development environment: MM Flash MX 2004, Player version WIN 7,0,14,0
      Tested also on WIN 9,0,28

      I am trying to develop a "flash report generator" that would allow to forget
      all the pesky details of how the printJob() class works. Among other nifty
      things like page format control, precision positioning, event-driven page
      formatting, etc, a very important feature is ability to create multi-page
      report, with pages that require some time to get ready. Typical example
      would be page with several images that are loaded from URLs.

      What I found out, it seems that FlashPlayer expects that all the calls to
      the PrintJob.addPage() method occour in the same thread. Well, I don't know
      if it's correct to use term "thread" here, but point is, if the player ticks
      a single frame after PrintJob.start() was called, it will no more be
      possible to add a single page.

      It is easy to test:
      1. Create a movie, have two layers. One layer spans two frames, other has
      two keyframes, where AS will go.
      2. Put a whatever movieclip in the layer that spans two frames, give it an
      instance name "mc".
      3. Write this code in the frames of the other layer (with two keyframes)

      //Code in frame 1:
      var pj:PrintJob = new PrintJob();

      // Code in frame 2:
      delete pj;

      Run this movie, and you'll see how this doesn't work. However, if you'd put
      all that code in Frame one, all runs fine.

      Another simple test:
      Create a one-frame movie, put a button on stage. Attach this event code:

      on (release) {
      _root.pj = new PrintJob();
      _root.counter = 3;
      _root.onEnterFrame = function() {
      if (this.counter == 0) {
      delete this.pj;

      Should have printed a document with three pages with the stage image. No
      luck either.

      Here's another funny (undocumented) behaviour:

      //Code in frame 1:
      var pj:PrintJob = new PrintJob();

      The Flash player will print the clip anyway, even thou it's not asked to -
      PrintJob.send() method is never called.

      Now, it is possible to workaround this bug, sort of. But that means, that to
      finish my report generator, I will need to first build all the pages of the
      report, in several dynamically-created movieclips (could be hundred), wait
      until all the content is loaded, and only then do PrintJob.start() and add
      every page in primitive cycle. But, it's sort of compromise, because:
      1) It will take a lot of memory to host every page of complex repor on
      stage, simultaneously
      2) report can not be generated, knowing the actual dimensions of the paper
      (they become available only after successful call to PrintJob.start()

      So, I would be happy to hear some official word on this.


      Pavils Jurjans