UTestXML.pas
上传用户:raido2005
上传日期:2022-06-22
资源大小:5044k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. //*******************************************************//
  2. //                                                       //
  3. //                      DelphiFlash.com                  //
  4. //         Copyright (c) 2004-2006 FeatherySoft, Inc.    //
  5. //                    info@delphiflash.com               //
  6. //                                                       //
  7. //*******************************************************//
  8. //  Description:  Sample of making XML from SWF and conversely
  9. //  Last update:  27 jun 2006
  10. unit UTestXML;
  11. interface
  12. uses
  13.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  14.   Dialogs, StdCtrls, SWFStreams, SWFObjects, FlashObjects, ShellApi, ComCtrls;
  15. type
  16.   TdlgName = class(TForm)
  17.     OD: TOpenDialog;
  18.     Label1: TLabel;
  19.     ProgressBar: TProgressBar;
  20.     GroupBox1: TGroupBox;
  21.     CBExt: TCheckBox;
  22.     CBSubFolder: TCheckBox;
  23.     CBSomeFolder: TCheckBox;
  24.     CBFontExt: TCheckBox;
  25.     CBFBytecode: TCheckBox;
  26.     CBActionExt: TCheckBox;
  27.     CBABytecode: TCheckBox;
  28.     bMakeXML: TButton;
  29.     GroupBox2: TGroupBox;
  30.     bMakeSWF: TButton;
  31.     RB1: TRadioButton;
  32.     RB2: TRadioButton;
  33.     procedure bMakeXMLClick(Sender: TObject);
  34.     procedure bMakeSWFClick(Sender: TObject);
  35.     procedure CBSubFolderClick(Sender: TObject);
  36.     procedure CBFontExtClick(Sender: TObject);
  37.   private
  38.     procedure onProcess(sender: TBasedSWFStream; Percent: byte; WT: TProgressWorkType);
  39.   public
  40.     SWF: TSWFStreamReader;
  41.     Movie: TFlashMovie;
  42.   end;
  43. var
  44.   dlgName: TdlgName;
  45. implementation
  46. {$R *.dfm}
  47. procedure TdlgName.bMakeXMLClick(Sender: TObject);
  48.  var Stt: string;
  49. begin
  50.   OD.Filter := 'SWF|*.swf';
  51.   if OD.Execute then
  52.     begin
  53.       Screen.Cursor := crHourGlass;
  54.       SWF := TSWFStreamReader.Create('');
  55.       With SWF.XMLReadWriteSettings do
  56.        begin
  57.          BasePath := ExtractFilePath(OD.FileName);
  58.          if CBExt.Checked then
  59.             AsExternal := [lpImage, lpSound, lpVideo]
  60.            else
  61.             AsExternal := [];
  62.          if CBFontExt.Checked then
  63.            AsExternal := AsExternal + [lpFont];
  64.          if CBActionExt.Checked then
  65.            AsExternal := AsExternal + [lpActions];
  66.          FontAsByteCode := CBFBytecode.Checked;
  67.          ActionsAsByteCode := CBABytecode.Checked;
  68.          if CBSubFolder.Checked then
  69.            begin
  70.              Stt := BasePath + ChangeFileExt(ExtractFileName(OD.FileName), '.files');
  71. //             uncoment for testing releative path
  72. //             stt := 'c:temp' + ChangeFileExt(ExtractFileName(OD.FileName), '.files');
  73.              SomePath := CBSomeFolder.Checked;
  74.              if CBSomeFolder.Checked then
  75.                begin
  76.                 Path := Stt;
  77.                 CreateDir(Path);
  78.                end else
  79.                begin
  80.                  PathImage := Stt + '_I';
  81.                  CreateDir(PathImage);
  82.                  PathSound := Stt + '_S';
  83.                  CreateDir(PathSound);
  84.                  PathVideo := Stt + '_V';
  85.                  CreateDir(PathVideo);
  86.                  PathFont := Stt + '_F';
  87.                  CreateDir(PathFont);
  88.                  PathActions := Stt + '_A';
  89.                  CreateDir(PathActions);
  90.                end;
  91.            end else
  92.             FilePrefix := ChangeFileExt(ExtractFileName(OD.FileName), '_');
  93.        end;
  94.       SWF.OnProgress := onProcess;
  95.       SWF.LoadFromFile(OD.FileName);
  96.       SWF.SaveToXMLFile(ChangeFileExt(OD.FileName, '.xml'));
  97.       SWF.Free;
  98.       label1.Caption := '';
  99.       ProgressBar.Position := 0;
  100.       Screen.Cursor := crDefault;
  101.     end;
  102. end;
  103. procedure TdlgName.bMakeSWFClick(Sender: TObject);
  104.  var BaseSWF: TBasedSWFStream;
  105. begin
  106.   OD.Filter := 'XML|*.xml';
  107.   if OD.Execute then
  108.     begin
  109.       Screen.Cursor := crHourGlass;
  110.       if RB1.Checked
  111.         then
  112.           BaseSWF := TSWFStreamReader.Create('')
  113.         else
  114.           BaseSWF := TFlashMovie.Create(0, 0, 1, 1, 1);
  115.           
  116.       BaseSWF.OnProgress := onProcess;
  117.       BaseSWF.LoadFromXMLFile(OD.FileName, true);
  118.       BaseSWF.MakeStream;
  119.       BaseSWF.SaveToFile(ChangeFileExt(OD.FileName, '_new.swf'));
  120.       BaseSWF.Free;
  121.       label1.Caption := '';
  122.       ProgressBar.Position := 0;
  123.       ShellExecute(0, 'open', pchar(ChangeFileExt(OD.FileName, '_new.swf')), nil, nil, SW_NORMAL);
  124.       Screen.Cursor := crDefault;
  125.     end;
  126. end;
  127. procedure TdlgName.onProcess(sender: TBasedSWFStream; Percent: byte; WT: TProgressWorkType);
  128.  var Lbl: string;
  129. begin
  130.   case WT of
  131.    pwtReadStream: Lbl := 'Loading file';
  132.    pwtMakeStream: Lbl := 'Making SWF stream';
  133.    pwtLoadXML: Lbl := 'Loading XML';
  134.    pwtParseXML: Lbl := 'Parsing XML';
  135.    pwtSaveXML: Lbl := 'Saving XML';
  136.    pwtCompressStream: Lbl := 'Compressing stream';
  137.   end;
  138.   if Lbl <> Label1.Caption then
  139.     begin
  140.       label1.Caption := Lbl;
  141.       label1.Update;
  142.     end;
  143.   ProgressBar.Position := Percent;
  144. end;
  145. procedure TdlgName.CBSubFolderClick(Sender: TObject);
  146. begin
  147.   CBSomeFolder.Enabled := CBSubFolder.Checked;
  148. end;
  149. procedure TdlgName.CBFontExtClick(Sender: TObject);
  150. begin
  151.   CBFBytecode.Enabled := CBFontExt.Checked;
  152. end;
  153. end.