Posted by: prashantbhagwat | June 5, 2008

Multi Page printing in Flash MX using Javascript

Hi,

Using Flash MX, we are not able to print the data in multiple page. If we try to print the movieclip which has text to print and this movieclip exceeds the page limit, Flash print function compress the data into single page.

To over come this problem, we have another way to print the data using Javascript.

Lets see how to do it -

Step 1: Create a flash file from where we need to print the multipage data. Which have input text field and print button. Print button will call fscommand as fscommand (“printContent”);

Step 2: Publish the Flash file as Flash with FSCommand.

Step 3: Add switch statement in published HTML which will handle the FSCommand send by Flash.

        switch (command)
        {
           case “printContent”:
                   var str = “<html><body>”
                  str = str + args;
                  str = str + “</body></html>”
                  parent.forPrintFrame.document.write(str);
                 fnPrintContent ();
                 break;
       }

And some more script as -

var t;
function fnPrintContent ()
{
 t = setTimeout(“parent.fnPrint();”,1000);
}

fnPrintContent will call another function, fnPrint (which is present in parent frame) after 1 second.

Step 4: Create a empty HTML file as PrintData.html

Step 5: Now create index.html which has 2 frames like -

<FRAME SRC=”flashFile.html” NAME=”content” NORESIZE  FRAMEBORDER=”NO”>
 <FRAME SRC=”PrintData.html” id=”printFrm” NAME=”forPrintFrame” NORESIZE FRAMEBORDER=”NO”>

First frame has published flash file and second frame will have empty html file.

Now add following function in index.html file -

function fnPrint ()
{
 window.clearTimeout(content.t);
 window.forPrintFrame.focus ();
 window.print ();
}

Step 6: Now run the index.html file, write some data in flash file and click the Print button.

 


Leave a response

You must be logged in to post a comment.

Categories