1 /*
2 * Copyright (C) 2005, 2006, 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 /*
20 * zou lunkai zoulunkai@gmail.com
21 *
22 * Test "this" context in the UNLOAD event handler.
23 *
24 * run as ./unload_movieclip_test1
25 */
26
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <ming.h>
31
32 #include "ming_utils.h"
33
34 #define OUTPUT_VERSION 6
35 #define OUTPUT_FILENAME "unload_movieclip_test1.swf"
36
37 SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth);
38
39 SWFDisplayItem
add_static_mc(SWFMovie mo,const char * name,int depth)40 add_static_mc(SWFMovie mo, const char* name, int depth)
41 {
42 SWFMovieClip mc;
43 SWFDisplayItem it;
44
45 mc = newSWFMovieClip();
46 SWFMovieClip_nextFrame(mc);
47
48 it = SWFMovie_add(mo, (SWFBlock)mc);
49 SWFDisplayItem_setDepth(it, depth);
50 SWFDisplayItem_setName(it, name);
51
52 return it;
53 }
54
55 int
main(int argc,char ** argv)56 main(int argc, char** argv)
57 {
58 SWFMovie mo;
59 SWFMovieClip dejagnuclip;
60 SWFDisplayItem it;
61
62 const char *srcdir=".";
63 if ( argc>1 )
64 srcdir=argv[1];
65 else
66 {
67 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
68 return 1;
69 }
70
71 Ming_init();
72 Ming_useSWFVersion (OUTPUT_VERSION);
73
74 mo = newSWFMovie();
75 SWFMovie_setDimension(mo, 800, 600);
76 SWFMovie_setRate(mo, 2);
77
78 // Frame 1: Place dejagnu clip and init testing variables
79
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, "_root.x = 0;");
83 SWFMovie_nextFrame(mo);
84
85 // Frame 2: Place a static mc and define onUnload for it
86
87 it = add_static_mc(mo, "mc", 3);
88 add_actions(mo, "mc.onUnload = function () { "
89 " _root.x = this._currentframe; "
90 " _root.check_equals(typeof(this), 'movieclip'); "
91 " _root.check_equals(this, _root.mc); "
92 "};");
93 SWFMovie_nextFrame(mo);
94
95 // Frame 3: Remove the mc to trigger onUnload
96
97 SWFDisplayItem_remove(it);
98 SWFMovie_nextFrame(mo);
99
100 // Frame 4: checks
101
102 check_equals(mo, "_root.x", "1");
103
104 add_actions(mo, "_root.totals(); stop(); ");
105 SWFMovie_nextFrame(mo);
106
107 //Output movie
108 puts("Saving " OUTPUT_FILENAME );
109 SWFMovie_save(mo, OUTPUT_FILENAME);
110
111 return 0;
112 }
113
114