3 Example implementation for creating a button with rfxswf
5 Part of the swftools package.
7 Copyright (c) 2000, 2001 Matthias Kramm <kramm@quiss.org>
8 Rainer Böhme <rfxswf@reflex-studio.de>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
27 #include "../rfxswf.h"
33 int useDefineButton2 = 0; // set this to 1 to use DefineButton2 Tags
34 // instead of DefineButton1
36 int main (int argc,char ** argv)
41 ActionTAG*a1,*a2,*a3, *actiontoset;
42 S32 width=300,height = 300;
47 memset(&swf,0x00,sizeof(SWF)); // set global movie parameters
49 swf.fileVersion = 4; // make flash 4 compatible swf
50 swf.frameRate = 0x1900; // about 0x19 frames per second
52 swf.movieSize.xmax = 20*width; // flash units: 1 pixel = 20 units
53 swf.movieSize.ymax = 20*height;
55 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
62 for(count=1;count<4;count++)
64 t = swf_InsertTag(t,ST_DEFINESHAPE);
65 swf_ShapeNew(&s); // create new shape instance
66 rgb.r = rgb.b = rgb.g = 0x00;
67 ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
68 rgb.r = count*0x40; rgb.b = 0xff;
69 fs1 = swf_ShapeAddSolidFillStyle(s,&rgb);
70 swf_SetU16(t,33+count); // now set character ID
75 swf_SetRect(t,&r); // set shape bounds
76 swf_SetShapeHeader(t,s); // write all styles to tag
77 swf_ShapeSetAll(t,s,0,0,ls1,fs1,0); // move to (0,0), select linestyle ls1 and no fillstyle
78 swf_ShapeSetCircle(t,s,width*10,height*10,width*10,height*10);
79 swf_ShapeSetEnd(t); // finish drawing
80 swf_ShapeFree(s); // clean shape structure (which isn't needed anymore after writing the tag)
83 a1 = action_SetTarget(0, "movie");
84 a1 = action_NextFrame(a1);
85 a1 = action_SetTarget(a1, "");
88 //a2 = action_GetUrl(a2, "test.swf","_level0"); // load a swf
89 //a2 = action_GetUrl(a2, "index.html","_this"); // load html in new window
90 a2 = action_GetUrl(0, "http://www.quiss.org/swftools/index.html","_parent"); // load html in this window
93 a3 = action_GotoFrame(0,33);
100 t = swf_InsertTag(t,ST_DEFINEBUTTON);
101 swf_SetU16(t,31); //id
102 swf_ButtonSetRecord(t,BS_UP|BS_HIT,34,1,NULL,NULL);
103 swf_ButtonSetRecord(t,BS_OVER,35,1,NULL,NULL);
104 swf_ButtonSetRecord(t,BS_DOWN,36,1,NULL,NULL);
105 swf_SetU8(t,0); // end of button records
107 swf_ActionSet(t,actiontoset);
111 t = swf_InsertTag(t,ST_DEFINEBUTTON2);
112 swf_SetU16(t,ID_BUTTON); //id
113 swf_ButtonSetFlags(t, 0); //menu=no
114 swf_ButtonSetRecord(t,BS_UP|BS_HIT,34,1,NULL,NULL);
115 swf_ButtonSetRecord(t,BS_OVER,35,1,NULL,NULL);
116 swf_ButtonSetRecord(t,BS_DOWN,36,1,NULL,NULL);
117 swf_SetU8(t,0); // end of button records
119 swf_ButtonSetCondition(t, BC_OVERDOWN_OVERUP);
120 swf_ActionSet(t,actiontoset);
122 swf_ButtonPostProcess(t, 1); // don't forget!
129 t = swf_InsertTag(t,ST_PLACEOBJECT2);
130 swf_ObjectPlace(t, ID_BUTTON, 2,0,0,0);
132 t = swf_InsertTag(t,ST_SHOWFRAME);
133 t = swf_InsertTag(t,ST_END);
135 f = open("buttontest.swf",O_WRONLY|O_CREAT, 0644);
136 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
139 swf_FreeTags(&swf); // cleanup