Actionscript 3.0 form wiith user inputs and calculated fields saves empty as a PDF using AlivePDF

351 views Asked by At

I've created a form that has lines, static text, and textFields in Flash Professional CS5.5, and using Actionscript 3.0 created fields that accepts a user's inputs and then calculates those user inputs and stores them in fields the user cannot edit. I need to print the filled-in form as a PDF and am using AlivePDF for this. The script creates the PDF but it is blank. How to I capture the entire stage as a PDF?

Here's the code in the .as file.

package  {
        // Flash imports
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.display.SimpleButton;
        import flash.text.*;
        import fl.controls.CheckBox;
        import fl.accessibility.CheckBoxAccImpl; 
        import fl.controls.Button;
        import flash.filesystem.File;
        import flash.filesystem.FileStream;
        import flash.net.FileReference;
        import flash.net.FileReferenceList;
        //import flash.display.Sprite;
        import flash.media.CameraRoll;
        import flash.display.StageScaleMode;
        import flash.media.MediaPromise;
        import flash.events.MediaEvent;
        import flash.events.Event;

        //AlivePDF imports
        import org.alivepdf.pdf.PDF;
        import org.alivepdf.layout.Orientation
        import org.alivepdf.layout.Size;
        import org.alivepdf.layout.Unit;
        import org.alivepdf.display.Display
        import org.alivepdf.saving.Method;
        import org.alivepdf.fonts.FontFamily;
        import org.alivepdf.fonts.Style;
        import org.alivepdf.colors.RGBColor;
        import org.alivepdf.images.ImageFormat;
        import org.alivepdf.saving.Download;
        import org.alivepdf.layout.Layout;

        public class mfDataCollection extends MovieClip {

            public function mfDataCollection() {
                init();
            }

            private function init():void {
                CheckBoxAccImpl.enableAccessibility();
                stage.focus = testDate;
                focusRect  = testDate;
                testDate.tabIndex = 1;  
                outsideTemp.tabIndex = 2; 
                buildingNumber.tabIndex = 3; 
                unitNumber.tabIndex = 4; 
                CAZ1AmbientCO.tabIndex = 5; 
                CAZ1Doors.tabIndex = 6; 
                CAZ1Fireplace.tabIndex = 7; 
                CAZ1CombustionAppliances.tabIndex = 8; 
                CAZ1Baseline.tabIndex = 9; 
                CAZ1Baseline.restrict = "-9-9";
                CAZ1Dryer.tabIndex = 10;
                CAZ1Dryer.restrict = "-9-9";
                CAZ1CheckUnderDoors.tabIndex = 11;
                CAZ1CheckUnderDoors.restrict = "-9-9";
                CAZ1AirHandler.tabIndex = 12;
                CAZ1AirHandler.restrict = "-9-9";
                CAZ1RecheckPressure.tabIndex = 13;
                CAZ1RecheckPressure.restrict = "-9-9";
                CAZ1SetToWC.tabIndex = 14;
                CAZ1WC.tabIndex = 15;
                CAZ1BaselineCopy.tabIndex = 15;
                CAZ1WCD.tabIndex = 16;
                CAZ1DepressurizationLimitsPassed.tabIndex = 17;
                CAZ1Monoxer.tabIndex = 18;
                CAZ1App1SmallestBTU.tabIndex = 19;
                CAZ1App1SpilliagePassed.tabIndex = 20;
                CAZ1App1AmbientCO2.tabIndex = 21;
                CAZ1App1AmbientCO2.restrict = "-9-9";
                CAZ1App1Draft.tabIndex = 22;
                CAZ1App1Draft.restrict = "-9-9";
                CAZ1App1DraftPassed.tabIndex = 23;
                CAZ1App1SpillageFailed.tabIndex = 24;
                CAZ1App1UndilutedCO.tabIndex = 25;
                CAZ1App1UndilutedCO.restrict = "-9-9";
                CAZ1App1ActionLevelsPassed.tabIndex = 26;
                CAZ1CompleteApp2.tabIndex = 27;
                CAZ1App2TestRequired.tabIndex = 28;
                ResetHousetoNormal.tabIndex = 29;
                OvenCO.tabIndex = 30;
                OvenCO.restrict = "0-9";
                LeftRearBurner.tabIndex = 31;
                LeftRearBurner.restrict = "0-9";
                LeftFrontBurner.tabIndex = 32;
                LeftFrontBurner.restrict = "0-9";
                RightFrontBurner.tabIndex = 33;
                RightFrontBurner.restrict = "0-9";
                RightRearBurner.tabIndex = 34;
                RightRearBurner.restrict = "0-9";
                RightFrontBurner.tabIndex = 35;
                CAZ1Dimensions.tabIndex = 36;
                CAZ2Dimensions.tabIndex = 37;
                GasLeakTestingPassed.tabIndex = 38;
                Notes.tabIndex = 39;
                IOUWorkOrder.tabIndex = 40;


                // Setup handlers for mouse clicks
                CAZ1Dryer.addEventListener(MouseEvent.CLICK, handleMouseClicks);
                CAZ1CheckUnderDoors.addEventListener(MouseEvent.CLICK, handleMouseClicks);
                CAZ1AirHandler.addEventListener(MouseEvent.CLICK, handleMouseClicks);
                CAZ1RecheckPressure.addEventListener(MouseEvent.CLICK, handleMouseClicks);
                CAZ1WC.addEventListener(MouseEvent.CLICK, handleMouseClicks);
                CAZ1BaselineCopy.addEventListener(MouseEvent.CLICK, handleMouseClicks);
                CAZ1WCD.addEventListener(MouseEvent.CLICK, handleMouseClicks);
            }

            private function handleMouseClicks(event:MouseEvent):void {

                var numCAZ1Baseline:Number = Number(CAZ1Baseline.text);
                var numCAZ1Dryer:Number = Number(CAZ1Dryer.text);
                var numCAZ1CheckUnderDoors:Number = Number(CAZ1CheckUnderDoors.text);
                var numCAZ1AirHandler:Number = Number(CAZ1AirHandler.text);
                var numCAZ1RecheckPressure:Number = Number(CAZ1RecheckPressure.text);
                var numCAZ1WC:Number = Number(CAZ1WC.text);
                var numCAZ1BaselineCopy:Number = numCAZ1Baseline;

                numCAZ1WC = Math.min(numCAZ1Dryer, numCAZ1CheckUnderDoors, numCAZ1AirHandler, numCAZ1RecheckPressure);
                CAZ1WC.text = String(numCAZ1WC);
                CAZ1BaselineCopy.text = String(numCAZ1BaselineCopy);
                var numCAZ1WCD:Number = Number(CAZ1WCD.text);
                numCAZ1WCD = numCAZ1WC - numCAZ1Baseline;
                CAZ1WCD.text = numCAZ1WCD.toFixed(1);
            }

            private function handleButtonClicks(event:MouseEvent):void {
                trace("You have clicked: " + event.currentTarget.name);
                var filename:String; // = "CAZ_Bldg-" + buildingNumber.text + "-" + unitNumber.text + ".pdf";
                var myPDF:PDF;
                switch (event.currentTarget.name) {
                    case "btnSaveAsFileButton":
                        exportPDF();
                        break;
                    default:
                        trace("You clicked something else");

                }
            }

            public function exportPDF() : void {
                var filename:String = "CAZ_Bldg-" + buildingNumber.text + "-" + unitNumber.text + ".pdf";
                trace("You are saving " + filename);
                var myPDF = new PDF(Orientation.PORTRAIT, Unit.INCHES, Size.A4);
                myPDF.setDisplayMode (Display.FULL_PAGE, Layout.SINGLE_PAGE);
                myPDF.addPage();
                var f:FileStream = new FileStream();
                        var file:File = File.userDirectory.resolvePath( filename );
                f.open( file, FileMode.WRITE);
                var bytes:ByteArray = myPDF.save(Method.LOCAL);
                f.writeBytes(bytes);
                f.close();
            }

        } // End of mfDataCollecion class

    } // End of package
0

There are 0 answers