2 * Copyright (C) 2005, 2006, 2007, 2009, 2010,
3 * 2011 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "ming_utils.h"
25 #define OUTPUT_VERSION 8
26 #define OUTPUT_FILENAME "RegisterClassTest3.swf"
30 main(int argc
, char** argv
)
33 SWFMovieClip mc3
, mc2
, dejagnuclip
;
34 SWFAction ac
, ac1
, initac
;
38 const char *srcdir
=".";
39 if (argc
> 1) srcdir
= argv
[1];
41 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
46 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
47 SWFMovie_setDimension(mo
, 800, 600);
48 SWFMovie_setRate (mo
, 12.0);
53 // Character ID 2. Has 1 showframe. Is exported first.
54 mc2
= newSWFMovieClip();
55 SWFMovieClip_add(mc2
, (SWFBlock
)sha
);
56 SWFMovieClip_nextFrame(mc2
);
59 SWFMovie_addExport(mo
, (SWFBlock
)mc2
, "C2");
60 SWFMovie_writeExports(mo
);
62 // Main timeline actions for frame 1
63 add_actions(mo
, "var c = 0; var i = 0; trace('frame 1'); gotoAndStop(3);");
64 initac
= newSWFAction("trace('onInitialize'); _root.i++;");
66 // ID 3 is defined here. It has no showframe. It is exported immediately.
67 mc3
= newSWFMovieClip();
68 SWFMovie_addExport(mo
, (SWFBlock
)mc3
, "ctor");
69 SWFMovie_writeExports(mo
);
71 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10,
73 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
75 // Init actions for ID 3. This only exists to create the constructor
76 // for mc2 in its initactions.
78 " _global.ctor = function () {"
80 " trace('Object ID 2 is constructed');"
84 SWFInitAction ia
= newSWFInitAction_withId(ac
, 3);
85 SWFMovie_add(mo
, (SWFBlock
)ia
);
87 // Init actions for ID 2 (registered class)
88 ac1
= newSWFAction("Object.registerClass('C2', ctor); "
89 "trace('Registered class');");
90 ia
= newSWFInitAction_withId(ac1
, 2);
91 SWFMovie_add(mo
, (SWFBlock
)ia
);
95 SWFMovie_nextFrame(mo
);
96 add_actions(mo
, "trace('Frame 2');");
99 it
= SWFMovie_add(mo
, (SWFBlock
)mc2
);
100 SWFDisplayItem_setName(it
, "mc2");
101 SWFDisplayItem_addAction(it
, initac
, SWFACTION_INIT
);
104 SWFMovie_nextFrame(mo
);
106 // Remove object ID 2
107 SWFMovie_remove(mo
, it
);
109 add_actions(mo
, "trace('frame 3');");
111 // The class should not be constructed if the object is removed after
112 // being placed. It should be constructed if it's not removed. MovieClips
113 // with an onUnload handler are always constructed.
114 check_equals(mo
, "c", "0");
115 check_equals(mo
, "i", "0");
116 check(mo
, "_root.mc2 == undefined");
117 add_actions(mo
, "gotoAndPlay(5);");
120 SWFMovie_nextFrame(mo
);
121 add_actions(mo
, "trace('Frame 4');");
123 // Place object ID 2 again
124 it
= SWFMovie_add(mo
, (SWFBlock
)mc2
);
125 SWFDisplayItem_setName(it
, "mc2a");
126 SWFDisplayItem_addAction(it
, initac
, SWFACTION_INIT
);
129 SWFMovie_nextFrame(mo
);
131 // This time the MovieClip was not removed before we get here,
132 // so it should be present and the constructor should be
134 add_actions(mo
, "trace('frame 5');");
135 check_equals(mo
, "c", "1");
136 check_equals(mo
, "i", "1");
137 check(mo
, "typeof(_root.mc2a) == 'movieclip'");
138 add_actions(mo
, "stop();");
140 SWFMovie_nextFrame(mo
);
142 puts("Saving " OUTPUT_FILENAME
);
143 SWFMovie_save(mo
, OUTPUT_FILENAME
);