2 * Copyright (C) 2005, 2006, 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
23 * Timeline(starts from test2):
25 * Frame | 7 | 8 | 9 | 10| 11| 12|
26 * --------+---+---+---+---+---+---+
27 * Event | J | P | R | P | R | * |
29 * P = place (by PlaceObject2)
30 * R = remove (by RemoveObject2)
36 * frame7: gotoAndPlay(12);
37 * frame8: place mc1 at depth 100
39 * frame10: place mc2 at depth 100
45 * (1) both mc1 and mc2 occupys depth -16485 after gotoFrame.
46 * (2) both mc1 and mc2 are visible in frame7 at runtime.
50 * (1) different DisplayObjects in the removed depths zone could share the same depth.
51 * (2) DisplayList::testInvariant() probably fails.
59 #include "ming_utils.h"
61 #define OUTPUT_VERSION 6
62 #define OUTPUT_FILENAME "goto_frame_test.swf"
65 SWFDisplayItem
add_static_mc(SWFMovie mo
, const char* name
, int depth
);
68 add_static_mc(SWFMovie mo
, const char* name
, int depth
)
73 mc
= newSWFMovieClip();
74 SWFMovieClip_nextFrame(mc
);
76 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
77 SWFDisplayItem_setDepth(it
, depth
);
78 SWFDisplayItem_setName(it
, name
);
83 main(int argc
, char** argv
)
86 SWFMovieClip mc_red
, dejagnuclip
;
88 SWFDisplayItem it_red
, it
;
90 const char *srcdir
=".";
95 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
100 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
101 SWFMovie_setDimension(mo
, 800, 600);
102 SWFMovie_setRate (mo
, 12.0);
104 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
105 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
106 // Add a ShowFrame here, do all checks at later frames!
107 // This will guarantee all the check-functions are defined before we call them.
108 add_actions(mo
, "asOrder = '0+';");
109 SWFMovie_nextFrame(mo
); //1st frame
111 mc_red
= newSWFMovieClip();
112 sh_red
= make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
113 SWFMovieClip_add(mc_red
, (SWFBlock
)sh_red
);
114 SWFMovieClip_nextFrame(mc_red
);//1st frame
115 SWFMovieClip_nextFrame(mc_red
);//2st frame
116 add_clip_actions(mc_red
, "_root.asOrder += '3+';"
118 SWFMovieClip_nextFrame(mc_red
);//3nd frame
120 add_clip_actions(mc_red
, "_root.asOrder += '7+'; stop();");
121 SWFMovieClip_nextFrame(mc_red
);//4th frame
123 it_red
= SWFMovie_add(mo
, (SWFBlock
)mc_red
);
124 SWFDisplayItem_setDepth(it_red
, 3);
125 SWFDisplayItem_setName(it_red
, "mc_red");
127 add_actions(mo
, "_root.asOrder += '1+';"
128 "check_equals(mc_red._currentframe, 1); "
129 "mc_red.gotoAndStop(3);"
130 "check_equals(mc_red._currentframe, 3); "
131 "_root.gotoAndStop(3);"
132 "_root.asOrder += '2+';" );
133 SWFMovie_nextFrame(mo
); //2nd frame
135 add_actions(mo
, "_root.asOrder += '4+';"
136 "_root.gotoAndStop(4);"
137 "_root.asOrder += '5+';");
138 SWFMovie_nextFrame(mo
); //3nd frame
140 add_actions(mo
, "_root.asOrder += '6+';"
141 " _root.gotoAndPlay(5);");
142 SWFMovie_nextFrame(mo
); //4nd frame
145 check_equals(mo
, "_root.asOrder", "'0+1+2+3+4+5+6+'");
146 SWFMovie_nextFrame(mo
); //5th frame
148 check_equals(mo
, "_root.asOrder", "'0+1+2+3+4+5+6+7+'");
149 SWFMovie_nextFrame(mo
); //6th frame
152 // test2: test forward gotoFrame
154 add_actions(mo
, "gotoAndPlay(_currentframe + 5);");
155 check_equals(mo
, "mc1._target", "'/mc1'");
156 check_equals(mo
, "mc2._target", "'/mc2'");
157 SWFMovie_nextFrame(mo
); // 7th frame
160 it
= add_static_mc(mo
, "mc1", 100);
161 SWFDisplayItem_addAction(it
, newSWFAction(
162 "_root.note(this+' unloaded');"
163 ), SWFACTION_UNLOAD
);
164 SWFMovie_nextFrame(mo
); // 8th frame
167 SWFDisplayItem_remove(it
);
168 SWFMovie_nextFrame(mo
); // 9th frame
171 it
= add_static_mc(mo
, "mc2", 100);
172 SWFDisplayItem_addAction(it
, newSWFAction(
173 "_root.note(this+' unloaded');"
174 ), SWFACTION_UNLOAD
);
175 SWFMovie_nextFrame(mo
); // 10th frame
178 SWFDisplayItem_remove(it
);
179 SWFMovie_nextFrame(mo
); // 11th frame
182 check_equals(mo
, "mc1.getDepth()", "-16485");
183 check_equals(mo
, "mc1._name", "'mc1'");
184 check_equals(mo
, "mc2.getDepth()", "-16485");
185 check_equals(mo
, "mc2._name", "'mc2'");
187 add_actions(mo
, "totals(); stop();");
188 SWFMovie_nextFrame(mo
); // 12th frame
191 puts("Saving " OUTPUT_FILENAME
);
192 SWFMovie_save(mo
, OUTPUT_FILENAME
);