JavaScript与Flash8.0通信之打印实战篇

王朝html/css/js·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

最近为银行作一个凭证打印,应用到了javaScript与flash 8.0的通讯,所以我将这段代码贴出来。起初计划纯粹用javascrip作打印,后来想到要更好的升级(原因就不说啦),所以就用javaScript与flash 8.0来作。

先看界面:

录入数据,点击确定,执行函数,数据通过javascrip脚本传递到.swf文件中。界面如:

代码:

<SCRIPTLANGUAGE=JavaScript>

//alert("lll")

<!--

functionsgxg(args){

//alert("lll")

vv=newArray()

ss=newArray()

for(i=0;i<3;i++)

{

vv[i]=i;

}

for(k=3;k<6;k++)

{

ss[k]=k;

}

ss.shift();

ss.shift();

ss.shift();

ss[2]=12;

op=document.formDate

//alert(op.kemu.value)

varkemu=op.kemu.value;

vardates=op.dates.value;

varaccount=op.account.value;

varcontent=op.content.value;

window.document.myFlash.SetVariable("_level0.datas.kemu.text",kemu);

//============================================

time=dates.split("-");

window.document.myFlash.SetVariable("_level0.datas.years.text",time[0]);

window.document.myFlash.SetVariable("_level0.datas.months.text",time[1]);

window.document.myFlash.SetVariable("_level0.datas.days.text",time[2]);

//==============================================

window.document.myFlash.SetVariable("_level0.datas.account.text",account);

window.document.myFlash.SetVariable("_level0.datas.content_start0.text",vv.join("-"));

window.document.myFlash.SetVariable("_level0.datas.content_end0.text",ss.join("-"));

window.document.myFlash.TCallFrame("_level0.datas",0);

}

//-->

</SCRIPT>

其中SetVariable、TCallFrame是javaScrip控制flash的命令。SetVariable:是给flash中的变量赋值。(就是将javaScrip中数值赋给.swf)TCallFrame:是执行flash中的actionScript.(主要是执行flash脚本中的打印)下面是flash界面:

其中的数据接收帧脚本:

count=0;

cos1=content_start0.text;

cos2=content_end0.text;

content_start=cos1.split("-");

content_end=cos2.split("-");

for(i=0;i<content_start.length;i++){

count+=(content_end[i]-content_start[i]);

}

this.amount.text=count;

//=========================

//===========

amounts=newArray();

for(i=0;i<content_start.length;i++){

amounts[i]=String((content_end[i]-content_start[i])).split("");

if(amounts[i].length<10){

middle=newArray();

for(k=0;k<10-amounts[i].length;k++){

middle[k]=0;

}

amounts[i]=middle.concat(amounts[i]);

amounts[i].push("0");

amounts[i].push("0");

}else{

amounts[i].push("0");

amounts[i].push("0");

}

}

for(s=0;s<amounts.length;s++){

for(u=0;u<12;u++){

this["amount"+s]["values"+u].text=amounts[s][u];

}

}

//===================================

if(cos1<>undefined){

if(cos1<>""){

for(i=0;i<content_start.length;i++){

this["content_start"+i].text=content_start[i];

}

}

}

if(cos2<>undefined){

if(cos2<>""){

for(i=0;i<content_end.length;i++){

this["content_end"+i].text=content_end[i];

}

}

}

源代码:

flash源码:

点击浏览该文件

php源文件:

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">

<title>UntitledDocument</title>

</head>

<SCRIPTLANGUAGE=JavaScript>

//alert("lll")

<!--

functionsgxg(args){

//alert("lll")

vv=newArray()

ss=newArray()

for(i=0;i<3;i++)

{

vv[i]=i;

}

for(k=3;k<6;k++)

{

ss[k]=k;

}

ss.shift();

ss.shift();

ss.shift();

ss[2]=12;

op=document.formDate

//alert(op.kemu.value)

varkemu=op.kemu.value;

vardates=op.dates.value;

varaccount=op.account.value;

varcontent=op.content.value;

window.document.myFlash.SetVariable("_level0.datas.kemu.text",kemu);

//============================================

time=dates.split("-");

window.document.myFlash.SetVariable("_level0.datas.years.text",time[0]);

window.document.myFlash.SetVariable("_level0.datas.months.text",time[1]);

window.document.myFlash.SetVariable("_level0.datas.days.text",time[2]);

//==============================================

window.document.myFlash.SetVariable("_level0.datas.account.text",account);

window.document.myFlash.SetVariable("_level0.datas.content_start0.text",vv.join("-"));

window.document.myFlash.SetVariable("_level0.datas.content_end0.text",ss.join("-"));

window.document.myFlash.TCallFrame("_level0.datas",0);

/*for(i=0;i<time.length;i++)

{

alert(time[i])

}*/

}

functionprintDatas()

{

alert("exeprintDates")

//op=document.formDate

window.document.myFlash.SetVariable("_level0.i",1);

window.document.myFlash.TCallFrame("_level0",0);

}

//-->

</SCRIPT>

<body>

<palign="center">

<objectclassid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0

width="550"height="300"id="myFlash">

<paramname="movie"value="bank.swf">

<paramname="quality"value="high">

<embedsrc="bank.swf"quality="high"pluginspage=http://www.macromedia.com/go/getflashplayer

type="application/x-shockwave-flash"width="550"height="300"name="myFlash"></embed>

</object>

</p>

<formname="formDate"method="post"action="">

<tablewidth="600"border="0"align="center">

<tr>

<tdalign="right">科目:</td>

<td>&nbsp;<inputtype="text"name="kemu"maxlength="45"></td>

<tdalign="right">日期:</td>

<td>&nbsp;<inputtype="text"name="dates"maxlength="45"></td>

</tr>

<tr>

<tdalign="right">帐号:</td>

<td>&nbsp;<inputtype="text"name="account"maxlength="45"></td>

<tdalign="right">摘要:</td>

<td>&nbsp;<inputtype="text"name="content"maxlength="45"></td>

</tr>

<tr>

<tdcolspan="4"align="center"><inputtype="button"maxlength="45"value="确定"onClick="sgxg(this)">&nbsp;

<inputtype="button"maxlength="45"value="打印"onClick="printDatas()"></td>

</tr>

</table>

<p>&nbsp;</p>

</form>

<p>&nbsp;</p>

</body>

</html>

参考:

Play() -------------------------------------------------------- 播放动画

StopPlay()--------------------------------------------------- 停止动画

IsPlaying()--------------------------------------------------- 动画是否正在播放

GotoFrame(frame_number)---------------------------- 跳转到某帧

TotalFrames()---------------------------------------------- 获取动画总帧数

CurrentFrame()-------------------------------------------- 回传当前动画所在帧数-1

Rewind()---------------------------------------------------- 使动画返回第一帧

SetZoomRect(left,top,right,buttom)--------------- 放大指定区域

Zoom(percent)-------------------------------------------- 改变动画大小

Pan(x_position,y_position,unit)----------------------- 使动画在x,y方向上平移

PercentLoaded()------------------------------------------ 返回动画被载入的百分比

LoadMovie(level_number,path)----------------------- 加载动画

TGotoFrame(movie_clip,frame_number)----------- movie_clip跳转到指定帧数

TGotoLabel(movie_clip,label_name)----------------- movie_clip跳转到指定标签

TCurrentFrame(movie_clip)----------------------------- 回传movie_clip当前帧-1

TCurrentLabel(movie_clip)------------------------------ 回传movie_clip当前标签

TPlay(movie_clip)------------------------------------------ 播放movie_clip

TStopPlay(movie_clip)----------------------------------- 停止movie_clip的播放

GetVariable(variable_name)---------------------------- 获取变量

SetVariable(variable_name,value)--------------------- 变量赋值

TCallFrame(movie_clip,frame_number)-------------- call指定帧上的action

TCallLabel(movie_clip,label)----------------------------- call指定标签上的action

TGetProperty(movie_clip,property)------------------ 获取movie_clip的指定属性

TSetProperty(movie_clip,property,number)------- 设置movie_clip的指定属性

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航