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 * Zou Lunkai, zoulunkai@gmail.com
22 * Test for DoInitAction tag.
24 * Tags order(compiled with Ming0.4.beta4):
25 * DefineMovieClip(mc1)
28 * DefineMovieClip(mc2)
32 * Tests show that the actions order is like this:
34 * mc1.onClipInitialize
36 * mc2.onClipInitialize
50 #include "ming_utils.h"
52 #define OUTPUT_VERSION 6
53 #define OUTPUT_FILENAME "init_action_test.swf"
57 main(int argc
, char** argv
)
60 SWFMovieClip mc1
, mc2
, dejagnuclip
;
63 const char *srcdir
=".";
68 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
73 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
74 SWFMovie_setDimension(mo
, 800, 600);
75 SWFMovie_setRate (mo
, 12.0);
77 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
78 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
80 add_actions(mo
, " _root.x = '0+'; ");
81 SWFMovie_nextFrame(mo
); /* 1st frame */
84 mc1
= newSWFMovieClip();
85 sh1
= make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0);
86 SWFMovieClip_add(mc1
, (SWFBlock
)sh1
);
87 /* add init actions */
88 add_clip_init_actions(mc1
, " _root.note('mc1.init_actions'); "
90 " y = 'var_of_root'; " );
93 add_clip_actions(mc1
, " _root.note('mc1.actions'); _root.x += '9+'; ");
94 SWFMovieClip_nextFrame(mc1
);//1st frame
96 mc2
= newSWFMovieClip();
97 sh2
= make_fill_square (600, 600, 60, 60, 255, 0, 0, 255, 0, 0);
98 SWFMovieClip_add(mc2
, (SWFBlock
)sh2
);
99 /* add init actions */
100 add_clip_init_actions(mc2
, " _root.note('mc2.init_actions'); _root.x += '3+'; ");
102 add_clip_actions(mc2
, " _root.note('mc2.actions'); _root.x += '11+'; ");
103 SWFMovieClip_nextFrame(mc2
);//1st frame
106 /* add mc1 to _root */
108 it1
= SWFMovie_add(mo
, (SWFBlock
)mc1
);
109 SWFDisplayItem_setDepth(it1
, 10);
110 SWFDisplayItem_setName(it1
, "mc1");
112 SWFDisplayItem_addAction(it1
,
113 newSWFAction(" _root.note('mc1.onClipInitialize'); _root.x += '2+'; "
114 "_root.check_equals(this.__proto__, MovieClip.prototype);"
118 SWFDisplayItem_addAction(it1
,
119 newSWFAction(" _root.note('mc1.onClipConstruct'); _root.x += '5+'; "),
120 SWFACTION_CONSTRUCT
);
122 SWFDisplayItem_addAction(it1
,
123 newSWFAction(" _root.note('mc1.onClipLoad'); _root.x += '8+'; "),
127 /* add mc2 to _root */
129 it2
= SWFMovie_add(mo
, (SWFBlock
)mc2
);
130 SWFDisplayItem_setDepth(it2
, 11);
131 SWFDisplayItem_setName(it2
, "mc2");
133 SWFDisplayItem_addAction(it2
,
134 newSWFAction(" _root.note('mc2.onClipInitialize'); _root.x += '4+'; "),
137 SWFDisplayItem_addAction(it2
,
138 newSWFAction(" _root.note('mc2.onClipConstruct'); _root.x += '6+'; "),
139 SWFACTION_CONSTRUCT
);
141 SWFDisplayItem_addAction(it2
,
142 newSWFAction(" _root.note('mc2.onClipLoad'); _root.x += '10+'; "),
146 /* add main timeline actions */
147 add_actions(mo
, "_root.note('_root.actions'); _root.x += '7+'; ");
148 SWFMovie_nextFrame(mo
); /* 2nd frame */
150 /* The check below used to succeeds, and started failing when
151 * executing init actions "after" DLIST tags.
152 * Should be fixed if we postpone the call to ::construct
153 * to "after" init actions are executed, which would require
154 * some book keeping in sprite_instance class
156 check_equals(mo
, "_root.x", "'0+1+2+3+4+5+6+7+8+9+10+11+'");
158 check_equals(mo
, "_root.y", "'var_of_root'");
159 add_actions(mo
, " _root.totals(); stop(); ");
160 SWFMovie_nextFrame(mo
); /* 3rd frame */
164 puts("Saving " OUTPUT_FILENAME
);
165 SWFMovie_save(mo
, OUTPUT_FILENAME
);