Return to FunctionReference page
Function
SWFButton newSWFButton(void);
Purpose
- Creates a new, empty button object.
Parameters
None
Returns
- A new, empty button object.
Language
- C
Ming version
- (unknown). At least 0.4.0.beta5 and onwards, likely earlier versions as well.
Notes
None as yet
Example
Note - this example is in C, and works fine with gcc and Ming 0.4.0.beta5. Try it. :)
1 #define BOX_HEIGHT 200
2 #define BOX_WIDTH 300
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <ming.h>
7
8
9 int main(void)
10 {
11 // General variables
12 SWFDisplayItem buttons_display_item;
13 int i;
14 SWFDisplayItem mc_display_item;
15 SWFMovieClip movie_clip;
16 SWFDisplayItem shape_display_item;
17 SWFShape shape_object;
18 SWFMovie my_movie;
19 SWFAction my_movie_action;
20
21 // Fill styles we create
22 SWFFillStyle dark_blue_fill;
23 SWFFillStyle light_blue_fill;
24 SWFFillStyle green_fill;
25
26 // Variables used for the play button
27 SWFAction play_action;
28 SWFButton play_button;
29 SWFButtonRecord play_record_down;
30 SWFButtonRecord play_record_over;
31 SWFButtonRecord play_record_up;
32 SWFShape play_shape_down;
33 SWFShape play_shape_over;
34 SWFShape play_shape_up;
35
36 // Variables used for the stop button
37 SWFAction stop_action;
38 SWFButton stop_button;
39 SWFButtonRecord stop_record_down;
40 SWFButtonRecord stop_record_over;
41 SWFButtonRecord stop_record_up;
42 SWFShape stop_shape_down;
43 SWFShape stop_shape_over;
44 SWFShape stop_shape_up;
45
46
47 // Initialise the movie structure in memory
48 Ming_init();
49 my_movie = newSWFMovieWithVersion(7);
50
51 // Set the desired compression level for the output (9 = maximum compression)
52 Ming_setSWFCompression(9);
53
54 // Adjust the dimensions of the movie
55 SWFMovie_setDimension(my_movie, 800, 600);
56
57 // Set the frame rate for the movie to 24 frames per second
58 SWFMovie_setRate(my_movie, 24.0);
59
60 // Ensure the movie starts out in the "stopped" state
61 my_movie_action = newSWFAction("_root.stop();");
62 SWFMovie_add(my_movie, (SWFBlock) my_movie_action);
63
64 // Create the fill styles we'll be using
65 light_blue_fill = newSWFSolidFillStyle(0x00, 0x00, 0xf0, 0xff);
66 dark_blue_fill = newSWFSolidFillStyle(0x00, 0x00, 0x90, 0xff);
67 green_fill = newSWFSolidFillStyle(0x00, 0xcc, 0x00, 0xff);
68
69 // *** Create the Play button ***
70
71 // Create a shape to be used in the play button for its "UP" state
72 play_shape_up = newSWFShape();
73 SWFShape_setRightFillStyle(play_shape_up, dark_blue_fill); // Use the dark blue fill
74 SWFShape_setLine(play_shape_up, 1, 0x00, 0x00, 0x00, 0xff);
75 SWFShape_movePenTo(play_shape_up, 220.0, 500.0);
76 SWFShape_drawLine(play_shape_up, 25, 25);
77 SWFShape_drawLine(play_shape_up, -25, 25);
78 SWFShape_drawLine(play_shape_up, 0, -50);
79
80 // Create a shape to be used in the play button for its "MOUSE OVER" state
81 play_shape_over = newSWFShape();
82 SWFShape_setRightFillStyle(play_shape_over, light_blue_fill); // Use the light blue fill
83 SWFShape_setLine(play_shape_over, 1, 0x00, 0x00, 0x00, 0xff);
84 SWFShape_movePenTo(play_shape_over, 220.0, 500.0);
85 SWFShape_drawLine(play_shape_over, 25, 25);
86 SWFShape_drawLine(play_shape_over, -25, 25);
87 SWFShape_drawLine(play_shape_over, 0, -50);
88
89 // Create a shape to be used in the play button for its "DOWN" state
90 play_shape_down = newSWFShape();
91 SWFShape_setRightFillStyle(play_shape_down, green_fill); // Use the green fill
92 SWFShape_setLine(play_shape_down, 1, 0x00, 0x00, 0x00, 0xff);
93 SWFShape_movePenTo(play_shape_down, 220.0, 500.0);
94 SWFShape_drawLine(play_shape_down, 25, 25);
95 SWFShape_drawLine(play_shape_down, -25, 25);
96 SWFShape_drawLine(play_shape_down, 0, -50);
97
98 // Create an empty button object we can use
99 play_button = newSWFButton();
100
101 // Add the shapes to the button for its various states
102 play_record_up = SWFButton_addCharacter(play_button, (SWFCharacter) play_shape_up, SWFBUTTON_UP|SWFBUTTON_HIT);
103 play_record_over = SWFButton_addCharacter(play_button, (SWFCharacter) play_shape_over, SWFBUTTON_OVER);
104 play_record_down = SWFButton_addCharacter(play_button, (SWFCharacter) play_shape_down, SWFBUTTON_DOWN);
105
106 // Add the Play action to the play button
107 play_action = newSWFAction("_root.play();");
108 SWFButton_addAction(play_button, play_action, SWFBUTTON_MOUSEUP);
109
110 // *** Create the Stop button ***
111
112 // Create a shape to be used in the stop button for its "UP" state
113 stop_shape_up = newSWFShape();
114 SWFShape_setRightFillStyle(stop_shape_up, dark_blue_fill); // Use the dark blue fill
115 SWFShape_setLine(stop_shape_up, 1, 0x00, 0x00, 0x00, 0xff);
116 SWFShape_movePenTo(stop_shape_up, 150.0, 500.0);
117 SWFShape_drawLine(stop_shape_up, 50, 0);
118 SWFShape_drawLine(stop_shape_up, 0, 50);
119 SWFShape_drawLine(stop_shape_up, -50, 0);
120 SWFShape_drawLine(stop_shape_up, 0, -50);
121
122 // Create a shape to be used in the stop button for its "MOUSE OVER" state
123 stop_shape_over = newSWFShape();
124 SWFShape_setRightFillStyle(stop_shape_over, light_blue_fill); // Use the light blue fill
125 SWFShape_setLine(stop_shape_over, 1, 0x00, 0x00, 0x00, 0xff);
126 SWFShape_movePenTo(stop_shape_over, 150.0, 500.0);
127 SWFShape_drawLine(stop_shape_over, 50, 0);
128 SWFShape_drawLine(stop_shape_over, 0, 50);
129 SWFShape_drawLine(stop_shape_over, -50, 0);
130 SWFShape_drawLine(stop_shape_over, 0, -50);
131
132 // Create a shape to be used in the stop button for its "DOWN" state
133 stop_shape_down = newSWFShape();
134 SWFShape_setRightFillStyle(stop_shape_down, green_fill); // Use the green fill
135 SWFShape_setLine(stop_shape_down, 1, 0x00, 0x00, 0x00, 0xff);
136 SWFShape_movePenTo(stop_shape_down, 150.0, 500.0);
137 SWFShape_drawLine(stop_shape_down, 50, 0);
138 SWFShape_drawLine(stop_shape_down, 0, 50);
139 SWFShape_drawLine(stop_shape_down, -50, 0);
140 SWFShape_drawLine(stop_shape_down, 0, -50);
141
142 // Create an empty button object we can use
143 stop_button = newSWFButton();
144
145 // Add the shapes to the button for its various states
146 stop_record_up = SWFButton_addCharacter(stop_button, (SWFCharacter) stop_shape_up, SWFBUTTON_UP|SWFBUTTON_HIT);
147 stop_record_over = SWFButton_addCharacter(stop_button, (SWFCharacter) stop_shape_over, SWFBUTTON_OVER);
148 stop_record_down = SWFButton_addCharacter(stop_button, (SWFCharacter) stop_shape_down, SWFBUTTON_DOWN);
149
150 // Add the Stop action to the stop button
151 stop_action = newSWFAction("_root.stop();");
152 SWFButton_addAction(stop_button, stop_action, SWFBUTTON_MOUSEUP);
153
154 // *** Create the movie clip container for the buttons ***
155
156 // Embed the buttons in a movie clip
157 movie_clip = newSWFMovieClip();
158 mc_display_item = SWFMovieClip_add(movie_clip, (SWFBlock) play_button);
159 mc_display_item = SWFMovieClip_add(movie_clip, (SWFBlock) stop_button);
160
161 // Advance the movie clip one frame, else it doesn't get displayed
162 SWFMovieClip_nextFrame(movie_clip);
163
164 // Add the movie clip to the main movie
165 buttons_display_item = SWFMovie_add(my_movie, movie_clip);
166
167 // Set the movie clip to be shown higher in the display stack than the main movie
168 SWFDisplayItem_setDepth(buttons_display_item, 100);
169
170 // ***** Create the "main movie" (a box) here *****
171
172 // Create the shape object we want
173 shape_object = newSWFShape();
174 SWFShape_setLine(shape_object, 1, 0x00, 0x00, 0x00, 0xff);
175 SWFShape_setRightFillStyle(shape_object, light_blue_fill);
176 SWFShape_drawLine(shape_object, BOX_WIDTH, 0.0);
177 SWFShape_drawLine(shape_object, 0.0, BOX_HEIGHT);
178 SWFShape_drawLine(shape_object, -(BOX_WIDTH), 0.0);
179 SWFShape_drawLine(shape_object, 0.0, -(BOX_HEIGHT));
180
181 // Add the shape object to the movie
182 shape_display_item = SWFMovie_add(my_movie, (SWFBlock) shape_object);
183
184 // Set the display depth for the image
185 SWFDisplayItem_setDepth(shape_display_item, 10);
186
187 // Move to 100, 100
188 SWFDisplayItem_moveTo(shape_display_item, 150.00, 100.0);
189
190 // Progressively move the square down and to the right
191 for (i = 0; i <= 250; i++)
192 {
193 SWFMovie_nextFrame(my_movie);
194 SWFDisplayItem_move(shape_display_item, 2, 2);
195 }
196
197 // Save the swf movie file to disk
198 SWFMovie_save(my_movie, "ming-test-controlbar.swf");
199
200 // Free the memory allocated in this function
201 destroySWFMovie(my_movie);
202 destroySWFShape(shape_object);
203 destroySWFMovieClip(movie_clip);
204 destroySWFButton(stop_button);
205 destroySWFButton(play_button);
206 destroySWFFillStyle(dark_blue_fill);
207 destroySWFFillStyle(light_blue_fill);
208 destroySWFFillStyle(green_fill);
209 return EXIT_SUCCESS;
210 }