3 Some hardcoded abc scripts.
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2008,2009 Matthias Kramm <kramm@quiss.org>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
26 void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events)
30 TAG*tag=swf->firstTag;
32 if(tag->id == ST_SHOWFRAME)
34 if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2)
39 abc_file_t*file = abc_file_new();
40 abc_method_body_t*c = 0;
42 abc_class_t*cls = abc_class_new2(file, "rfx::MainTimeline", "flash.display::MovieClip");
43 abc_class_protectedNS(cls, "rfx:MainTimeline");
45 TAG*abctag = swf_InsertTagBefore(swf, swf->firstTag, ST_DOABC);
47 tag = swf_InsertTag(abctag, ST_SYMBOLCLASS);
50 swf_SetString(tag, "rfx.MainTimeline");
52 c = abc_class_getstaticconstructor(cls, 0)->body;
54 c->old.local_count = 1;
55 c->old.init_scope_depth = 9;
56 c->old.max_scope_depth = 10;
62 c = abc_class_getconstructor(cls, 0)->body;
64 c->old.local_count = 1;
65 c->old.init_scope_depth = 10;
66 c->old.max_scope_depth = 11;
68 debugfile(c, "constructor.as");
74 __ constructsuper(c,0);
76 __ getlex(c, "[package]flash.system::Security");
77 __ pushstring(c, "*");
78 __ callpropvoid(c, "[package]::allowDomain", 1);
80 if(stop_each_frame || has_buttons) {
83 abc_method_body_t*f = 0; //frame script
84 while(tag && tag->id!=ST_END) {
86 char needs_framescript=0;
88 char functionname[80];
89 sprintf(framename, "[packageinternal]rfx::frame%d", frame);
91 if(!f && (tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2 || stop_each_frame)) {
92 /* make the contructor add a frame script */
93 __ findpropstrict(c,"[package]::addFrameScript");
95 __ getlex(c,framename);
96 __ callpropvoid(c,"[package]::addFrameScript",2);
98 f = abc_class_method(cls, 0, multiname_fromstring(framename))->body;
100 f->old.local_count = 1;
101 f->old.init_scope_depth = 10;
102 f->old.max_scope_depth = 11;
103 __ debugfile(f, "framescript.as");
107 if(stop_each_frame) {
108 __ findpropstrict(f, "[package]::stop");
109 __ callpropvoid(f, "[package]::stop", 0);
113 if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) {
114 U16 id = swf_GetDefineID(tag);
115 sprintf(buttonname, "::button%d", swf_GetDefineID(tag));
116 __ getlex(f,buttonname);
117 __ getlex(f,"flash.events::MouseEvent");
118 __ getproperty(f, "::CLICK");
119 sprintf(functionname, "::clickbutton%d", swf_GetDefineID(tag));
120 __ getlex(f,functionname);
121 __ callpropvoid(f, "::addEventListener" ,2);
123 needs_framescript = 1;
125 abc_method_body_t*h =
126 abc_class_method(cls, 0, multiname_fromstring(functionname))->body;
127 list_append(h->method->parameters, multiname_fromstring("flash.events::MouseEvent"));
129 h->old.max_stack = 6;
130 h->old.local_count = 2;
131 h->old.init_scope_depth = 10;
132 h->old.max_scope_depth = 11;
136 ActionTAG*oldaction = swf_ButtonGetAction(tag);
137 if(oldaction && oldaction->op == ACTION__GOTOFRAME) {
138 int framenr = GET16(oldaction->data);
140 __ findpropstrict(h,"[package]::gotoAndStop");
141 __ pushuint(h,framenr+1);
142 __ callpropvoid(h,"[package]::gotoAndStop", 1);
145 sprintf(framename, "frame%d", framenr);
146 __ getlocal_0(h); //this
147 __ findpropstrict(h, "[package]flash.events::TextEvent");
148 __ pushstring(h, "link");
151 __ pushstring(h, framename);
152 __ constructprop(h,"[package]flash.events::TextEvent", 4);
153 __ callpropvoid(h,"[package]::dispatchEvent", 1);
155 } else if(oldaction && oldaction->op == ACTION__GETURL) {
157 __ findpropstrict(h,"flash.net::navigateToURL");
158 __ findpropstrict(h,"flash.net::URLRequest");
159 // TODO: target _blank
160 __ pushstring(h,oldaction->data); //url
161 __ constructprop(h,"flash.net::URLRequest", 1);
162 __ callpropvoid(h,"flash.net::navigateToURL", 1);
164 __ getlocal_0(h); //this
165 __ findpropstrict(h, "[package]flash.events::TextEvent");
166 __ pushstring(h, "link");
169 __ pushstring(h,oldaction->data); //url
170 __ constructprop(h,"[package]flash.events::TextEvent", 4);
171 __ callpropvoid(h,"[package]::dispatchEvent", 1);
173 } else if(oldaction) {
174 fprintf(stderr, "Warning: Couldn't translate button code of button %d to flash 9 abc action\n", id);
177 swf_ActionFree(oldaction);
179 if(tag->id == ST_SHOWFRAME) {
196 if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) {
198 sprintf(buttonname, "::button%d", swf_GetDefineID(tag));
199 multiname_t*s = multiname_fromstring(buttonname);
200 //abc_class_slot(cls, multiname_fromstring(buttonname), s);
201 abc_class_slot(cls, multiname_fromstring(buttonname),
202 multiname_fromstring("flash.display::SimpleButton"));
208 abc_script_t*s = abc_initscript(file);
210 c->old.max_stack = 2;
211 c->old.local_count = 1;
212 c->old.init_scope_depth = 1;
213 c->old.max_scope_depth = 9;
217 __ getscopeobject(c, 0);
218 __ getlex(c,"::Object");
220 __ getlex(c,"flash.events::EventDispatcher");
222 __ getlex(c,"flash.display::DisplayObject");
224 __ getlex(c,"flash.display::InteractiveObject");
226 __ getlex(c,"flash.display::DisplayObjectContainer");
228 __ getlex(c,"flash.display::Sprite");
230 __ getlex(c,"flash.display::MovieClip");
232 __ getlex(c,"flash.display::MovieClip");
241 __ initproperty(c,"rfx::MainTimeline");
244 //abc_method_body_addClassTrait(c, "rfx:MainTimeline", 1, cls);
245 multiname_t*classname = multiname_fromstring("rfx::MainTimeline");
246 abc_initscript_addClassTrait(s, classname, cls);
247 multiname_destroy(classname);
249 swf_WriteABC(abctag, file);
252 TAG*swf_AddAS3FontDefine(TAG*tag, U16 id, char*fontname)
254 tag = swf_InsertTag(tag, ST_DOABC);
255 abc_file_t*file = abc_file_new();
257 //abc_class_t*cls = abc_class_new2(file, fontname, "flash.display::MovieClip");
258 //abc_class_slot(cls, multiname_fromstring(fontname), multiname_fromstring("flash.text::Font"));
260 abc_class_t*cls = abc_class_new2(file, fontname, "flash.text::Font");
262 abc_script_t*s = abc_initscript(file);
263 code_t*c = s->method->body->code;
264 c = abc_getlocal_0(c);
265 c = abc_pushscope(c);
266 c = abc_getscopeobject(c, 0);
267 c = abc_getlex(c,"flash.text::Font");
268 c = abc_pushscope(c);
269 c = abc_getlex(c,"flash.text::Font");
270 c = abc_newclass(c,cls);
272 c = abc_initproperty(c, fontname);
273 c = abc_returnvoid(c);
274 s->method->body->code = c;
276 abc_initscript_addClassTrait(s, multiname_fromstring(fontname), cls);
277 swf_WriteABC(tag, file);
279 tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
282 swf_SetString(tag, fontname);