======================================================
注:本文源代码点此下载
======================================================
delphi与flash交互具体存在两个问题:
1、如何能让delphi应用程序接收到flash发来的消息,并处理;
2、怎样能从delphi应用程序向flash传递命令,控制.swf文件的运行。
一、flash向delphi发送消息:
flash向delphi发送消息运用flash中自带的fscommand命令即可。
第一步(flash中button添加script):
on (release) {
var usercode = editcode.text
var username = editname.text;
fscommand("btsubmit", usercode+","+username); //这样传入args
}
flash中某一元件的单击事件会触发fscommand命令了,其中参数“btsubmit”是命令,后面的就是命令的值。
以下为在delphi中使用的接收代码:
procedure tfrmmain.flash1fscommand(sender: tobject; const command,
args: widestring);
begin
if command='btsubmit' then
showmessage(args);
end;
在tshockwaveflash控件中已经存在了专门接收命令的事件了"onfscommand",其它的就很清楚了。
二、delphi向flash传递指令:
delphi方面,执行代码如下:
flash1.setvariable('btsubmittoflash','这是delphi向flash传的');
flash中必需存在变量名为"btsubmittoflash"的元件,应为文本元件(必须),后面是传递的内容。执行后会在flash中名为btsubmittoflash的文本元件中显示传入的“这是delphi向flash传的”这段内容。
三、由于播放flash的时候,点击右键会出现诸如放大,缩小的flash控件的字样,所以最好屏蔽右键。
procedure tform1.applicationevents1message(var msg: tagmsg;var handled: boolean);
var
mpoint : tpoint;
begin
//if ischild(flash1.handle, msg.hwnd) then
if((msg.message = wm_rbuttondown) or (msg.message = wm_rbuttonup))then
begin
getcursorpos(mpoint);
//如果去掉下面这行就是屏蔽右键菜单,不去掉为自定义右键菜单
popupmenu1.popup(mpoint.x, mpoint.y);
handled:=true;
end;
end;
procedure tform1.formshow(sender: tobject);
begin
application.onmessage := applicationevents1message;//屏蔽flash右键菜单,或弹出自定义右键菜单
end;
===========(背景透明)============
wmode参数值为transparent
======================================================
在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定 这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/