Thank you for your response! I keep getting error "ArgumentError: Error #2015: Invalid BitmapData." on the line where I create my BitmapData object (scroll to the bottom of the code to see where I create my BitmapData).private function saveFile():void
{
var zoomSliderVisibleBeforePrint:Boolean;
if (map.zoomSliderVisible)
{
map.zoomSliderVisible = false;
zoomSliderVisibleBeforePrint = true;
}
var printJob:FlexPrintJob = new FlexPrintJob();
var h:Number = printJob.pageHeight;
var w:Number = printJob.pageWidth;
//VGROUP
var printBox:VGroup = new VGroup();
printBox.styleName = "PrintBox";
printBox.width = map.width;
//VGROUP inner
var printBoxTitle:VGroup = new VGroup();
var printBoxSubTitle:VGroup = new VGroup();
var selectedAlign:String = LRCa[LRCcbo.selectedIndex];
printBox.horizontalAlign=LRCa[LRCcbo.selectedIndex].toString().toLocaleLowerCase();
this.addChild(printBox);
try
{
//TITLE
var printTitle:Label = new Label();
printTitle.text = txtTitle.text;
if (titleFontSize!=0)
{
printTitle.setStyle("fontSize", titleFontSize);
}
else
{
printTitle.setStyle("fontSize", h / 12);
}
if (titleFontWeight!="")
printTitle.setStyle("fontWeight", titleFontWeight);
printTitle.percentWidth = 100;
printBoxTitle.addElement(printTitle);
//SUBTITLE
var printSubtitle:Label = new Label();
printSubtitle.text = txtSubtitle.text;
if (subtitleFontSize!=0)
{
printSubtitle.setStyle("fontSize", subtitleFontSize);
}
else
{
printSubtitle.setStyle("fontSize", h / 24);
}
if (subtitleFontWeight!="")
{
printSubtitle.setStyle("fontWeight", subtitleFontWeight);
}
printSubtitle.percentWidth = 100;
printBoxSubTitle.addElement(printSubtitle);
printBox.addElement(printBoxTitle);
printBox.addElement(printBoxSubTitle);
//MAP
var bmpMap:BitmapData = ImageSnapshot.captureBitmapData(map);
var printImg:BitmapImage = new BitmapImage();
printImg.smooth = true;
printImg.source = bmpMap;
printBox.addElement(printImg);
//COPYRIGHT
var now:Date = new Date();
var printCopy:Label = new Label();
printCopy.text = copyright + " " + now.toLocaleString() + ".";
if (copyrightFontSize!=0)
{
printCopy.setStyle("fontSize", copyrightFontSize);
}
else
{
printCopy.setStyle("fontSize", h / 48);
}
if (copyrightFontWeight!="")
{
printCopy.setStyle("fontWeight", copyrightFontWeight);
}
printCopy.percentWidth = 100;
printBox.addElement(printCopy);
//COMMENTS
if(txtComments.textFlow.getText())
{
var spacerLabel:Label = new Label();
spacerLabel.text = " ";
//set the comment title:
var printCommentTitleLabel:Label = new Label();
printCommentTitleLabel.setStyle("fontSize", h / 24);
printCommentTitleLabel.text = "Comments: ";
//set the comments:
var printComment:Label = new Label();
printComment.setStyle("fontSize", h / 48);
printComment.text = txtComments.textFlow.getText();
//add to container:
var printBoxComments:VGroup = new VGroup();
printBoxComments.percentWidth = 100;
printBoxComments.addElement(spacerLabel);
printBoxComments.addElement(printCommentTitleLabel);
printBoxComments.addElement(printComment);
printBox.addElement(printBoxComments);
}
}
finally
{
}
var bd:BitmapData = new BitmapData(printBox.width, printBox.height); //ArgumentError: Error #2015: Invalid BitmapData.
bd.draw(printBox, new Matrix());
var pngEnc:PNGEncoder = new PNGEncoder();
var imgData:ByteArray = pngEnc.encode(bd);
fileReference = new FileReference();
fileReference.save(imgData,"TIGER.png");
}