Skip to main content
Inspiring
April 7, 2009
Answered

help with compiling error

  • April 7, 2009
  • 2 replies
  • 966 views

package com.wiley.as3bible.printing {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.printing.PrintJob;
   
    public class Printing extends Sprite {
       
        private var _printableContent:Sprite;
        private var _textField:TextField;
        private var _loader:URLLoader;
       
        public function Printing() {
           
            //Load the text from a text file
            _loader = new URLLoader();
            _loader.load(new URLRequest("http://www.rightactionscript.com/samplefiles/lorem_ipsum.txt"));
            _loader.addEventListener(Event.COMPLETE, completeHandler);
            //Create a multiline text field that autosizes.
            _textField = new TextField();
            _textField.width = 400;
            _textField.multiline = true;
            _textField.wordWrap = true;
            _textField.autoSize = TextFieldAutoSize.LEFT;
           
            //Create a sprite container for the text field,
            //and add the text field to it.
            _printableContent = new Sprite();
            addChild(_printableContent);
            _printableContent.addChild(_textField);
        }
       
        //When the text loads add it to the text field and  then print the text
        private function completeHandler(event:Event):void {
            _textField.text = _loader.data;
           
            var printJob:PrintJob = new PrintJob();
            if (printJob.start()) {
                printJob.addPage(_printableContent);
                printJob.send();
            }
        }
    }
}

the compiling error is:

1046: Type was not found or was not a compile-time constant: PrintJob.

1180: Call to a possibly undefined method PrintJob.

can anyone explain this to me?

This topic has been closed for replies.
Correct answer funkysoul

the .as file you posted above needs to be saved with the name of Printing and should be on your root directory inside of the folder structure

com.wiley.as3bible.printing

eg. "c:\test\com\wiley\as3bible\printing\Printing.as"

and your fla file is here:

"c:\test\myPrinting.fla"

btw.. your .as file always needs to carry the exact same name as you type in the "public class xxxx extends Sprite"

2 replies

funkysoul
Inspiring
April 7, 2009

Hmm.. I've just copy&pasted your code and it worked out for me..

The error you get from the output panel is a message saying that Flash can't find the PrintJob class.

But why exactly it does that.. hmmm...

Btw. which flash version are you using and which flash player version are you targetting?

Inspiring
April 7, 2009

I think I am confused as to what I need to name the .as file and what I put in the document class window in the .fla file.

funkysoul
funkysoulCorrect answer
Inspiring
April 7, 2009

the .as file you posted above needs to be saved with the name of Printing and should be on your root directory inside of the folder structure

com.wiley.as3bible.printing

eg. "c:\test\com\wiley\as3bible\printing\Printing.as"

and your fla file is here:

"c:\test\myPrinting.fla"

btw.. your .as file always needs to carry the exact same name as you type in the "public class xxxx extends Sprite"

April 7, 2009

The class used as a type declaration is either unknown or is an expression that could have different values at run time. Check that you are importing the correct class and that its package location has not changed. Also, check that the package that contains the code (not the imported class) is defined correctly (for example, make sure to use proper ActionScript 3.0 package syntax, and not ActionScript 2.0 syntax).