Keypress event
Submitted by eLenka on 4 August, 2010 - 14:31
.png)
Demonstration of using Action instructions for creating keypress event. Click on movie and press arrow keys on your keyboard to move the ball.
Source archive: keypress.zip (246 KB)
Sample works
Some sample source:
var Movie: TFlashMovie; label1, label2, label3, label4, label5, label6, label7, label8: TSWFOffsetMarker; begin Movie := TFlashMovie.Create(0, 0, 400, 300, 20, scPix); Movie.Version := 6; { Background } Movie.BackgroundColor.RGB := SWFRGB(0,0,0); Movie.AddRectangle(0, 0, 400, 300).SetLinearGradient(cswfNavy, cswfGray20, 270); Movie.PlaceObject(Movie.Shapes[0], 1); Movie.AddCircle(0, 0, 20).SetRadialGradient(cswfRed, cswfBlack, 35, 35); Movie.AddSprite.PlaceObject(Movie.Shapes[1], 1); with Movie.PlaceObject(Movie.Sprites[0], 2) do begin SetTranslate(200, 150); with OnKeyDown do begin ConstantPool(['Key', 'getCode', 'this', '_x', '_y']); Push([0, 0], [vtInteger, vtConstant8]); GetVariable; PushConstant(1); CallMethod; StoreRegister(0); Push(37); StrictEquals; label1 := _If.BranchOffsetMarker; Push([0, 39], [vtRegister, vtInteger]); StrictEquals; label2 := _If.BranchOffsetMarker; Push([0, 38], [vtRegister, vtInteger]); StrictEquals; label3 := _If.BranchOffsetMarker; Push([0, 40], [vtRegister, vtInteger]); StrictEquals; label4 := _If.BranchOffsetMarker; label5 := Jump.BranchOffsetMarker; SetMarker(label1, false); Push([2], [vtConstant8]); GetVariable; PushConstant([3, 2]); GetVariable; PushConstant(3); GetMember; Push(1); Subtract; SetMember; label6 := Jump.BranchOffsetMarker; SetMarker(label2, false); PushConstant(2); GetVariable; PushConstant([3, 2]); GetVariable; PushConstant(3); GetMember; Push(1); Add2; SetMember; label7 := Jump.BranchOffsetMarker; SetMarker(label3, false); Push([2], [vtConstant8]); GetVariable; PushConstant([4, 2]); GetVariable; PushConstant(4); GetMember; Push(1); Subtract; SetMember; label8 := Jump.BranchOffsetMarker; SetMarker(label4, false); PushConstant(2); GetVariable; PushConstant([4, 2]); GetVariable; PushConstant(4); GetMember; Push(1); Add2; SetMember; SetMarker(label8, false); SetMarker(label7, false); SetMarker(label6, false); SetMarker(label5, false); end; end; Movie.ShowFrame; Movie.MakeStream; Movie.SaveToFile('demo.swf'); Movie.Free;