"Fossies" - the Fresh Open Source Software Archive 
Member "gnash-0.8.10/testsuite/misc-ming.all/action_order/ActionOrderTest5.c" (19 Jan 2012, 6859 Bytes) of package /linux/www/old/gnash-0.8.10.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 */
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <ming.h>
21
22 #include "ming_utils.h"
23
24 #define OUTPUT_VERSION 8
25 #define OUTPUT_FILENAME "ActionOrderTest5.swf"
26
27 // A relatively simple looping test checking order of unload events.
28 //
29 // See InitActionTest3 and InitActionTest4. This is the same test but without
30 // static event handlers.
31
32 int main(int argc, char* argv[])
33 {
34
35 SWFMovie mo;
36 SWFMovieClip mc1, mc2, mc3, mc4, dejagnuclip;
37 SWFDisplayItem it;
38 SWFAction ac;
39 SWFInitAction initac;
40
41 const char *srcdir=".";
42 if (argc > 1) srcdir = argv[1];
43 else {
44 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
45 return 1;
46 }
47
48 Ming_init();
49 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
50 SWFMovie_setDimension(mo, 800, 600);
51 SWFMovie_setRate (mo, 1.0);
52
53 add_actions(mo,
54 "if (!_global.hasOwnProperty('arr')) { _global.arr = []; };"
55 "_global.ch = function(a, b) {"
56 " trace(a);"
57 " if (typeof(b)=='undefined' || (typeof(b)=='boolean' && b)) {"
58 " _global.arr.push(a);"
59 " };"
60 "};"
61 "this.onEnterFrame = function() { "
62 " _global.ch('onEnterFrame', false);"
63 "};"
64 );
65
66 SWFMovie_nextFrame(mo);
67
68 // MovieClip 1
69 mc1 = newSWFMovieClip(); // 1 frames
70
71 // SWF_EXPORTASSETS
72 SWFMovie_addExport(mo, (SWFBlock)mc1, "Segments_Name");
73 SWFMovie_writeExports(mo);
74
75 // MovieClip mc3 has two frames. In each frame a different MovieClip
76 // is placed with the name Segments.
77 mc3 = newSWFMovieClip(); // 2 frames
78
79 // MovieClip 2
80 mc2 = newSWFMovieClip(); // 1 frames
81
82 // Add mc2 to mc3 (first frame)
83 it = SWFMovieClip_add(mc3, (SWFBlock)mc2);
84 SWFDisplayItem_setDepth(it, 1);
85 SWFDisplayItem_setName(it, "Segments");
86
87 // Frame 2 of mc3
88 SWFMovieClip_nextFrame(mc3);
89
90 // Remove mc2
91 SWFDisplayItem_remove(it);
92
93 // Add mc1
94 it = SWFMovieClip_add(mc3, (SWFBlock)mc1);
95 SWFDisplayItem_setDepth(it, 1);
96 SWFDisplayItem_setName(it, "Segments");
97
98 SWFMovieClip_nextFrame(mc3);
99
100 // End mc3
101
102
103 // This is frame 1 of the main timeline
104
105 // Put our sprite mc3 on stage.
106 it = SWFMovie_add(mo, (SWFBlock)mc3);
107 SWFDisplayItem_setDepth(it, 1);
108 SWFDisplayItem_setName(it, "mc");
109
110 // mc4 is just for executing init actions.
111 mc4 = newSWFMovieClip();
112 SWFMovie_addExport(mo, (SWFBlock)mc4, "__Packages.Bug");
113 SWFMovie_writeExports(mo);
114
115 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
116 0, 0, 800, 600);
117 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
118
119 ac = newSWFAction(
120 "_global.loops = 0;"
121 "_global.c = 0;"
122 "if( !_global.Bug ) {"
123 " _global.Bug = function () {"
124 " this.onUnload = function() { "
125 " _global.ch('dynamic unload: ' + this.c);"
126 " }; "
127 " this.onLoad = function() { "
128 " _global.ch('dynamic load: ' + this.c);"
129 " }; "
130 " this.c = _global.c;"
131 " _global.ch('ctor: ' + _global.c);"
132 " _global.c++;"
133 " };"
134 "};"
135 );
136
137 initac = newSWFInitAction_withId(ac, 4);
138 SWFMovie_add(mo, (SWFBlock)initac);
139
140 ac = newSWFAction("Object.registerClass('Segments_Name',Bug);");
141 initac = newSWFInitAction_withId(ac, 1);
142 SWFMovie_add(mo, (SWFBlock)initac);
143 add_actions(mo, "_global.ch('Frame ' + "
144 "_level0._currentframe + ' actions: ' "
145 "+ _level0.mc.Segments.c);");
146
147 // Frame 2 of the main timeline
148 SWFMovie_nextFrame(mo);
149 add_actions(mo, "_global.ch('Frame ' + "
150 "_level0._currentframe + ' actions: ' "
151 "+ _level0.mc.Segments.c);");
152
153 add_actions(mo,
154 " if (_global.loops < 5) {"
155 " _global.loops++;"
156 " gotoAndPlay(2);"
157 " }"
158 " else {"
159 " mc.stop();"
160 " delete this.onEnterFrame;"
161 " gotoAndPlay(4);"
162 " };"
163 );
164
165 SWFMovie_nextFrame(mo);
166
167 check_equals(mo, "_global.arr.length", "20");
168 check_equals(mo, "_global.arr[0]", "'Frame 2 actions: undefined'");
169 check_equals(mo, "_global.arr[1]", "'ctor: 0'");
170 check_equals(mo, "_global.arr[2]", "'Frame 3 actions: 0'");
171 check_equals(mo, "_global.arr[3]", "'dynamic load: 0'");
172 check_equals(mo, "_global.arr[4]", "'Frame 2 actions: 0'");
173 check_equals(mo, "_global.arr[5]", "'Frame 3 actions: 0'");
174 check_equals(mo, "_global.arr[6]", "'Frame 2 actions: 0'");
175 check_equals(mo, "_global.arr[7]", "'ctor: 1'");
176 check_equals(mo, "_global.arr[8]", "'dynamic unload: 0'");
177 check_equals(mo, "_global.arr[9]", "'Frame 3 actions: 0'");
178 check_equals(mo, "_global.arr[11]", "'Frame 2 actions: 0'");
179 check_equals(mo, "_global.arr[12]", "'Frame 3 actions: 1'");
180 check_equals(mo, "_global.arr[13]", "'Frame 2 actions: 1'");
181 check_equals(mo, "_global.arr[14]", "'ctor: 2'");
182 check_equals(mo, "_global.arr[15]", "'dynamic unload: 1'");
183 check_equals(mo, "_global.arr[16]", "'Frame 3 actions: 1'");
184 check_equals(mo, "_global.arr[17]", "'dynamic load: 2'");
185 check_equals(mo, "_global.arr[18]", "'Frame 2 actions: 1'");
186 check_equals(mo, "_global.arr[19]", "'Frame 3 actions: 2'");
187 check_equals(mo, "_global.arr.toString()",
188 "'Frame 2 actions: undefined,ctor: 0,Frame 3 actions: 0,dynamic load: 0,Frame 2 actions: 0,Frame 3 actions: 0,Frame 2 actions: 0,ctor: 1,dynamic unload: 0,Frame 3 actions: 0,dynamic load: 1,Frame 2 actions: 0,Frame 3 actions: 1,Frame 2 actions: 1,ctor: 2,dynamic unload: 1,Frame 3 actions: 1,dynamic load: 2,Frame 2 actions: 1,Frame 3 actions: 2'");
189
190 SWFMovie_nextFrame(mo);
191 add_actions(mo, "totals(21); stop();");
192
193 SWFMovie_nextFrame(mo);
194
195 // SWF_END
196 SWFMovie_save(mo, OUTPUT_FILENAME);
197
198 return 0;
199 }
200