first, what environment are you using to build this in? (I build in Flex and Flash so this may be a little biased)
I don't recognize PrintCancelled as a valid method. And I dont think Flash API has HTML as a method either.
when you test to do you get compiler errors? you probably should get at least 4.
Just breezing through your code, "var mySprite" cannot equal "new mySprite" you'll get : Error 1180: Call to a possibly undefined method mySprite.
No its not a compile issue. Sorry for the mistakes, I was just trying to simplify the code by removing unnecessary details from my production code.
You're right, it should read "new Sprite()". PrintCancelled is just an exception we defined, you can skip that.
html is of type mx:HTML (its a component for AIR).
My environment is Flex Builder 3.1.0, building for Adobe AIR 1.x.Flex framework 3.1.0.
The problem, in short is this. If I replace the whole HTML, HTMLLoader etc with any other component, say a text box, I can easily get the print. With HTMLLoader, I cannot.I get a blank page.
I tried so far
a. Printing after Event.Complete from HtmlLoader.
b. Printing after HTML_RENDER
c. Putting this in a simple AIR application, creating HTMLLoader in creationComplete handler and then printing on click of a button.
Only (c) works. Unfortunately, in our production system, we wanted to do this in the background depending on configuration (that is go to either an IP printer, or use PrintJob to print based on configuration).
Hope this helps.
1 person found this helpful
Perhaps the size of the HTML control is never properly set because it isn't in another container. Flex components expect to get layout information from their parent. You generally can't use Flex components outside of the Flex framework (Sprite is a basic Flash object and isn't part of the Flex framework). You don't really need the HTML component for this anyway, just use the plain HTMLLoader object (the variable named loader in your code).
After you set the size of the loader, you should wait for an event like render since the change isn't instantaneous.
However, I don't think you will be pleased with the results of printing HTML. For something simple like your example, you would be better off using the TextField (which can display basic HTML). For more complex layout, you could use the new Text Layout Framework (http://labs.adobe.com/technologies/textlayout/).