Pages: [1]
  Print  
Author Topic: print part of a screen  (Read 314 times)
squarenine
Gaia Novice
*
Posts: 7


« on: August 11, 2011, 11:19:13 AM »

Hi,

I made a color game and I want to add a print function to print a part of the page.

This is what I have:

Code:
assets.printer.x = 20;
assets.printer.y = 20;
assets.printer.addEventListener(MouseEvent.MOUSE_DOWN, printerEvent);
assets.printer.visible = true;

}

private function printerEvent(event:MouseEvent):void {
var pj = new PrintJob();
        var success = pj.start();
if (success) {
                pj.addPage (0, {xMin : 200, xMax: 1200, yMin: 300, yMax: 800});
                pj.send();
        }
}

This is the error I get :

Code:
TypeError: Error #1034: Type Coercion failed: cannot convert 0 to flash.display.Sprite.
at pages::ColorPage/printerEvent()

Anybody got an idea how to do this?

Thanks in advance!
Logged
Ramiro
Moderator
Gaia Addict
*****
Posts: 861


interactive pragmatism


« Reply #1 on: August 11, 2011, 08:03:25 PM »

looks quite obvious, the addPage method expects a Sprite as the first param, you're passing a number 0...
Logged
squarenine
Gaia Novice
*
Posts: 7


« Reply #2 on: August 13, 2011, 06:23:18 AM »

Thanks for the reply but

public function addPage(target:Sprite, printArea:Rectangle = null, options:PrintJobOptions = null, frameNum:int = 0):void

Quote
The target is the movieclip to be printed. The name of the movieclip should be in quotation marks. If you want to print the stage (_root), you should set this to 0 (as in _level0); to print a level, enter the number for that level.

But this doesnt work, and assets.color1, assets.color1.loader or container doesnt work.

Is there a way how I can do this?

Thanks in advance.
Logged
Ramiro
Moderator
Gaia Addict
*****
Posts: 861


interactive pragmatism


« Reply #3 on: August 13, 2011, 07:00:46 PM »

ok, addPage is a method from a custom library, and the error you're seeing is clearly from that library. Not sure what could it be...
Logged
squarenine
Gaia Novice
*
Posts: 7


« Reply #4 on: August 27, 2011, 06:59:16 AM »

Thanks for the reply!

I don't think PrintJob is a custom library, but build in AS3.

Is there a way to convert asset sprite to a normal sprite ?

I get this error

Quote
TypeError: Error #1034: Type Coercion failed: cannot convert com.gaiaframework.assets::BitmapSpriteAsset@24a80cc1 to flash.display.Sprite.
   at pages::ColorPage/printerEvent()

while doing this

Code:
        var success = pj.start();
if (success) {
                pj.addPage (assets.color1, {xMin : 200, xMax: 1200, yMin: 300, yMax: 800});
                pj.send();
        }
Logged
Ramiro
Moderator
Gaia Addict
*****
Posts: 861


interactive pragmatism


« Reply #5 on: August 27, 2011, 10:13:40 AM »

heh, I thought it was custom, I've never used it.

Sure, use the content property of the sprite asset
Logged
codeKnow
Gaia Expert
****
Posts: 319


codeknow
WWW
« Reply #6 on: August 29, 2011, 10:32:21 AM »

Is there a way to convert asset sprite to a normal sprite ?

I think what you want to do is *addChild to the sprite that you do want to print out. I have worked this type of function into a project before.
http://codeknow.blogspot.com/2011/04/draw-it-digital-draw-print.html <-- if you want to see.

So how did I do it ?

First get the print classes from flash.
Code:
import flash.printing.*;

Next just set up the print function which in this case was *onClick*
Create a new *print job, as the desired items to the *Sprite that I want to print out (something that was just a empty spite on stage), position the items however I see fit to the printed page, and then in this case also put everything back; Here is the function I used. I guess another way would just to duplicate all printed objects and delete after printed...etc... "all roads lead to rome" .. this one is slightly paved Smiley

Code:
private function printObjects(event:MouseEvent):void
{
//newPrintJobObject
var printPage:PrintJob=new PrintJob;

pageHolder_mc.frontPage_mc.addChild(pageHolder_mc.pageBack_mc);

try
{
//print array is all items I wanted to print out, created well before printObject
i=_printArray.length;
while (i--)
{
_printArray[i].visible=true;
_printArray[i].x=0;
_printArray[i].y=0;
_printArray[i].width=363.75;
_printArray[i].height=281;
//printAll is blank sprite to print
printAll_mc.addChild(_printArray[i]);
}

//postion all objects inside of each sprite
pageHolder_mc.pageBack_mc.x=pageHolder_mc.frontPage_mc.x=308;
pageHolder_mc.pageBack_mc.y=pageHolder_mc.frontPage_mc.y=374;
pageHolder_mc.pageBack_mc.rotation=pageHolder_mc.frontPage_mc.rotation=-90;

messagePage_mc.x=pageHolder_mc.eventPage_mc.x=327.85;
messagePage_mc.y=30.35;
pageHolder_mc.eventPage_mc.y=394.15;
messagePage_mc.rotation=pageHolder_mc.eventPage_mc.rotation=90;

printAll_mc.x=0 - printAll_mc.width;

//start the print process
printPage.start();
printPage.addPage(printAll_mc);
}
//start the print process *print process was strange on different comps, until I added this ... quite odd and not sure I ever //really figured out why I had to dupe what I just did but in a different way... but it works !
catch (event:Error)
{
i=_printArray.length;
while (i--)
{
_printArray[i].visible=true;
_printArray[i].rotation=0;
pageHolder_mc.addChild(_printArray[i]);
}
messagePage_mc.visible=false;
pageHolder_mc.pageBack_mc.width=pageHolder_mc.frontPage_mc.width=pageHolder_mc.eventPage_mc.width=393.6;
pageHolder_mc.pageBack_mc.height=pageHolder_mc.frontPage_mc.height=pageHolder_mc.eventPage_mc.height=304.05;

pageHolder_mc.pageBack_mc.x=pageHolder_mc.frontPage_mc.x=pageHolder_mc.eventPage_mc.x=0;
pageHolder_mc.pageBack_mc.y=pageHolder_mc.frontPage_mc.y=pageHolder_mc.eventPage_mc.y=0;

_canvas.canvas.visible=true;
}

//reset all items back and print== null
i=_printArray.length;
while (i--)
{
_printArray[i].visible=true;
_printArray[i].rotation=0;
pageHolder_mc.addChild(_printArray[i]);
}

messagePage_mc.visible=false;
pageHolder_mc.pageBack_mc.width=pageHolder_mc.frontPage_mc.width=pageHolder_mc.eventPage_mc.width=393.6;
pageHolder_mc.pageBack_mc.height=pageHolder_mc.frontPage_mc.height=pageHolder_mc.eventPage_mc.height=304.05;

pageHolder_mc.pageBack_mc.x=pageHolder_mc.frontPage_mc.x=pageHolder_mc.eventPage_mc.x=0;
pageHolder_mc.pageBack_mc.y=pageHolder_mc.frontPage_mc.y=pageHolder_mc.eventPage_mc.y=0;

printPage.send();
printPage=null;

reset();
}


hope this helps in some way or fashion, fact is ... it works... its just really freaking tedious.
good luck Smiley

mB
« Last Edit: August 29, 2011, 10:37:15 AM by codeKnow » Logged
Pages: [1]
  Print  
 
Jump to:  

TinyPortal v1.0 beta 4 © Bloc