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
22 * Test "this" context in the UNLOAD event handler.
24 * run as ./unload_movieclip_test1
32 #include "ming_utils.h"
34 #define OUTPUT_VERSION 6
35 #define OUTPUT_FILENAME "unload_movieclip_test1.swf"
37 SWFDisplayItem
add_static_mc(SWFMovie mo
, const char* name
, int depth
);
40 add_static_mc(SWFMovie mo
, const char* name
, int depth
)
45 mc
= newSWFMovieClip();
46 SWFMovieClip_nextFrame(mc
);
48 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
49 SWFDisplayItem_setDepth(it
, depth
);
50 SWFDisplayItem_setName(it
, name
);
56 main(int argc
, char** argv
)
59 SWFMovieClip dejagnuclip
;
62 const char *srcdir
=".";
67 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
72 Ming_useSWFVersion (OUTPUT_VERSION
);
75 SWFMovie_setDimension(mo
, 800, 600);
76 SWFMovie_setRate(mo
, 2);
78 // Frame 1: Place dejagnu clip and init testing variables
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
);
85 // Frame 2: Place a static mc and define onUnload for it
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); "
93 SWFMovie_nextFrame(mo
);
95 // Frame 3: Remove the mc to trigger onUnload
97 SWFDisplayItem_remove(it
);
98 SWFMovie_nextFrame(mo
);
102 check_equals(mo
, "_root.x", "1");
104 add_actions(mo
, "_root.totals(); stop(); ");
105 SWFMovie_nextFrame(mo
);
108 puts("Saving " OUTPUT_FILENAME
);
109 SWFMovie_save(mo
, OUTPUT_FILENAME
);