sololie哥,新开的例子就可以监控到,但是一应用到下面透明的地方,按下A键就没反应.
还有就是一直闪屏.秒数越少,闪的越历害.unit falsh;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, ShockwaveFlashObjects_TLB, ExtCtrls, jpeg,
Buttons, dxGDIPlusClasses, MPlayer;type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
BitBtn1: TBitBtn;
Panel2: TPanel;
img1: TImage;
shckwvflsh1: TShockwaveFlash;
tmr1: TTimer;
Image1: TImage;
Image2: TImage;
Label1: TLabel;
Image3: TImage;
Timer1: TTimer; procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
private { Private declarations }
public
OldWndProc: TWndMethod;
procedure NewWndProc(var msg: TMessage); { Public declarations }
end;var
Form1: TForm1;
leftFoot,rightFoot : Boolean;
implementation{$R *.dfm}
var
bmpBuf: TBitmap;
isKeyDown: ShortInt;procedure TForm1.FormCreate(Sender: TObject);
begin OldWndProc := shckwvflsh1.WindowProc;
shckwvflsh1.WindowProc := NewWndProc;
DoubleBuffered := True; // 设置跟 shckwvflash 控件宽高和xy 一致
bmpBuf := TBitmap.Create;
bmpBuf.PixelFormat := pf16bit;
bmpBuf.Transparent := true;
bmpBuf.Width := shckwvflsh1.Width;
bmpBuf.Height := shckwvflsh1.Height;
img1.Width := shckwvflsh1.Width;
img1.Height := shckwvflsh1.Height;
img1.Top := shckwvflsh1.Top;
img1.Left := shckwvflsh1.Left;
img1.Transparent := True;
shckwvflsh1.Visible := False;
shckwvflsh1.Quality2 := 'High';
// shckwvflsh1.Movie := 'c:\1.swf';
DoubleBuffered:=True;
shckwvflsh1.Movie:='C:\Documents and Settings\Administrator\桌面\瑜伽2\Flash\yoga\1.swf';
shckwvflsh1.Scale:='ShowAll' ;
end;procedure TForm1.FormResize(Sender: TObject);
begin
Repaint;
end;procedure TForm1.FormPaint(Sender: TObject);
var
bmpFormBg: TBitmap;
begin
// bmpFormBg := TBitmap.Create;
// bmpFormBg.LoadFromFile('C:\Documents and Settings\Administrator\桌面\瑜伽素材\Main.bmp');
// Canvas.StretchDraw(ClientRect, bmpFormBg);
// bmpformBg.Free;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
bmpBuf.Free;
//bmpFormBg.Free;
end;procedure TForm1.tmr1Timer(Sender: TObject);
begin
if isKeyDown = 1 then
begin
Caption := '按住了A键';
Image3.Visible:=true;
end;
if isKeyDown = 2 then
begin
Caption := '松开了A键';
image3.Visible:=false;
end;
shckwvflsh1.PaintTo(bmpBuf.Canvas, 0, 0);
bmpBuf.Canvas.Brush.Style := bsClear;
bmpBuf.Transparent := True;
img1.Picture.Bitmap.Assign(bmpBuf);
Label1.Caption:=inttostr(shckwvflsh1.FrameNum);
end;procedure TForm1.NewWndProc(var msg: TMessage);
begin
if msg.Msg = WM_KEYDOWN then
begin// 这里做处理 if (msg.Msg = WM_KEYDOWN) and ((msg.WParam = Ord('A'))) then
isKeyDown := 1;
if (msg.Msg = WM_KEYUP) and (msg.WParam = Ord('A')) then
isKeyDown := 2; OldWndProc(msg);end;
OldWndProc(msg);
end;end.
还有就是一直闪屏.秒数越少,闪的越历害.unit falsh;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, ShockwaveFlashObjects_TLB, ExtCtrls, jpeg,
Buttons, dxGDIPlusClasses, MPlayer;type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
BitBtn1: TBitBtn;
Panel2: TPanel;
img1: TImage;
shckwvflsh1: TShockwaveFlash;
tmr1: TTimer;
Image1: TImage;
Image2: TImage;
Label1: TLabel;
Image3: TImage;
Timer1: TTimer; procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
private { Private declarations }
public
OldWndProc: TWndMethod;
procedure NewWndProc(var msg: TMessage); { Public declarations }
end;var
Form1: TForm1;
leftFoot,rightFoot : Boolean;
implementation{$R *.dfm}
var
bmpBuf: TBitmap;
isKeyDown: ShortInt;procedure TForm1.FormCreate(Sender: TObject);
begin OldWndProc := shckwvflsh1.WindowProc;
shckwvflsh1.WindowProc := NewWndProc;
DoubleBuffered := True; // 设置跟 shckwvflash 控件宽高和xy 一致
bmpBuf := TBitmap.Create;
bmpBuf.PixelFormat := pf16bit;
bmpBuf.Transparent := true;
bmpBuf.Width := shckwvflsh1.Width;
bmpBuf.Height := shckwvflsh1.Height;
img1.Width := shckwvflsh1.Width;
img1.Height := shckwvflsh1.Height;
img1.Top := shckwvflsh1.Top;
img1.Left := shckwvflsh1.Left;
img1.Transparent := True;
shckwvflsh1.Visible := False;
shckwvflsh1.Quality2 := 'High';
// shckwvflsh1.Movie := 'c:\1.swf';
DoubleBuffered:=True;
shckwvflsh1.Movie:='C:\Documents and Settings\Administrator\桌面\瑜伽2\Flash\yoga\1.swf';
shckwvflsh1.Scale:='ShowAll' ;
end;procedure TForm1.FormResize(Sender: TObject);
begin
Repaint;
end;procedure TForm1.FormPaint(Sender: TObject);
var
bmpFormBg: TBitmap;
begin
// bmpFormBg := TBitmap.Create;
// bmpFormBg.LoadFromFile('C:\Documents and Settings\Administrator\桌面\瑜伽素材\Main.bmp');
// Canvas.StretchDraw(ClientRect, bmpFormBg);
// bmpformBg.Free;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
bmpBuf.Free;
//bmpFormBg.Free;
end;procedure TForm1.tmr1Timer(Sender: TObject);
begin
if isKeyDown = 1 then
begin
Caption := '按住了A键';
Image3.Visible:=true;
end;
if isKeyDown = 2 then
begin
Caption := '松开了A键';
image3.Visible:=false;
end;
shckwvflsh1.PaintTo(bmpBuf.Canvas, 0, 0);
bmpBuf.Canvas.Brush.Style := bsClear;
bmpBuf.Transparent := True;
img1.Picture.Bitmap.Assign(bmpBuf);
Label1.Caption:=inttostr(shckwvflsh1.FrameNum);
end;procedure TForm1.NewWndProc(var msg: TMessage);
begin
if msg.Msg = WM_KEYDOWN then
begin// 这里做处理 if (msg.Msg = WM_KEYDOWN) and ((msg.WParam = Ord('A'))) then
isKeyDown := 1;
if (msg.Msg = WM_KEYUP) and (msg.WParam = Ord('A')) then
isKeyDown := 2; OldWndProc(msg);end;
OldWndProc(msg);
end;end.
begin
if msg.Msg = WM_KEYDOWN then
begin// 这里做处理 if (msg.Msg = WM_KEYDOWN) and ((msg.WParam = Ord('A'))) then
isKeyDown := 1;
if (msg.Msg = WM_KEYUP) and (msg.WParam = Ord('A')) then
isKeyDown := 2; // OldWndProc(msg); // 这个哪来的?去掉。
end;
OldWndProc(msg);
end;
// 分两个timer来处理procedure TForm1.tmr1Timer(Sender: TObject);
begin
if isKeyDown = 1 then
begin
Caption := '按住了A键';
Image3.Visible:=true;
end;
if isKeyDown = 2 then
begin
Caption := '松开了A键';
image3.Visible:=false;
end;
Label1.Caption:=inttostr(shckwvflsh1.FrameNum);
end;procedure TForm1.tmr2Timer(Sender: TObject);
begin
shckwvflsh1.PaintTo(bmpBuf.Canvas, 0, 0);
img1.Picture.Bitmap.Assign(bmpBuf);
end;
最后的就是按键按下问题了...
我还以为这flash你按A键,它里面的人就跳一下之类的。
你还是想说清楚你想干什么吧,按A键做什么?碎嚼碎嚼
蓝色光芒兄给了一个例子,也很不错.procedure TForm1.FormCreate(Sender: TObject);
begin
ActiveX.CoInitialize(NIL);
fMainLoaded := false;
psSoftPath := ExtractFilePath(Application.ExeName);
SWF.Movie := psSoftPath + '容器.swf';
Self.KeyPreview := True;
end;//Flash自定义回调接口,最好用XML解析 request , 偷懒了...
//初始化完成,可以调用LoadFromFile和Clear接口了
//<invoke name="InitFinished" returntype="xml"><arguments></arguments></invoke>
//该文件装入成功
//<invoke name="LoadFinished" returntype="xml"><arguments><string>file://E:\xxx\dog_rose.jpg</string></arguments></invoke>
//该文件装入失败,原因:无法读取该文件或者不是可显示对象
//<invoke name="LoadFaild" returntype="xml"><arguments><string>file://E:\xx\xx.swf</string></arguments></invoke>procedure TForm1.SWFFlashCall(ASender: TObject; const request: WideString);
var
S : String;
begin
S := request;
if not fMainLoaded then begin
if Pos('"InitFinished"' , S)>0 then begin //容器初始化完成,之后就可以调用LoadFromFile和Clear接口了
fMainLoaded := True;
CallLoadFromFile('dog_rose.jpg',0,0); //装入背景图,全路径或者相对于容器.swf的路径,最好用全路径
CallLoadFromFile(psSoftPath + '枫叶.swf',0,0);
end;
end;
end;//调用容器Flash中的装入接口,参数width,height<=0的话,将采用装入对象默认的宽和高,否则就是缩放该对象
//装入接口是耗时接口,装入结果会延迟通过OnFlashCall通知,通知包括:LoadFinished和LoadFaild
//由于是延迟接口,因此可以连续投放到装入队列中
function TForm1.CallLoadFromFile(Const URL : String; x:integer=0; y : integer=0; width:integer=0; height:integer=0) : Boolean;
var
W : WideString;
begin
W := '<invoke name="LoadFromFile" returntype="xml">' +
'<arguments>' +
'<string>' + URL + '</string>' +
'<number>' + IntToStr(x) + '</number>' +
'<number>' + IntToStr(y) + '</number>' +
'<number>' + IntToStr(width) + '</number>' +
'<number>' + IntToStr(height) + '</number>' +
'</arguments>'+
'</invoke>';
try
SWF.CallFunction(W);
Result := True;
except
Result := False;
end;
procedure TForm1.ReLoadBtnClick(Sender: TObject);
begin
CallClear();
CallLoadFromFile(psSoftPath + 'Main.png');
CallLoadFromFile(psSoftPath + '1.swf',0,0,1000,0);
end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = Ord('A')) and (Self.ActiveControl<>NIL) and (Self.ActiveControl is TShockwaveFlash) then
Caption := 'A Down'
end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = Ord('A')) and (Self.ActiveControl<>NIL) and (Self.ActiveControl is TShockwaveFlash) then
Caption := 'A Up'
end;
优点是窗体可以直接监控到按键情况.
但容器不透明,我还需要放置N个图片显示在flash之上.
同过他的想到的办法是在上面做一个panel容器在SWF 之上,但必须把PANEL做成透明的,才可以.
不同的图片都调用一次,
CallLoadFromFile,给你写了参数来调整位置以及大小的,
先CallLoadFromFile的在后面,后CallLoadFromFile在上面
1.CallLoadFromFile(psSoftPath + 'Main1.png');
2.CallLoadFromFile(psSoftPath + 'Main2.png');
3.CallLoadFromFile(psSoftPath + 'Main3.png');
4.CallLoadFromFile(psSoftPath + 'Main4.png');
5.CallLoadFromFile(psSoftPath + 'Main5.png');1>加载以后,按键按下A字母,'Main2.png'处于不可显状态.指定某个清楚.可不可以做到?
2>还有一个问题,CallClear 这个清除不了,等于是重复加截!
谢了
也可以在按A后,Clear,然后加载 除了Main2.png外的其他来实现,不过这方法显然没有第一个方法好,
有点无语了,你这么加载图片,图片都放到一起了,位置参数都没给
kiboisme
蓝色光芒 兄,觉的有没有问题.
这代码,清楚不了.帮看看,加一次,就是重复一次,原来的还在!
蓝色光芒 给的这个例子,我发现,窗体在打开的时候,按下按键可以做判断,但是只要一按BUTTON按钮加载,就没办法判断了.有点抓逛了...
sololie 哥的方法,座等..555555555
(Self.ActiveControl<>NIL) and //判断存在有焦点的控件
(Self.ActiveControl is TShockwaveFlash) then //判断焦点是否在Flash上,如果3个条件满足,那显示,
Caption := 'A Down'晕阿!!!你放了一个按钮,而当前焦点在按钮上,条件3不满足当然不显示了,如果你点一下Flash,再按A,就显示了,代码要学会阅读并尝试去理解,这样的进步才踏实。
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = Ord('A')) and (Self.ActiveControl<>NIL) then //and (Self.ActiveControl is TShockwaveFlash)
Caption := 'A Down';
end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = Ord('A')) and (Self.ActiveControl<>NIL) then //and (Self.ActiveControl is TShockwaveFlash)
Caption := 'A UP';我这样处理了一下,我也发现了,我把button的事件keydown ,keyUP事件调用窗体的就可以了
我真错了,后面我想回复,回复不了,我回复三次了..
这代码,清除不了.帮看看,加截一次,就是重复一次,画面不在了,但原来的声音还在!
如果你加截三次,就有三个声音..不理解...
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = Ord('A')) and (Self.ActiveControl<>NIL) then
Caption := 'An Down'end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = Ord('A')) and (Self.ActiveControl<>NIL) then // and (Self.ActiveControl is TShockwaveFlash)
Caption := 'A Up'
end;procedure TForm1.BitBtn2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
bitbtn2.OnKeyUp := form1.OnKeyUp;
end;procedure TForm1.BitBtn2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
bitbtn2.OnKeyDown := form1.OnKeyDown;
end;
function TForm1.CallRemove(index: integer): Boolean;
var
W : WideString;
begin
W := '<invoke name="Remove" returntype="xml">' +
'<arguments>' +
'<number>' + IntToStr(index) + '</number>' +
'</arguments>'+
'</invoke>';
try
SWF.CallFunction(W);
Result := True;
except
Result := False;
end;
end;
注意index,比如你一次加载了,A,B,C,D,E 5个文件,要释放A就index=0,依次,当释放一个之后,后面的序号依次往前靠,也就是释放A之后,B的序号变成0了。