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
23 * (1) step1: create a dynamic child in an onClipUnload handler of static_mc1;
24 * (2) step2: define a onUnload handler for the child;
25 * (3) step3: remove static_mc1;
29 * (1) onClipUnload for static_mc1 is triggered.
30 * (2) user defined onUnload for the dynamic child is NOT triggered.
31 * (3) the dynamic child is destroyed even without onUnload triggered.
34 * (1) step1: create a dynamic child in an onClipLoad handler of static_mc2;
35 * (2) step2: define a onUnload handler for the child;
36 * (3) step3: remove static_mc2;
40 * (1)onClipUnload for static_mc2 is triggered.
41 * (2)user defined onUnload for the dynamic child is triggered.
44 * seems createEmptyMovieClip() does not work in an user defined onUnload handler,
45 * not sure why, need more inspect later.
52 #include "ming_utils.h"
54 #define OUTPUT_VERSION 6
55 #define OUTPUT_FILENAME "new_child_in_unload_test.swf"
60 main(int argc
, char** argv
)
63 SWFMovieClip mc1
, mc2
, dejagnuclip
;
64 SWFDisplayItem it1
, it2
;
66 const char *srcdir
=".";
71 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
76 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
77 SWFMovie_setDimension(mo
, 800, 600);
78 SWFMovie_setRate (mo
, 12.0);
80 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
81 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
82 add_actions(mo
, "testvar1 = 0; testvar2 = 0;");
83 SWFMovie_nextFrame(mo
); // frame1
86 mc1
= newSWFMovieClip();
87 SWFMovieClip_nextFrame(mc1
);
88 it1
= SWFMovie_add(mo
, (SWFBlock
)mc1
);
89 SWFDisplayItem_setName(it1
, "static_mc1");
90 SWFDisplayItem_addAction(it1
,
92 " this.createEmptyMovieClip('dyn1', 100); "
93 " _root.check_equals(dyn1.getDepth(), 100);"
94 " _root.dyn1Ref = dyn1;"
95 // shouldn't be executed.
96 " dyn1.onUnload = function () { _root.check(false); } ;"
101 mc2
= newSWFMovieClip();
102 SWFMovieClip_nextFrame(mc2
);
103 it2
= SWFMovie_add(mo
, (SWFBlock
)mc2
);
104 SWFDisplayItem_setName(it2
, "static_mc2");
105 SWFDisplayItem_addAction(it2
,
107 " this.createEmptyMovieClip('dyn2', 200); "
108 " _root.check_equals(dyn2.getDepth(), 200);"
109 " dyn2.onUnload = function () {_root.dyn2testvar = 'executed'; } ;"
112 SWFDisplayItem_addAction(it2
,
114 " _root.check_equals(_level0.dyn1Ref.getDepth(), 100);"
115 " _level0.dyn1Ref.swapDepths(101); "
116 // Check that we can still swap the new child created in onClipUnload(mc1)
117 // Note mc1 is already unloaded(this is in mc2.unload).
118 " _root.check_equals(_level0.dyn1Ref.getDepth(), 101);"
121 SWFMovie_nextFrame(mo
); // frame2
123 SWFDisplayItem_remove(it1
);
124 SWFDisplayItem_remove(it2
);
125 SWFMovie_nextFrame(mo
); // frame3
127 check_equals(mo
, "typeof(_root.dyn1Ref)", "'movieclip'");
128 check_equals(mo
, "_root.dyn1Ref.valueof()", "null");
129 // check that dyn2.onUnload was triggered
130 check_equals(mo
, "_root.dyn2testvar", "'executed'");
131 SWFMovie_nextFrame(mo
); // frame4
133 add_actions(mo
, " _root.totals(7); stop(); ");
134 SWFMovie_nextFrame(mo
); // frame5
137 puts("Saving " OUTPUT_FILENAME
);
138 SWFMovie_save(mo
, OUTPUT_FILENAME
);