Merge
Submitted by eLenka on 4 August, 2010 - 14:54

Demonstration of the existing SWF file merging with additional info.
Source archive: merge.zip (417 KB)
Sample works
| Made template:
|
Inserted image and replaced text in template:
|
Some sample source:
var stt: string; MR: TSWFStreamReader; il: integer; Movie: TFlashMovie; SO: TSWFObject; ID_Img1, ID_Img2, newID1, newID2: word; IsProcess: boolean; FS: TSWFImageFill; begin if not (CB1.Checked or CB2.Checked) then begin ShowMessage('Please check any option.'); Exit; end; if not MTempl then begin ShowMessage('Please make a template.'); Exit; end; stt := ExtractFilePath(ParamStr(0)) + 'template.swf'; MR := TSWFStreamReader.Create(stt); MR.ReadBody(true, false); Movie := TFlashMovie.Create(MR.MovieRect.Left, MR.MovieRect.Top, MR.MovieRect.Right, MR.MovieRect.bottom, MR.FPS); Movie.Version := MR.Version; Movie.CurentObjID := 1000; // Searching an object ID for placing the image into the one if CB1.Checked then ID_Img1 := TSWFDefineShape(MR.FindObjectFromName('img1')).ShapeId else ID_Img1 := $FFFF; if CB2.Checked then ID_Img2 := TSWFDefineShape(MR.FindObjectFromName('img2')).ShapeId else ID_Img2 := $FFFF; for il := 0 to MR.TagList.Count - 1 do begin IsProcess := true; Case MR.TagInfo[il].TagID of tagShowFrame: begin IsProcess := false; Movie.ShowFrame; end; tagPlaceObject2: with TSWFPlaceObject2(MR.TagInfo[il].SWFObject) do begin if not CB1.Checked then IsProcess := not ((Name = 'prew1') or (Name = 'img1') or (Name = 'name1')); if not CB2.Checked then IsProcess := not ((Name = 'prew2') or (Name = 'img2') or (Name = 'name2')); end; tagDefineShape2, tagDefineShape3: with TSWFDefineShape(MR.TagInfo[il].SWFObject) do begin if (ShapeId = ID_Img1) then newID1 := Movie.AddImage(nameImg1).CharacterId; if (ShapeId = ID_Img2) then newID2 := Movie.AddImage(nameImg2).CharacterId; end; end; if IsProcess then begin SO := GenerateSWFObject(MR.TagInfo[il].TagID); SO.Assign(MR.TagInfo[il].SWFObject); Movie.ObjectList.Add(SO); case MR.TagInfo[il].TagID of tagDefineEditText: // Changing of a text template to an image file name with TSWFDefineEditText(SO) do if (VariableName = 'name1') and CB1.Checked then InitialText := ExtractFileName(nameImg1) else if (VariableName = 'name2') and CB2.Checked then InitialText := ExtractFileName(nameImg2); tagDefineShape2, tagDefineShape3: with TSWFDefineShape(SO) do begin if (ShapeId = ID_Img1) or (ShapeId = ID_Img2) then begin // Adding of an image filling FillStyles.Clear; FS := TSWFImageFill.Create; FS.SWFFillType := SWFFillClipBitmap; if ShapeId = ID_Img1 then begin FS.ImageID := newID1; FS.ScaleTo(Rect(0, 0, 100*twips, 100*twips), Size1.cx, Size1.cy); end else begin FS.ImageID := newID2; FS.ScaleTo(Rect(0, 0, 100*twips, 100*twips), Size2.cx, Size2.cy); end; FillStyles.Add(FS); TSWFStyleChangeRecord(Edges[0]).Fill1Id := FillStyles.Count; end; end; end; end; end; Movie.MakeStream; stt := ExtractFilePath(ParamStr(0)) + IntToStr(Random(999999))+'.swf'; Player.Movie := stt; DeleteFile(stt); stt := ExtractFilePath(ParamStr(0)) + 'merge.swf'; Movie.SaveToFile(stt); MR.Free; Movie.Free; Player.Movie := stt; end;