PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/testsuite/misc-ming.all/action_order/action_execution_order_test5.c

https://github.com/frash/frash
C | 263 lines | 150 code | 45 blank | 68 comment | 1 complexity | a5ed5fb6984387698181b35ecf8e376e MD5 | raw file
  1. /*
  2. * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 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. /*
  19. * Zou Lunkai, zoulunkai@gmail.com
  20. *
  21. * For nested movieClips:
  22. * (1) parent onLoad called first;
  23. * (2) child unload called first;
  24. * (3) child onEnterFrame called first;
  25. *
  26. * yes, parent could be a child of another parent,
  27. * and child could be a parent of another child:)
  28. * Just always keep (1)(2)(3) in mind.
  29. *
  30. * movieClips hiberarchy:
  31. * _root (5 frames)
  32. * |----dejagnuclip(placed at 1st frame of main timeline)
  33. * |----mc1
  34. * |----mc11
  35. * |----mc12
  36. * |----mc121
  37. * |----mc1211
  38. *
  39. * expected onClipEvents order:
  40. * mc1.OnLoad;
  41. * mc11.OnLoad;
  42. * mc12.OnLoad; mc121.OnLoad; mc1211.OnLoad;
  43. * mc1211.OnEnterFrame; mc121.OnEnterFrame; mc12.OnEnterFrame
  44. * mc11.OnEnterFrame;
  45. * mc1.OnEnterFrame;
  46. * mc1211.OnUnload; mc121.OnUnload; mc12.OnUnload;
  47. * mc11.OnUnload;
  48. * mc1.OnUnload;
  49. *
  50. * The actual order of tags are dependent on compiler, so you need to
  51. * verify first if the order of tags is what you expect.
  52. */
  53. #include <stdlib.h>
  54. #include <stdio.h>
  55. #include <ming.h>
  56. #include "ming_utils.h"
  57. #define OUTPUT_VERSION 6
  58. #define OUTPUT_FILENAME "action_execution_order_test5.swf"
  59. int
  60. main(int argc, char** argv)
  61. {
  62. SWFMovie mo;
  63. SWFMovieClip mc1, mc11, mc12, mc121, mc1211, dejagnuclip;
  64. SWFDisplayItem it1, it11, it12, it121, it1211;
  65. const char *srcdir=".";
  66. if ( argc>1 )
  67. srcdir=argv[1];
  68. else
  69. {
  70. fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
  71. return 1;
  72. }
  73. Ming_init();
  74. mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  75. SWFMovie_setDimension(mo, 800, 600);
  76. SWFMovie_setRate (mo, 12.0);
  77. dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  78. SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  79. SWFMovie_nextFrame(mo); /* 1st frame of _root */
  80. /*===================== Start of defining movieClips ==========================*/
  81. mc1211 = newSWFMovieClip();
  82. SWFMovieClip_nextFrame(mc1211); /* mc1211, 1st frame */
  83. SWFMovieClip_nextFrame(mc1211); /* mc1211, 2nd frame */
  84. mc121 = newSWFMovieClip();
  85. /* add mc1211 to mc121 and name it as "mc1211" */
  86. it1211 = SWFMovieClip_add(mc121, (SWFBlock)mc1211);
  87. SWFDisplayItem_setDepth(it1211, 1);
  88. SWFDisplayItem_setName(it1211, "mc1211");
  89. /* add onClipEvents */
  90. SWFDisplayItem_addAction(it1211, // the inner most child
  91. compileSWFActionCode(" _root.note('mc1211 onInitialize called'); "
  92. " _root.check_equals(this.__proto__, MovieClip.prototype);"
  93. " _root.check_equals(this._parent.__proto__, MovieClip.prototype);"
  94. " _root.check_equals(this._parent._parent.__proto__, MovieClip.prototype);"),
  95. SWFACTION_INIT);
  96. SWFDisplayItem_addAction(it1211,
  97. compileSWFActionCode(" _root.note('mc1211 onLoad called'); "
  98. " _root.x1 += '5+'; "),
  99. SWFACTION_ONLOAD);
  100. SWFDisplayItem_addAction(it1211,
  101. compileSWFActionCode(" _root.note('mc1211 onUnload called'); "
  102. " _root.x1 += '11+'; "),
  103. SWFACTION_UNLOAD);
  104. SWFDisplayItem_addAction(it1211,
  105. compileSWFActionCode(" _root.note('mc1211 onEnterFrame called'); "
  106. " _root.x1 += '6+'; "),
  107. SWFACTION_ENTERFRAME);
  108. SWFMovieClip_nextFrame(mc121); /* mc121, 1st frame */
  109. SWFMovieClip_nextFrame(mc121); /* mc121, 2nd frame */
  110. mc12 = newSWFMovieClip();
  111. /* add mc121 to mc12 and name it as "mc121" */
  112. it121 = SWFMovieClip_add(mc12, (SWFBlock)mc121);
  113. SWFDisplayItem_setDepth(it121, 1);
  114. SWFDisplayItem_setName(it121, "mc121");
  115. /* add onClipEvents */
  116. SWFDisplayItem_addAction(it121,
  117. compileSWFActionCode(" _root.note('mc121 onLoad called'); "
  118. " _root.x1 += '4+'; "),
  119. SWFACTION_ONLOAD);
  120. SWFDisplayItem_addAction(it121,
  121. compileSWFActionCode(" _root.note('mc121 onUnload called'); "
  122. " _root.x1 += '12+'; "),
  123. SWFACTION_UNLOAD);
  124. SWFDisplayItem_addAction(it121,
  125. compileSWFActionCode(" _root.note('mc121 onEnterFrame called'); "
  126. " _root.x1 += '7+'; "),
  127. SWFACTION_ENTERFRAME);
  128. SWFMovieClip_nextFrame(mc12); /* mc12, 1st frame */
  129. SWFMovieClip_nextFrame(mc12); /* mc12, 2nd frame */
  130. mc11 = newSWFMovieClip();
  131. SWFMovieClip_nextFrame(mc11); /* mc11, 1st frame */
  132. SWFMovieClip_nextFrame(mc11); /* mc11, 2nd frame */
  133. mc1 = newSWFMovieClip();
  134. /* add mc11 to mc1 and name it as "mc11" */
  135. it11 = SWFMovieClip_add(mc1, (SWFBlock)mc11);
  136. SWFDisplayItem_setDepth(it11, 2);
  137. /* add onClipEvents */
  138. SWFDisplayItem_setName(it11, "mc11");
  139. SWFDisplayItem_addAction(it11,
  140. compileSWFActionCode(" _root.note('mc11 onLoad called'); "
  141. " _root.x1 += '2+'; "),
  142. SWFACTION_ONLOAD);
  143. SWFDisplayItem_addAction(it11,
  144. compileSWFActionCode(" _root.note('mc11 onUnload called'); "
  145. " _root.x1 += '14+'; "),
  146. SWFACTION_UNLOAD);
  147. SWFDisplayItem_addAction(it11,
  148. compileSWFActionCode(" _root.note('mc11 onEnterFrame called'); "
  149. " _root.x1 += '9+'; "),
  150. SWFACTION_ENTERFRAME);
  151. /* add mc12 to mc1 and name it as "mc12" */
  152. it12 = SWFMovieClip_add(mc1, (SWFBlock)mc12);
  153. SWFDisplayItem_setDepth(it12, 1);
  154. SWFDisplayItem_setName(it12, "mc12");
  155. /* add onClipEvents */
  156. SWFDisplayItem_addAction(it12,
  157. compileSWFActionCode(" _root.note('mc12 onInitialize called'); "
  158. " _root.check_equals(this, _root.mc1.mc12);"
  159. " _root.check_equals(this.__proto__, MovieClip.prototype);"
  160. " _root.check_equals(this._parent.__proto__, MovieClip.prototype);"
  161. " _root.check_equals(this._parent.mc11.__proto__, MovieClip.prototype);"
  162. // test child __proto__
  163. " _root.check_equals(this.mc121.__proto__, MovieClip.prototype);"),
  164. SWFACTION_INIT);
  165. SWFDisplayItem_addAction(it12, // the inner most child
  166. compileSWFActionCode(" _root.note('mc12 onConstruct called'); "
  167. " _root.check_equals(this, _root.mc1.mc12);"
  168. " _root.check_equals(this.__proto__, MovieClip.prototype);"
  169. " _root.check_equals(this._parent.__proto__, MovieClip.prototype);"
  170. " _root.check_equals(this._parent.mc11.__proto__, MovieClip.prototype);"
  171. " _root.check_equals(this.mc121.__proto__, MovieClip.prototype);"),
  172. SWFACTION_CONSTRUCT);
  173. SWFDisplayItem_addAction(it12,
  174. compileSWFActionCode(" _root.note('mc12 onLoad called'); "
  175. " _root.x1 += '3+'; "),
  176. SWFACTION_ONLOAD);
  177. SWFDisplayItem_addAction(it12,
  178. compileSWFActionCode(" _root.note('mc12 onUnload called'); "
  179. " _root.x1 += '13+'; "),
  180. SWFACTION_UNLOAD);
  181. SWFDisplayItem_addAction(it12,
  182. compileSWFActionCode(" _root.note('mc12 onEnterFrame called'); "
  183. " _root.x1 += '8+'; "),
  184. SWFACTION_ENTERFRAME);
  185. SWFMovieClip_nextFrame(mc1); /* mc1, 1st frame */
  186. SWFMovieClip_nextFrame(mc1); /* mc1, 2nd frame */
  187. /*===================== End of defining movieClips ==========================*/
  188. it1 = SWFMovie_add(mo, (SWFBlock)mc1);
  189. /* add onClipEvents */
  190. SWFDisplayItem_addAction(it1,
  191. compileSWFActionCode(" _root.note('mc1 onLoad called'); "
  192. " _root.x1 += '1+'; "),
  193. SWFACTION_ONLOAD);
  194. SWFDisplayItem_addAction(it1,
  195. compileSWFActionCode(" _root.note('mc1 onUnload called'); "
  196. " _root.x1 += '15+'; "),
  197. SWFACTION_UNLOAD);
  198. SWFDisplayItem_addAction(it1,
  199. compileSWFActionCode(" _root.note('mc1 onEnterFrame called'); "
  200. " _root.x1 += '10+'; "),
  201. SWFACTION_ENTERFRAME);
  202. /* place _root.mc1 */
  203. SWFDisplayItem_setDepth(it1, 10);
  204. SWFDisplayItem_setName(it1, "mc1");
  205. SWFMovie_nextFrame(mo); /* 2nd frame of _root */
  206. SWFMovie_nextFrame(mo); /* 3rd frame of _root */
  207. /* remove _root.mc1 */
  208. SWFDisplayItem_remove(it1);
  209. SWFMovie_nextFrame(mo); /* 4th frame of _root */
  210. /* checks */
  211. check_equals(mo, "_root.x1", "'1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+'");
  212. add_actions(mo, " _root.totals(); stop(); ");
  213. SWFMovie_nextFrame(mo); /* 5th frame of _root */
  214. //Output movie
  215. puts("Saving " OUTPUT_FILENAME );
  216. SWFMovie_save(mo, OUTPUT_FILENAME);
  217. return 0;
  218. }