内嵌资源:
图片
a) 内联方式内嵌:<mx:Button label="my button" icon="@Embed(source='myImage.gif')"/>
b) 使用ActionScript绑定
<mx:Script>
<![CDATA[
[Embed(source="myImage.gif")]
[Bindable]
public var imaCls:Class;
]]>
</mx:Script>
<mx:Button label="my button" icon="{imgCls}"/>
swf和音频文件
<mx:script>
<![CDATA[
[Embed(source="mySound.mp3")]
[Bindable]
public var mySound:Class;
[Embed(source="mySWF.swf")]
[Bindable]
public var mySWF:Class;
]]>
</mx:script>
Flex 打印
基本打印:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.printing.FlexPrintJob;
private function print():void {
// create print job
var printJob:FlexPrintJob = new FlexPrintJob();
if(printJob.start()){
// add page
printJob.addObject(myLabel,"none");
// send to printer
printJob.send();
}
}
]]>
</mx:Script>
<mx:Label id="myLabel" text="Hello World" />
<mx:Button click="print()" label="Print" />
</mx:Application>
打印多页
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.printing.FlexPrintJob;
private function print():void {
// create print job
var printJob:FlexPrintJob = new FlexPrintJob();
if(printJob.start()){
// add 2 pages
printJob.addObject(page1,"none");
printJob.addObject(page2,"none");
// send to printer
printJob.send();
}
}
]]>
</mx:Script>
<mx:Label id="page1" text="Hello World page 1" />
<mx:Label id="page2" text="Hello World page 2" />
<mx:Button click="print()" label="Print" />
</mx:Application>
打印表格数据
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initData()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.printing.FlexPrintJob;
[Bindable]
public var dp:ArrayCollection;
// populate the dataProviders for the datagrids
private function initData():void{
this.dp = new ArrayCollection();
for(var i:Number=0; i<60; i++){
this.dp.addItem({row:i,data:"item " + i});
}
}
public function print():void {
// create print job
var printJob:FlexPrintJob = new FlexPrintJob();
// start print job
if(printJob.start()){
// add the print grid
printJob.addObject(printGrid);
while(true) {
// loop through print grids data and add additonal pages if neccessary
printGrid.nextPage();
if(!printGrid.validNextPage){
printJob.addObject(printGrid);
break;
}
}
// send to printer
printJob.send();
}
}
]]>
</mx:Script>
<mx:DataGrid id="dataGrid" dataProvider="{dp}" height="200" width="200">
<mx:columns>
<mx:DataGridColumn dataField="row" headerText="Row Number" />
<mx:DataGridColumn dataField="data" headerText="Row Data" />
</mx:columns>
</mx:DataGrid>
<mx:Button click="print()" label="Print" />
<mx:PrintDataGrid visible="false" id="printGrid" dataProvider="{dp}" height="700" width="600">
<mx:columns>
<mx:DataGridColumn dataField="row" headerText="Row Number" />
<mx:DataGridColumn dataField="data" headerText="Row Data" />
</mx:columns>
</mx:PrintDataGrid>
</mx:Application>
posted on 2011-03-16 09:16
长春语林科技 阅读(242)
评论(0) 编辑 收藏 所属分类:
flex