此示例显示如何在设计器中编辑报表模板,并在同一页面的查看器中显示此报表。要从代码创建和显示设计器,您需要调用StiDesignerFx.initialize() 静态方法。在应用程序的initialize事件中调用此方法。如果将设计器或查看器作为组件添加到MXML页面,则不需要此方法:
private function onInitialize(): void{ StiDesignerFx.initialize(); ...}
首先,在onCreateNewReportClick()事件中创建一个新的报表对象并将其分配给查看器:
private function onCreateNewReportClick(): void{ buttonDesignReport.enabled = true; // Create new report object report = new StiReport(); // Assign report to Viewer viewerFx.report = report;}
接下来在onDesignReportClick()事件中使用此报表调用报告设计器对话框:
private function onDesignReportClick(): void{ buttonViewDesignedReport.enabled = true; // Design report in Designer dialog window report.designDialog();}
最后,在onViewDesignedReportClick()事件中,将此报表标记为未呈现,并再次将其分配给报表查看器:
private function onViewDesignedReportClick(): void{ // Mark report as not rendered report.isRendered = false; // Reassign designed report to Viewer viewerFx.report = report;}
下面的屏幕截图中,您可以看到示例代码的结果。