2 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
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.
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
20 * Zou Lunkai, zoulunkai@gmail.com
22 * For nested movieClips:
23 * (1) parent onLoad called first;
24 * (2) child unload called first;
25 * (3) child onEnterFrame called first;
27 * yes, parent could be a child of another parent,
28 * and child could be a parent of another child:)
29 * Just always keep (1)(2)(3) in mind.
31 * movieClips hiberarchy:
33 * |----dejagnuclip(placed at 1st frame of main timeline)
40 * expected onClipEvents order:
43 * mc12.OnLoad; mc121.OnLoad; mc1211.OnLoad;
44 * mc1211.OnEnterFrame; mc121.OnEnterFrame; mc12.OnEnterFrame
47 * mc1211.OnUnload; mc121.OnUnload; mc12.OnUnload;
51 * The actual order of tags are dependent on compiler, so you need to
52 * verify first if the order of tags is what you expect.
59 #include "ming_utils.h"
61 #define OUTPUT_VERSION 6
62 #define OUTPUT_FILENAME "action_execution_order_test5.swf"
66 main(int argc
, char** argv
)
69 SWFMovieClip mc1
, mc11
, mc12
, mc121
, mc1211
, dejagnuclip
;
70 SWFDisplayItem it1
, it11
, it12
, it121
, it1211
;
72 const char *srcdir
=".";
77 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
82 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
83 SWFMovie_setDimension(mo
, 800, 600);
84 SWFMovie_setRate (mo
, 12.0);
86 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
87 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
88 SWFMovie_nextFrame(mo
); /* 1st frame of _root */
90 /*===================== Start of defining movieClips ==========================*/
92 mc1211
= newSWFMovieClip();
93 SWFMovieClip_nextFrame(mc1211
); /* mc1211, 1st frame */
94 SWFMovieClip_nextFrame(mc1211
); /* mc1211, 2nd frame */
96 mc121
= newSWFMovieClip();
98 /* add mc1211 to mc121 and name it as "mc1211" */
99 it1211
= SWFMovieClip_add(mc121
, (SWFBlock
)mc1211
);
100 SWFDisplayItem_setDepth(it1211
, 1);
101 SWFDisplayItem_setName(it1211
, "mc1211");
103 /* add onClipEvents */
104 SWFDisplayItem_addAction(it1211
, // the inner most child
105 compileSWFActionCode(" _root.note('mc1211 onInitialize called'); "
106 " _root.check_equals(this.__proto__, MovieClip.prototype);"
107 " _root.check_equals(this._parent.__proto__, MovieClip.prototype);"
108 " _root.check_equals(this._parent._parent.__proto__, MovieClip.prototype);"),
111 SWFDisplayItem_addAction(it1211
,
112 compileSWFActionCode(" _root.note('mc1211 onLoad called'); "
113 " _root.x1 += '5+'; "),
115 SWFDisplayItem_addAction(it1211
,
116 compileSWFActionCode(" _root.note('mc1211 onUnload called'); "
117 " _root.x1 += '11+'; "),
119 SWFDisplayItem_addAction(it1211
,
120 compileSWFActionCode(" _root.note('mc1211 onEnterFrame called'); "
121 " _root.x1 += '6+'; "),
122 SWFACTION_ENTERFRAME
);
124 SWFMovieClip_nextFrame(mc121
); /* mc121, 1st frame */
125 SWFMovieClip_nextFrame(mc121
); /* mc121, 2nd frame */
128 mc12
= newSWFMovieClip();
129 /* add mc121 to mc12 and name it as "mc121" */
130 it121
= SWFMovieClip_add(mc12
, (SWFBlock
)mc121
);
131 SWFDisplayItem_setDepth(it121
, 1);
132 SWFDisplayItem_setName(it121
, "mc121");
134 /* add onClipEvents */
135 SWFDisplayItem_addAction(it121
,
136 compileSWFActionCode(" _root.note('mc121 onLoad called'); "
137 " _root.x1 += '4+'; "),
139 SWFDisplayItem_addAction(it121
,
140 compileSWFActionCode(" _root.note('mc121 onUnload called'); "
141 " _root.x1 += '12+'; "),
143 SWFDisplayItem_addAction(it121
,
144 compileSWFActionCode(" _root.note('mc121 onEnterFrame called'); "
145 " _root.x1 += '7+'; "),
146 SWFACTION_ENTERFRAME
);
148 SWFMovieClip_nextFrame(mc12
); /* mc12, 1st frame */
149 SWFMovieClip_nextFrame(mc12
); /* mc12, 2nd frame */
152 mc11
= newSWFMovieClip();
153 SWFMovieClip_nextFrame(mc11
); /* mc11, 1st frame */
154 SWFMovieClip_nextFrame(mc11
); /* mc11, 2nd frame */
157 mc1
= newSWFMovieClip();
159 /* add mc11 to mc1 and name it as "mc11" */
160 it11
= SWFMovieClip_add(mc1
, (SWFBlock
)mc11
);
161 SWFDisplayItem_setDepth(it11
, 2);
163 /* add onClipEvents */
164 SWFDisplayItem_setName(it11
, "mc11");
165 SWFDisplayItem_addAction(it11
,
166 compileSWFActionCode(" _root.note('mc11 onLoad called'); "
167 " _root.x1 += '2+'; "),
169 SWFDisplayItem_addAction(it11
,
170 compileSWFActionCode(" _root.note('mc11 onUnload called'); "
171 " _root.x1 += '14+'; "),
173 SWFDisplayItem_addAction(it11
,
174 compileSWFActionCode(" _root.note('mc11 onEnterFrame called'); "
175 " _root.x1 += '9+'; "),
176 SWFACTION_ENTERFRAME
);
178 /* add mc12 to mc1 and name it as "mc12" */
179 it12
= SWFMovieClip_add(mc1
, (SWFBlock
)mc12
);
180 SWFDisplayItem_setDepth(it12
, 1);
181 SWFDisplayItem_setName(it12
, "mc12");
183 /* add onClipEvents */
184 SWFDisplayItem_addAction(it12
,
185 compileSWFActionCode(" _root.note('mc12 onInitialize called'); "
186 " _root.check_equals(this, _root.mc1.mc12);"
187 " _root.check_equals(this.__proto__, MovieClip.prototype);"
188 " _root.check_equals(this._parent.__proto__, MovieClip.prototype);"
189 " _root.check_equals(this._parent.mc11.__proto__, MovieClip.prototype);"
190 // test child __proto__
191 " _root.check_equals(this.mc121.__proto__, MovieClip.prototype);"),
194 SWFDisplayItem_addAction(it12
, // the inner most child
195 compileSWFActionCode(" _root.note('mc12 onConstruct called'); "
196 " _root.check_equals(this, _root.mc1.mc12);"
197 " _root.check_equals(this.__proto__, MovieClip.prototype);"
198 " _root.check_equals(this._parent.__proto__, MovieClip.prototype);"
199 " _root.check_equals(this._parent.mc11.__proto__, MovieClip.prototype);"
200 " _root.check_equals(this.mc121.__proto__, MovieClip.prototype);"),
201 SWFACTION_CONSTRUCT
);
203 SWFDisplayItem_addAction(it12
,
204 compileSWFActionCode(" _root.note('mc12 onLoad called'); "
205 " _root.x1 += '3+'; "),
207 SWFDisplayItem_addAction(it12
,
208 compileSWFActionCode(" _root.note('mc12 onUnload called'); "
209 " _root.x1 += '13+'; "),
211 SWFDisplayItem_addAction(it12
,
212 compileSWFActionCode(" _root.note('mc12 onEnterFrame called'); "
213 " _root.x1 += '8+'; "),
214 SWFACTION_ENTERFRAME
);
216 SWFMovieClip_nextFrame(mc1
); /* mc1, 1st frame */
217 SWFMovieClip_nextFrame(mc1
); /* mc1, 2nd frame */
219 /*===================== End of defining movieClips ==========================*/
223 it1
= SWFMovie_add(mo
, (SWFBlock
)mc1
);
225 /* add onClipEvents */
226 SWFDisplayItem_addAction(it1
,
227 compileSWFActionCode(" _root.note('mc1 onLoad called'); "
228 " _root.x1 += '1+'; "),
230 SWFDisplayItem_addAction(it1
,
231 compileSWFActionCode(" _root.note('mc1 onUnload called'); "
232 " _root.x1 += '15+'; "),
234 SWFDisplayItem_addAction(it1
,
235 compileSWFActionCode(" _root.note('mc1 onEnterFrame called'); "
236 " _root.x1 += '10+'; "),
237 SWFACTION_ENTERFRAME
);
240 /* place _root.mc1 */
241 SWFDisplayItem_setDepth(it1
, 10);
242 SWFDisplayItem_setName(it1
, "mc1");
243 SWFMovie_nextFrame(mo
); /* 2nd frame of _root */
246 SWFMovie_nextFrame(mo
); /* 3rd frame of _root */
248 /* remove _root.mc1 */
249 SWFDisplayItem_remove(it1
);
250 SWFMovie_nextFrame(mo
); /* 4th frame of _root */
253 check_equals(mo
, "_root.x1", "'1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+'");
254 add_actions(mo
, " _root.totals(); stop(); ");
255 SWFMovie_nextFrame(mo
); /* 5th frame of _root */
259 puts("Saving " OUTPUT_FILENAME
);
260 SWFMovie_save(mo
, OUTPUT_FILENAME
);