1 /*
2  *   Copyright (C) 2005, 2006, 2007, 2009, 2010,
3  *   2011 Free Software Foundation, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  */
19 
20 /*
21  * Zou Lunkai, zoulunkai@gmail.com
22  *
23  *
24  * expected behaviour:
25  * (1) Within the same frame, if PlaceObject(mc1) is before PlaceObject(mc2),
26  *     then frame0 actions of mc1 should be executed before frame0 actions of mc2.
27  * (2) Within the same timeline, frame actions(frameNum>0) of fisrt placed sprites executed last.
28  *
29  * The actual order of tags are dependent on compiler, so you need to
30  * verify first if the order of tags is what you expect.
31  */
32 
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <ming.h>
36 
37 #include "ming_utils.h"
38 
39 #define OUTPUT_VERSION 6
40 #define OUTPUT_FILENAME "action_execution_order_test2.swf"
41 
42 
43 int
main(int argc,char ** argv)44 main(int argc, char** argv)
45 {
46   SWFMovie mo;
47   SWFMovieClip  mc_red1, mc_red2, mc_red3, mc_red4, mc_red5, dejagnuclip;
48   SWFDisplayItem it_red1, it_red2, it_red3, it_red4, it_red5;
49   SWFShape  sh_red;
50 
51   const char *srcdir=".";
52   if ( argc>1 )
53     srcdir=argv[1];
54   else
55   {
56       fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
57       return 1;
58   }
59 
60   Ming_init();
61   mo = newSWFMovieWithVersion(OUTPUT_VERSION);
62   SWFMovie_setDimension(mo, 800, 600);
63   SWFMovie_setRate (mo, 12.0);
64 
65   dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
66   SWFMovie_add(mo, (SWFBlock)dejagnuclip);
67   SWFMovie_nextFrame(mo); /* 1st frame */
68 
69 
70   mc_red1 = newSWFMovieClip();
71   sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
72   SWFMovieClip_add(mc_red1, (SWFBlock)sh_red);
73   add_clip_actions(mc_red1, " _root.x1 += \"depth10+\"; ");
74   SWFMovieClip_nextFrame(mc_red1); /* mc_red1, 1st frame */
75   add_clip_actions(mc_red1, " _root.x2 += \"depth10+\"; stop(); ");
76   SWFMovieClip_nextFrame(mc_red1); /* mc_red1, 2nd frame */
77 
78   mc_red2 = newSWFMovieClip();
79   sh_red = make_fill_square (80, 300, 60, 60, 255, 0, 0, 255, 0, 0);
80   SWFMovieClip_add(mc_red2, (SWFBlock)sh_red);
81   add_clip_actions(mc_red2, " _root.x1 += \"depth12+\"; ");
82   SWFMovieClip_nextFrame(mc_red2); /* mc_red2, 1st frame */
83   add_clip_actions(mc_red2, " _root.x2 += \"depth12+\"; stop(); ");
84   SWFMovieClip_nextFrame(mc_red2); /* mc_red2, 2nd frame */
85 
86   mc_red3 = newSWFMovieClip();
87   sh_red = make_fill_square (160, 300, 60, 60, 255, 0, 0, 255, 0, 0);
88   SWFMovieClip_add(mc_red3, (SWFBlock)sh_red);
89   add_clip_actions(mc_red3, " _root.x1 += \"depth11+\"; ");
90   SWFMovieClip_nextFrame(mc_red3); /* mc_red3, 1st frame */
91   add_clip_actions(mc_red3, " _root.x2 += \"depth11+\";  stop();");
92   SWFMovieClip_nextFrame(mc_red3); /* mc_red3, 2nd frame */
93 
94 
95   /* add mc_red1 to _root and name it as "mc_red1" */
96   it_red1 = SWFMovie_add(mo, (SWFBlock)mc_red1);
97   SWFDisplayItem_setDepth(it_red1, 10);
98   SWFDisplayItem_setName(it_red1, "mc_red1");
99 
100   /* add mc_red2 to _root and name it as "mc_red2" */
101   it_red2 = SWFMovie_add(mo, (SWFBlock)mc_red2);
102   SWFDisplayItem_setDepth(it_red2, 12);
103   SWFDisplayItem_setName(it_red2, "mc_red2");
104 
105   /* add mc_red3 to _root and name it as "mc_red3" */
106   it_red3 = SWFMovie_add(mo, (SWFBlock)mc_red3);
107   SWFDisplayItem_setDepth(it_red3, 11);
108   SWFDisplayItem_setName(it_red3, "mc_red3");
109 
110   SWFMovie_nextFrame(mo); /* 2nd frame */
111 
112   /* Action order is not dependent on DisplayList depth here! */
113   check_equals(mo, "_root.x1", "'depth10+depth12+depth11+'");
114   SWFMovie_nextFrame(mo); /* 3rd frame */
115 
116   mc_red4 = newSWFMovieClip();
117   sh_red = make_fill_square (240, 300, 60, 60, 255, 0, 0, 255, 0, 0);
118   SWFMovieClip_add(mc_red4, (SWFBlock)sh_red);
119   add_clip_actions(mc_red4, " _root.x2 += \"depth9+\"; ");
120   SWFMovieClip_nextFrame(mc_red4); /* mc_red4, 1st frame */
121 
122    /* add mc_red4 to _root and name it as "mc_red4" */
123   it_red4 = SWFMovie_add(mo, (SWFBlock)mc_red4);
124   SWFDisplayItem_setDepth(it_red4, 9);
125   SWFDisplayItem_setName(it_red4, "mc_red4");
126 
127   mc_red5 = newSWFMovieClip();
128   sh_red = make_fill_square (240, 300, 60, 60, 255, 0, 0, 255, 0, 0);
129   SWFMovieClip_add(mc_red5, (SWFBlock)sh_red);
130   add_clip_actions(mc_red5, " _root.x2 += \"depth13+\"; ");
131   SWFMovieClip_nextFrame(mc_red5); /* mc_red4, 1st frame */
132 
133   /* add mc_red5 to _root and name it as "mc_red5" */
134   it_red5 = SWFMovie_add(mo, (SWFBlock)mc_red5);
135   SWFDisplayItem_setDepth(it_red5, 13);
136   SWFDisplayItem_setName(it_red5, "mc_red4");
137 
138   SWFMovie_nextFrame(mo); /* 4th frame */
139 
140 
141   check_equals(mo, "_root.x2", "'depth11+depth12+depth10+depth9+depth13+'");
142   add_actions(mo, " _root.totals(); stop(); ");
143   SWFMovie_nextFrame(mo); /* 5th frame */
144 
145 
146   //Output movie
147   puts("Saving " OUTPUT_FILENAME );
148   SWFMovie_save(mo, OUTPUT_FILENAME);
149 
150   return 0;
151 }
152 
153 
154 
155