2 * Copyright (C) 2005, 2006, 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 * Within the same frame, ActionScript in DoAction tags can referance movieClip
23 * placed after DoAction tags.
25 * Within the same frame, ActionScript in onClipLoad handlers can referance
26 * movieClip placed after the PlaceObject2 tag defining the clip event.
28 * The actual order of tags are dependent on compiler, so you need to
29 * verify first if the order of tags is what you expect.
36 #include "ming_utils.h"
38 #define OUTPUT_VERSION 6
39 #define OUTPUT_FILENAME "action_execution_order_test1.swf"
43 main(int argc
, char** argv
)
46 SWFMovieClip mc_red
, mc_blu
, dejagnuclip
;
47 SWFShape sh_red
, sh_blu
;
48 SWFDisplayItem it_red
, it_blu
;
50 const char *srcdir
=".";
55 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
60 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
61 SWFMovie_setDimension(mo
, 800, 600);
62 SWFMovie_setRate (mo
, 12.0);
64 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
65 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
66 SWFMovie_nextFrame(mo
); /* 1st frame */
68 /* This will add a DoAction Tag, which be compiled before PlaceObject(mc_red) tag. */
69 check_equals(mo
, "typeof(_root.mc_red)", "'movieclip'");
71 mc_red
= newSWFMovieClip();
72 sh_red
= make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
73 SWFMovieClip_add(mc_red
, (SWFBlock
)sh_red
);
74 SWFMovieClip_nextFrame(mc_red
);//1st frame
76 mc_blu
= newSWFMovieClip();
77 sh_blu
= make_fill_square (0, 300, 60, 60, 0, 0, 255, 0, 0, 255);
78 SWFMovieClip_add(mc_blu
, (SWFBlock
)sh_blu
);
79 SWFMovieClip_nextFrame(mc_blu
);//1st frame
82 * Add mc_red to _root and name it as "mc_red"
83 * Have onClipLoad reference mc_blu (yet to be placed)
85 it_red
= SWFMovie_add(mo
, (SWFBlock
)mc_red
);
86 SWFDisplayItem_addAction(it_red
,
88 "_root.mcRedLoadCalls++;"
89 "_root.typeofMcBluFromMcRedLoad = typeof(_root.mc_blu);"
90 "_root.typeofMcRedFromMcRedLoad = typeof(_root.mc_red);"
92 SWFDisplayItem_setDepth(it_red
, 3);
93 SWFDisplayItem_setName(it_red
, "mc_red");
96 * Add mc_blu to _root and name it as "mc_blu"
97 * Have onClipLoad reference mc_red (placed before)
99 it_blu
= SWFMovie_add(mo
, (SWFBlock
)mc_blu
);
100 SWFDisplayItem_addAction(it_blu
,
101 compileSWFActionCode(
102 "_root.mcBluLoadCalls++;"
103 "_root.typeofMcRedFromMcBluLoad = typeof(_root.mc_red);"
104 "_root.typeofMcBluFromMcBluLoad = typeof(_root.mc_blu);"
105 ), SWFACTION_ONLOAD
);
106 SWFDisplayItem_setDepth(it_blu
, 4);
107 SWFDisplayItem_setName(it_blu
, "mc_blu");
108 SWFDisplayItem_moveTo(it_blu
, 200, 0);
110 SWFMovie_nextFrame(mo
); /* 2nd frame */
112 // onLoad handler for mc_red DO can see mc_blu (not yet placed)
113 check_equals(mo
, "_root.typeofMcBluFromMcRedLoad", "'movieclip'");
115 // onLoad handler for mc_red DO can see itself
116 check_equals(mo
, "_root.typeofMcRedFromMcRedLoad", "'movieclip'");
118 // onLoad handler for mc_blu DO can see mc_red (placed before)
119 check_equals(mo
, "_root.typeofMcRedFromMcBluLoad", "'movieclip'");
121 // onLoad handler for mc_blu DO can see itself
122 check_equals(mo
, "_root.typeofMcBluFromMcBluLoad", "'movieclip'");
124 // onLoad handlers of mc_red and mc_blu called once
125 check_equals(mo
, "_root.mcBluLoadCalls", "1");
126 check_equals(mo
, "_root.mcRedLoadCalls", "1");
128 add_actions(mo
, " _root.totals(); stop(); ");
129 SWFMovie_nextFrame(mo
); /* 3rd frame */
132 puts("Saving " OUTPUT_FILENAME
);
133 SWFMovie_save(mo
, OUTPUT_FILENAME
);