2 * Copyright (C) 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 * Test "Jumping backward to the end of a DisplayObject's lifetime (with events: onConstruct)"
24 * Frame | 1 | 2 | 3 | 4 | 5 | 6 |
25 * --------+---+---+---+---+---+---+
26 * Event | | PP| RR| * | J | |
28 * P = place (by PlaceObject2)
29 * R = remove (by RemoveObject* tag)
35 * frame2: (1)a static DisplayObject(movieclip1) is placed at depth 3 (-16381) [ a red square ]
36 * onInitialize and onConstruct event handlers defined, onUnload event handler NOT defined.
37 * (2)a static DisplayObject(movieclip2) is placed at depth 4 [a green square]
38 * onInitialize and onConstruct event handlers defined, onUnload event handler also defined.
39 * frame3: (1)DisplayObject at depth 3 (-16381) removed.
40 * (2)DisplayObject at depth 4 removed.
41 * frame5: jump back to frame 4 and stop
46 * (1)the onInitialize and onConstruct event handler for the red square has been
48 * (2)the onInitialize and onConstruct event handlers for the green square has been
59 #include "ming_utils.h"
61 #define OUTPUT_VERSION 7
62 #define OUTPUT_FILENAME "loop_test6.swf"
66 main(int argc
, char** argv
)
69 SWFMovieClip mc1
, mc2
, dejagnuclip
;
70 SWFDisplayItem it1
, it2
;
73 const char *srcdir
=".";
78 //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
83 Ming_useSWFVersion (OUTPUT_VERSION
);
86 SWFMovie_setDimension(mo
, 800, 600);
87 SWFMovie_setRate(mo
, 6);
89 // Frame 1: Place dejagnu clip
91 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
92 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
93 add_actions(mo
, "mc1Initialized=0; mc1Constructed=0; mc2Initialized=0; mc2Constructed=0; ");
94 SWFMovie_nextFrame(mo
);
98 // Place red static movieClip1 DisplayObject at depth 3 (-16381)
99 // Place green static movieClip2 DisplayObject at depth 4 (-16380)
101 sh1
= make_fill_square (100, 300, 60, 60, 255, 0, 0, 255, 0, 0);
102 mc1
= newSWFMovieClip();
103 SWFMovieClip_add(mc1
, (SWFBlock
)sh1
);
104 SWFMovieClip_nextFrame(mc1
);
106 sh2
= make_fill_square (300, 400, 60, 60, 255, 0, 0, 0, 255, 0);
107 mc2
= newSWFMovieClip();
108 SWFMovieClip_add(mc2
, (SWFBlock
)sh2
);
109 SWFMovieClip_nextFrame(mc2
);
111 it1
= SWFMovie_add(mo
, (SWFBlock
)mc1
); //add movieClip1 to the _root
112 SWFDisplayItem_setDepth(it1
, 3);
113 SWFDisplayItem_setName(it1
, "movieClip1"); //name movieClip1
114 SWFDisplayItem_addAction(it1
, newSWFAction(
115 "_root.note(this+' constructed');"
116 "_root.mc1Constructed++;"
117 ), SWFACTION_CONSTRUCT
);
118 SWFDisplayItem_addAction(it1
, newSWFAction(
119 "_root.note(this+' initialized');"
120 "_root.mc1Initialized++;"
123 it2
= SWFMovie_add(mo
, (SWFBlock
)mc2
); //add movieClip2 to the _root
124 SWFDisplayItem_setDepth(it2
, 4);
125 SWFDisplayItem_setName(it2
, "movieClip2"); //name movieClip1
126 SWFDisplayItem_addAction(it2
, newSWFAction(
127 "_root.note(this+' constructed');"
128 "_root.mc2Constructed++;"
129 ), SWFACTION_CONSTRUCT
);
130 SWFDisplayItem_addAction(it2
, newSWFAction(
131 "_root.note(this+' initialized');"
132 "_root.mc2Initialized++;"
134 SWFDisplayItem_addAction(it2
, newSWFAction(
135 "_root.note(this+' unloaded');"
136 ), SWFACTION_UNLOAD
);
138 check_equals(mo
, "typeof(movieClip1)", "'movieclip'");
139 check_equals(mo
, "_root.mc1Constructed", "1");
140 check_equals(mo
, "typeof(movieClip2)", "'movieclip'");
141 check_equals(mo
, "_root.mc1Constructed", "1");
142 SWFMovie_nextFrame(mo
);
144 // Frame3: Remove movieclip1 and movieclip2
145 SWFDisplayItem_remove(it1
);
146 SWFDisplayItem_remove(it2
);
147 check_equals(mo
, "typeof(movieClip1)", "'undefined'");
148 check_equals(mo
, "_root.mc1Constructed", "1");
149 SWFMovie_nextFrame(mo
);
151 // Frame4: nothing new
152 SWFMovie_nextFrame(mo
);
154 // Frame5: check, gotoAndStop(4), check..
156 SWFMovie_add(mo
, (SWFBlock
)newSWFAction( "gotoAndStop(4);"));
157 check_equals(mo
, "typeof(movieClip1)", "'undefined'");
158 check_equals(mo
, "typeof(movieClip2)", "'movieclip'");
160 // onClipConstruct invoked or not during jumping back is dependent
161 // on whether the onClipUnload has been defined.
162 // Gnash fails by calling onClipConstruct again without considering onClipUnload!!
163 check_equals(mo
, "_root.mc1Constructed", "1");
164 check_equals(mo
, "_root.mc1Initialized", "1");
166 check_equals(mo
, "_root.mc2Constructed", "2");
167 check_equals(mo
, "_root.mc2Initialized", "2");
168 SWFMovie_add(mo
, (SWFBlock
)newSWFAction( "totals(); stop();" ));
169 SWFMovie_nextFrame(mo
);
172 puts("Saving " OUTPUT_FILENAME
);
173 SWFMovie_save(mo
, OUTPUT_FILENAME
);