void add_text_field(SWFMovie mo, const char* name, const char* varname, const char* initial_label, int depth, int x, int y) { SWFDisplayItem it; SWFTextField tf = newSWFTextField(); SWFTextField_setFont(tf, (void*)font); SWFTextField_addChars(tf, " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345689:.,/\\#@?!"); SWFTextField_setVariableName(tf, varname); SWFTextField_addString(tf, "Idle"); SWFTextField_setBounds(tf, 120, 12); SWFTextField_setFlags(tf, SWFTEXTFIELD_DRAWBOX|SWFTEXTFIELD_NOEDIT); it = SWFMovie_add(mo, (SWFBlock)tf); SWFDisplayItem_moveTo(it, x, y+2); SWFDisplayItem_setDepth(it, depth); SWFDisplayItem_setName(it, name); // "textfield"); // Label tf = newSWFTextField(); SWFTextField_setFont(tf, (void*)font); SWFTextField_addString(tf, initial_label); SWFTextField_setFlags(tf, SWFTEXTFIELD_DRAWBOX|SWFTEXTFIELD_NOEDIT); it = SWFMovie_add(mo, (SWFBlock)tf); SWFDisplayItem_scale(it, 0.3, 0.3); SWFDisplayItem_setDepth(it, depth*10); SWFDisplayItem_moveTo(it, x, y); }
SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height) { SWFShape sh; SWFMovieClip mc; SWFDisplayItem it; sh = make_fill_square (-(width/2), -(height/2), width, height, 255, 0, 0, 255, 0, 0); mc = newSWFMovieClip(); SWFMovieClip_add(mc, (SWFBlock)sh); SWFMovieClip_nextFrame(mc); it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setDepth(it, depth); SWFDisplayItem_moveTo(it, x, y); SWFDisplayItem_setName(it, name); SWFDisplayItem_addAction(it, newSWFAction( "_root.note(this+' onClipConstruct');" " _root.check_equals(typeof(_root), 'movieclip');" " if ( isNaN(_root.depth3Constructed) ) {" " _root.depth3Constructed=1; " " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);" " } else {" " _root.depth3Constructed++;" " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);" " }" ), SWFACTION_CONSTRUCT); return it; }
void add_clip(SWFMovie mo, char* file, char* name, char* url, int x, int y) { FILE *fd; SWFJpegBitmap bm; SWFShape sh; SWFMovieClip mc; SWFDisplayItem it; SWFAction ac; char action[1024]; printf("Adding %s\n", file); fd = fopen(file, "r"); if ( ! fd ) { perror(file); exit(1); } bm = newSWFJpegBitmap(fd); sh = newSWFShapeFromBitmap((SWFBitmap)bm, SWFFILL_CLIPPED_BITMAP); mc = newSWFMovieClip(); SWFMovieClip_add(mc, (SWFBlock)sh); SWFMovieClip_nextFrame(mc); /* showFrame */ it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setName(it, name); SWFDisplayItem_moveTo(it, x, y); /* "Click" handler */ sprintf(action, " \ %s.onPress = function () { \ _root.CoverArtLoader.loadClip('%s', coverart); \ }; \
/* The file doaction-after-placeobject.swf was created from * doaction-before-placeobject.swf by manually swapping the DoAction and * PlaceObject2 tags in the file with a hex editor */ int main (int argc, char **argv) { SWFMovie movie; SWFMovieClip clip; SWFDisplayItem item; if (Ming_init ()) return 1; Ming_useSWFVersion (7); movie = newSWFMovie(); SWFMovie_setRate (movie, 1); SWFMovie_setDimension (movie, 200, 150); clip = newSWFMovieClip (); item = SWFMovie_add (movie, (SWFBlock) clip); SWFDisplayItem_setName (item, "m"); SWFDisplayItem_addAction (item, compileSWFActionCode ("" " trace (\"clipEvent (load)\");" " trace (this);" ""), SWFACTION_ONLOAD); SWFMovie_add (movie, (SWFBlock) compileSWFActionCode ("" "trace (\"Frame 0\");" "")); SWFMovie_save (movie, "doaction-before-placeobject.swf"); return 0; }
static void embed_swf(SWFMovie movie, char* filename) { SWFPrebuiltClip builtclip; SWFDisplayItem it; char *name; SWFInput in; FILE *swf; if (!(swf = fopen (filename, "rb"))) { fprintf (stdout, "%s: %s\n", filename, strerror (errno)); exit(1); } if (!(in = newSWFInput_file(swf))) { fprintf (stdout, "Can't create SWFInput from file\n"); exit(1); } builtclip = newSWFPrebuiltClip_fromInput(in); if ( ! builtclip ) { fprintf (stdout, "Error creating prebuilt clip\n"); exit(1); } it = SWFMovie_add(mo, (SWFBlock)builtclip); name = base_name(filename); SWFDisplayItem_setName(it, name); free(name); }
static void embed_image(SWFMovie movie, char *f) { SWFFill fill; SWFBitmap bm; SWFShape shape; SWFMovieClip clip; SWFDisplayItem it, it2; FILE *raster; SWFInput in; int height, width; char *name; if (!(raster = fopen (f, "rb"))) { fprintf (stdout, "%s: %s\n", f, strerror (errno)); exit(1); } if (!(in = newSWFInput_file(raster))) { fprintf (stdout, "Can't create SWFInput from file\n"); exit(1); } if (!(bm = newSWFBitmap_fromInput (in))) { fprintf (stdout, "Error creating bitmap"); exit(1); } height = SWFBitmap_getHeight(bm); width = SWFBitmap_getWidth(bm); shape = newSWFShape(); SWFShape_movePenTo(shape, 0, 0); fill = SWFShape_addBitmapFill(shape, bm, SWFFILL_CLIPPED_BITMAP); SWFShape_setRightFill(shape, fill); SWFShape_drawLineTo(shape, width, 0); SWFShape_drawLineTo(shape, width, height); SWFShape_drawLineTo(shape, 0, height); SWFShape_drawLineTo(shape, 0, 0); clip = newSWFMovieClip(); it2 = SWFMovieClip_add(clip, (SWFBlock)shape); SWFMovieClip_nextFrame(clip); it = SWFMovie_add(mo, (SWFBlock)clip); name = base_name(f); SWFDisplayItem_setName(it, name); free(name); }
int main (int argc, char **argv) { SWFMovie movie; SWFVideoStream video; SWFDisplayItem item; SWFAction action; if (Ming_init ()) return 1; Ming_useSWFVersion (7); movie = newSWFMovie(); SWFMovie_setRate (movie, 1); SWFMovie_setDimension (movie, 200, 150); video = newSWFVideoStream (); SWFVideoStream_setDimension (video, 200, 150); item = SWFMovie_add (movie, (SWFBlock) video); SWFDisplayItem_setName (item, "video"); action = compileSWFActionCode ("" "trace (\"Test parsing of onMetaData\");" "nc = new NetConnection ();" "nc.connect (null);" "ns = new NetStream (nc);" "ns.onMetaData = function (info)" "{" " trace ('onMetaData');" " var props = [];" " for (var prop in info) {" " props.push (prop);" " }" " props.sort ();" " for (var i = 0; i < props.length; i++) {" " if (typeof (info[props[i]]) == 'object') {" " var keys = [];" " for (var key in info[props[i]]) {" " keys.push (key);" " }" " keys.sort ();" " trace (props[i] + ' = ');" " for (var j = 0; j < keys.length; j++) {" " trace (' ' + keys[j] + ' = ' + typeof (info[props[i]][keys[j]]) + ': ' + info[props[i]][keys[j]]);" " }" " } else {" " trace (props[i] + ' = ' + typeof (info[props[i]]) + ': ' + info[props[i]]);" " }" " }" " loadMovie ('FSCommand:quit', '');" "};" "video.attachVideo (ns);" "ns.setBufferTime (5);" "trace (\"Calling play\");" "ns.play (\"video.flv\");" "trace (\"done calling play\");" ""); SWFMovie_add (movie, (SWFBlock) action); SWFMovie_save (movie, "netstream-onmetadata.swf"); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc, dejagnuclip; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFMovie_nextFrame(mo); /* 1st frame */ mc = newSWFMovieClip(); add_clip_actions(mc, "_root.x = 1;" "_root.check_equals(_root.x, 1);"); SWFMovieClip_nextFrame(mc); add_actions(mo, " gotoAndPlay(4); "); SWFMovie_nextFrame(mo); /* 2nd frame */ SWFMovie_nextFrame(mo); /* 3rd frame */ /* add mc to _root and name it as "mc" */ SWFDisplayItem it; it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setDepth(it, 3); SWFDisplayItem_setName(it, "mc"); add_actions(mo, " _root.x = 2; " " _root.check_equals(_root.x, 2); "); SWFMovie_nextFrame(mo); /* 4th frame */ SWFDisplayItem_remove(it); check_equals(mo, "_root.x", "1"); check_equals(mo, "typeof(mc)", "'undefined'"); add_actions(mo, " _root.totals(); stop(); "); SWFMovie_nextFrame(mo); /* 5th frame */ //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
void add_xtrace_function_clip(SWFMovieClip mc, SWFBlock font, int depth, int x, int y, int width, int height) { SWFTextField tf; SWFDisplayItem it; int flags; tf = newSWFTextField(); SWFTextField_setFont(tf, font); /* setting flags seem unneeded */ flags = 0; //flags |= SWFTEXTFIELD_USEFONT; flags |= SWFTEXTFIELD_WORDWRAP; //flags |= SWFTEXTFIELD_NOEDIT; SWFTextField_setFlags(tf, flags); /* Add all ascii chars */ SWFTextField_addChars(tf, asciichars); SWFTextField_addString(tf, " - xtrace enabled -\n"); SWFTextField_setBounds(tf, width, height); /* * Hopefully we have a *single* _root. */ SWFTextField_setVariableName(tf, "_root._trace_text"); /* * Set flags explicitly so that the field is selectable * and you can cut&paste results. * (the default seems to include SWFTEXTFIELD_NOSELECT) */ SWFTextField_setFlags(tf, SWFTEXTFIELD_NOEDIT); /*SWFTextField_setHeight(tf, 240);*/ /*SWFTextField_setColor(tf, 0x00, 0x00, 0x00, 0xff);*/ /*SWFTextField_setAlignment(tf, SWFTEXTFIELD_ALIGN_LEFT);*/ /*SWFTextField_setLeftMargin(tf, 0);*/ /*SWFTextField_setRightMargin(tf, 0);*/ /*SWFTextField_setIndentation(tf, 0);*/ /*SWFTextField_setLineSpacing(tf, 40);*/ /*SWFTextField_setLineSpacing(tf, 40);*/ it = SWFMovieClip_add(mc, (SWFBlock)tf); SWFDisplayItem_moveTo(it, x, y); SWFDisplayItem_setDepth(it, depth); SWFDisplayItem_setName(it, "_xtrace_win"); add_clip_actions(mc, " _root.xtrace = function (msg) { " " _root._trace_text += msg + '\n'; " "};"); }
static void modify_placement (SWFMovie movie, guint mod) { SWFDisplayItem item; SWFBlock clip, clip2; clip = (SWFBlock) newSWFMovieClip (); add_rectangle ((SWFMovieClip) clip, 255, 0, 0); SWFMovieClip_nextFrame ((SWFMovieClip) clip); clip2 = (SWFBlock) newSWFMovieClip (); add_rectangle ((SWFMovieClip) clip2, 0, 0, 255); SWFMovieClip_nextFrame ((SWFMovieClip) clip2); item = SWFMovie_add (movie, clip); SWFDisplayItem_setDepth (item, 1); SWFDisplayItem_setName (item, "a"); SWFMovie_nextFrame (movie); item = SWFMovie_add (movie, clip2); SWFDisplayItem_setDepth (item, 1); SWFDisplayItem_moveTo (item, 20, 20); SWFDisplayItem_setName (item, "b"); }
SWFDisplayItem add_button(SWFMovie mo) { SWFDisplayItem it; SWFMovieClip mc, mc1; SWFButtonRecord br; SWFShape sh1, sh2, sh3, sh4, sh1a, sh2a, sh3a, sh4a; SWFButton bu = newSWFButton(); mc = newSWFMovieClip(); sh1 = make_fill_square(0, 0, 40, 40, 0, 0, 0, 0, 0, 0); sh1a = make_fill_square(30, 30, 5, 5, 128, 128, 128, 128, 128, 128); sh2 = make_fill_square(0, 0, 40, 40, 255, 0, 0, 255, 0, 0); sh2a = make_fill_square(30, 30, 5, 5, 128, 0, 0, 128, 0, 0); sh3 = make_fill_square(0, 0, 40, 40, 0, 255, 0, 0, 255, 0); sh3a = make_fill_square(30, 30, 5, 5, 0, 128, 0, 0, 128, 0); sh4 = make_fill_square(0, 0, 40, 40, 255, 255, 0, 255, 255, 0); sh4a = make_fill_square(30, 30, 5, 5, 128, 128, 0, 128, 128, 0); /* Higher depth DisplayObject is intentionally added before lower depth one */ br = SWFButton_addCharacter(bu, (SWFCharacter)sh1a, SWFBUTTON_HIT); SWFButtonRecord_setDepth(br, 2); br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT); SWFButtonRecord_setDepth(br, 1); /* Higher depth DisplayObject is intentionally added before lower depth one */ br = SWFButton_addCharacter(bu, (SWFCharacter)sh2a, SWFBUTTON_UP ); SWFButtonRecord_setDepth(br, 2); br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_UP ); SWFButtonRecord_setDepth(br, 1); mc1 = newSWFMovieClip(); br = SWFButton_addCharacter(bu, (SWFCharacter)mc1, SWFBUTTON_UP); SWFButtonRecord_setDepth(br, 8); br = SWFButton_addCharacter(bu, (SWFCharacter)mc1, SWFBUTTON_DOWN); SWFButtonRecord_setDepth(br, 7); br = SWFButton_addCharacter(bu, (SWFCharacter)mc1, SWFBUTTON_HIT); SWFButtonRecord_setDepth(br, 9); it = SWFMovieClip_add(mc, (SWFBlock)bu); SWFDisplayItem_setName(it, "button"); SWFMovieClip_nextFrame(mc); /* showFrame */ it = SWFMovie_add(mo, (SWFBlock)mc); return it; }
SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height) { SWFMovieClip mc; SWFDisplayItem it; mc = get_static_mc(width, height, 255, 0, 0); it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setDepth(it, depth); SWFDisplayItem_moveTo(it, x, y); SWFDisplayItem_setName(it, name); return it; }
static int add_imports() { int i; SWFMovieClip mc; SWFDisplayItem di; SWFAction ac; struct stat statbuf; mc = newSWFMovieClip(); for (i=0; i<numimport_specs; i++) { char *spec = import_specs[i]; char *file = strtok(spec, ":"); char *sym; char unchecked = 0; if ( -1 == stat(file, &statbuf) ) { unchecked = 1; } printf("Importing symbols from "); if ( unchecked ) printf("[UNAVAILABLE] "); printf("%s:", file); fflush(stdout); while ((sym=strtok(NULL, ","))) { SWFCharacter ch; printf(" %s", sym); fflush(stdout); ch = SWFMovie_importCharacter(mo, file, sym); SWFMovieClip_add(mc, (SWFBlock)ch); } printf("\n"); } SWFMovieClip_nextFrame(mc); di = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setName(di, "__shared_assets"); ac = newSWFAction("__shared_assets._visible=false;"); SWFMovie_add(mo, (SWFBlock)ac); return 1; }
SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth) { SWFShape sh; SWFMovieClip mc; SWFDisplayItem it; mc = newSWFMovieClip(); sh = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc, (SWFBlock)sh); SWFMovieClip_nextFrame(mc); it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setDepth(it, depth); SWFDisplayItem_setName(it, name); return it; }
void add_xtrace_function(SWFMovie mo, SWFBlock font, int depth, int x, int y, int width, int height) { SWFTextField tf; SWFDisplayItem it; tf = newSWFTextField(); SWFTextField_setFont(tf, font); /* setting flags seem unneeded */ /*SWFTextField_setFlags(tf, SWFTEXTFIELD_USEFONT|SWFTEXTFIELD_NOEDIT);*/ /* Add all ascii chars */ SWFTextField_addChars(tf, asciichars); SWFTextField_addString(tf, " - xtrace enabled -\n"); SWFTextField_setBounds(tf, width, height); /* * Hopefully we have a *single* _root. */ SWFTextField_setVariableName(tf, "_root._trace_text"); /*SWFTextField_setHeight(tf, 240);*/ /*SWFTextField_setColor(tf, 0x00, 0x00, 0x00, 0xff);*/ /*SWFTextField_setAlignment(tf, SWFTEXTFIELD_ALIGN_LEFT);*/ /*SWFTextField_setLeftMargin(tf, 0);*/ /*SWFTextField_setRightMargin(tf, 0);*/ /*SWFTextField_setIndentation(tf, 0);*/ /*SWFTextField_setLineSpacing(tf, 40);*/ /*SWFTextField_setLineSpacing(tf, 40);*/ it = SWFMovie_add(mo, (SWFBlock)tf); SWFDisplayItem_moveTo(it, x, y); SWFDisplayItem_setDepth(it, depth); SWFDisplayItem_setName(it, "_xtrace_win"); add_actions(mo, " _root.xtrace = function (msg) { " " trace (msg); " " _root._trace_text += msg + '\n'; " "};"); }
SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height) { SWFShape sh; SWFMovieClip mc; SWFDisplayItem it; sh = make_fill_square (-(width/2), -(height/2), width, height, 255, 0, 0, 255, 0, 0); mc = newSWFMovieClip(); SWFMovieClip_add(mc, (SWFBlock)sh); SWFMovieClip_nextFrame(mc); it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setDepth(it, depth); SWFDisplayItem_moveTo(it, x, y); SWFDisplayItem_setName(it, name); return it; }
void add_window(SWFMovie mo, int x, int y) { SWFShape sh_window; SWFFillStyle fstyle; SWFMovieClip mc_window; SWFDisplayItem it; sh_window = newSWFShape(); fstyle = SWFShape_addSolidFillStyle(sh_window, 0,0,0,255); SWFShape_setRightFillStyle(sh_window, fstyle); SWFShape_movePenTo(sh_window, 170, 170); SWFShape_drawLine(sh_window, -170, 0); SWFShape_drawLine(sh_window, 0, -170); SWFShape_drawLine(sh_window, 170, 0); SWFShape_drawLine(sh_window, 0, 170); mc_window = newSWFMovieClip(); SWFMovieClip_add(mc_window, (SWFBlock)sh_window); SWFMovieClip_add(mc_window, (SWFBlock)newSWFAction( "_root.xcheck(getBytesLoaded() < _root.getBytesLoaded());" "_root.xcheck(getBytesTotal() < _root.getBytesTotal());" )); SWFMovieClip_nextFrame(mc_window); /* showFrame */ it = SWFMovie_add(mo, (SWFBlock)mc_window); SWFDisplayItem_setName(it, "window"); SWFDisplayItem_moveTo(it, x, y); SWFDisplayItem_addAction(it, compileSWFActionCode( "_root.note('Click on \"Load PNG\" to load a PNG movie here.');" ), SWFACTION_ROLLOVER); SWFDisplayItem_addAction(it, compileSWFActionCode( "delete _level0.window.onMouseDown;" ), SWFACTION_ROLLOUT); }
int main(int argc, char ** argv) { SWFMovie mo; SWFDisplayItem it1, it2, it3; SWFShape sh1, sh2, sh3; int framenum; argc=argc; argv=argv; /* unused... */ /********************************************* * * Initialization * *********************************************/ puts("Setting things up"); Ming_init(); Ming_useSWFVersion (OUTPUT_VERSION); Ming_setScale(20.0); mo = newSWFMovie(); /***************************************************** * * Add the square named * *****************************************************/ SWFMovie_setDimension(mo, 100, 100); #define FRAMESGAP 5 sh1 = make_square(10, 10, 20, 20, 255, 0, 0); it1 = SWFMovie_add(mo, (SWFBlock)sh1); SWFDisplayItem_setDepth(it1, 1); SWFDisplayItem_setName(it1, "Name1"); for (framenum=0; framenum<FRAMESGAP; framenum++) { SWFMovie_nextFrame(mo); } sh2 = make_square(35, 10, 20, 20, 0, 255, 0); it2 = SWFMovie_add(mo, (SWFBlock)sh2); SWFDisplayItem_setDepth(it2, 2); SWFDisplayItem_setName(it2, "Name2"); for (framenum=0; framenum<FRAMESGAP; framenum++) { SWFMovie_nextFrame(mo); } sh3 = make_square(10, 35, 45, 20, 0, 0, 255); it3 = SWFMovie_add(mo, (SWFBlock)sh3); SWFDisplayItem_setDepth(it3, 3); SWFDisplayItem_setName(it3, "Name3"); for (framenum=0; framenum<FRAMESGAP; framenum++) { SWFMovie_nextFrame(mo); } SWFMovie_remove(mo, it1); for (framenum=0; framenum<FRAMESGAP; framenum++) { SWFMovie_nextFrame(mo); } SWFMovie_remove(mo, it2); for (framenum=0; framenum<FRAMESGAP; framenum++) { SWFMovie_nextFrame(mo); } SWFMovie_remove(mo, it3); puts("Saving " OUTPUT_FILENAME ); SWFMovie_nextFrame(mo); /* showFrame */ SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char* argv[]) { SWFMovie mo; SWFMovieClip mc1, mc2, mc3, mc4, dejagnuclip; SWFDisplayItem it; SWFAction ac; SWFInitAction initac; const char *srcdir="."; if (argc > 1) srcdir = argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); add_actions(mo, "if (!_global.hasOwnProperty('arr')) { _global.arr = []; };" "_global.ch = function(a, b) {" " trace(a);" " if (typeof(b)=='undefined' || (typeof(b)=='boolean' && b)) {" " _global.arr.push(a);" " };" "};" "this.onEnterFrame = function() { " " _global.ch('onEnterFrame', false);" "};" ); SWFMovie_nextFrame(mo); // MovieClip 1 mc1 = newSWFMovieClip(); // 1 frames // SWF_EXPORTASSETS SWFMovie_addExport(mo, (SWFBlock)mc1, "Segments_Name"); SWFMovie_writeExports(mo); // MovieClip mc3 has two frames. In each frame a different MovieClip // is placed with the name Segments. mc3 = newSWFMovieClip(); // 2 frames // MovieClip 2 mc2 = newSWFMovieClip(); // 1 frames // Add mc2 it = SWFMovieClip_add(mc3, (SWFBlock)mc2); SWFDisplayItem_setDepth(it, 1); SWFDisplayItem_setName(it, "Segments"); // Frame 2 SWFMovieClip_nextFrame(mc3); // Remove mc2 SWFDisplayItem_remove(it); // Add mc1 it = SWFMovieClip_add(mc3, (SWFBlock)mc1); SWFDisplayItem_setDepth(it, 1); SWFDisplayItem_setName(it, "Segments"); SWFMovieClip_nextFrame(mc3); // End mc3 // This is frame 1 of the main timeline // Put our sprite mc3 on stage. it = SWFMovie_add(mo, (SWFBlock)mc3); SWFDisplayItem_setDepth(it, 1); SWFDisplayItem_setName(it, "mc"); // mc4 is just for executing init actions. mc4 = newSWFMovieClip(); SWFMovie_addExport(mo, (SWFBlock)mc4, "__Packages.Bug"); SWFMovie_writeExports(mo); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); ac = newSWFAction( "_global.loops = 0;" "_global.c = 0;" "if( !_global.Bug ) {" " _global.Bug = function () {" " this.onUnload = function() { " " _global.ch('dynamic unload: ' + this.c);" " }; " " this.onLoad = function() { " " _global.ch('dynamic load: ' + this.c);" " }; " " this.c = _global.c;" " _global.ch('ctor: ' + _global.c);" " _global.c++;" " };" "};" ); initac = newSWFInitAction_withId(ac, 4); SWFMovie_add(mo, (SWFBlock)initac); ac = newSWFAction("Object.registerClass('Segments_Name',Bug);"); initac = newSWFInitAction_withId(ac, 1); SWFMovie_add(mo, (SWFBlock)initac); add_actions(mo, "_global.ch('Frame ' + " "_level0._currentframe + ' actions: ' " "+ _level0.mc.Segments.c);"); // Frame 2 of the main timeline SWFMovie_nextFrame(mo); add_actions(mo, "_global.ch('Frame ' + " "_level0._currentframe + ' actions: ' " "+ _level0.mc.Segments.c);"); add_actions(mo, " if (_global.loops < 5) {" " _global.loops++;" " gotoAndPlay(2);" " }" " else {" " delete this.onEnterFrame;" " gotoAndPlay(4);" " };" ); SWFMovie_nextFrame(mo); check_equals(mo, "_global.arr.length", "20"); check_equals(mo, "_global.arr[0]", "'Frame 2 actions: undefined'"); check_equals(mo, "_global.arr[1]", "'ctor: 0'"); xcheck_equals(mo, "_global.arr[2]", "'Frame 3 actions: 0'"); xcheck_equals(mo, "_global.arr[3]", "'dynamic load: 0'"); check_equals(mo, "_global.arr[4]", "'Frame 2 actions: 0'"); check_equals(mo, "_global.arr[5]", "'Frame 3 actions: 0'"); check_equals(mo, "_global.arr[6]", "'Frame 2 actions: 0'"); check_equals(mo, "_global.arr[7]", "'ctor: 1'"); check_equals(mo, "_global.arr[8]", "'dynamic unload: 0'"); xcheck_equals(mo, "_global.arr[9]", "'Frame 3 actions: 0'"); check_equals(mo, "_global.arr[11]", "'Frame 2 actions: 0'"); check_equals(mo, "_global.arr[12]", "'Frame 3 actions: 1'"); check_equals(mo, "_global.arr[13]", "'Frame 2 actions: 1'"); check_equals(mo, "_global.arr[14]", "'ctor: 2'"); check_equals(mo, "_global.arr[15]", "'dynamic unload: 1'"); xcheck_equals(mo, "_global.arr[16]", "'Frame 3 actions: 1'"); xcheck_equals(mo, "_global.arr[17]", "'dynamic load: 2'"); check_equals(mo, "_global.arr[18]", "'Frame 2 actions: 1'"); check_equals(mo, "_global.arr[19]", "'Frame 3 actions: 2'"); xcheck_equals(mo, "_global.arr.toString()", "'Frame 2 actions: undefined,ctor: 0,Frame 3 actions: 0,dynamic load: 0,Frame 2 actions: 0,Frame 3 actions: 0,Frame 2 actions: 0,ctor: 1,dynamic unload: 0,Frame 3 actions: 0,dynamic load: 1,Frame 2 actions: 0,Frame 3 actions: 1,Frame 2 actions: 1,ctor: 2,dynamic unload: 1,Frame 3 actions: 1,dynamic load: 2,Frame 2 actions: 1,Frame 3 actions: 2'"); SWFMovie_nextFrame(mo); add_actions(mo, "totals(21); stop();"); SWFMovie_nextFrame(mo); // SWF_END SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc1, mc2, dejagnuclip; SWFDisplayItem it; SWFShape sh1,sh2; SWFAction ac1, ac2; int i; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); //return 1; } Ming_init(); mo = newSWFMovie(); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 1.0); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFMovie_nextFrame(mo); sh1 = make_fill_square (0, 220, 60, 60, 255, 0, 0, 255, 0, 0); sh2 = make_fill_square (30, 250, 60, 60, 255, 0, 0, 0, 0, 0); it = SWFMovie_add(mo, (SWFBlock)sh1); SWFDisplayItem_setName(it, "sh1"); SWFDisplayItem_setDepth(it, 3); //place the sh1 DisplayObject at depth 3 it = SWFMovie_add(mo, (SWFBlock)sh2); SWFDisplayItem_setName(it, "sh2"); SWFDisplayItem_setDepth(it, 3); //place the sh2 DisplayObject at depth 3 again! add_actions(mo, "note('Placed red shape sh1 and black shape sh2 at the same depth 3. Should both be visible, red on top.');"); xcheck_equals(mo, "sh1", "sh2"); check_equals(mo, "typeof(sh1)", "'movieclip'"); xcheck_equals(mo, "typeof(sh2)", "'movieclip'"); SWFMovie_nextFrame(mo); mc1 = newSWFMovieClip(); it = SWFMovieClip_add(mc1, (SWFBlock)sh1); SWFDisplayItem_setName(it, "sh1"); SWFDisplayItem_moveTo(it, 100, 0); SWFMovieClip_nextFrame(mc1); mc2 = newSWFMovieClip(); it = SWFMovieClip_add(mc2, (SWFBlock)sh2); SWFDisplayItem_setName(it, "sh1"); SWFDisplayItem_moveTo(it, 100, 0); SWFMovieClip_nextFrame(mc2); it = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setName(it, "mc2"); SWFDisplayItem_setDepth(it, 4); //place the mc2 sprite at depth 3 again! it = SWFMovie_add(mo, (SWFBlock)mc1); SWFDisplayItem_setName(it, "mc1"); SWFDisplayItem_setDepth(it, 4); //place the mc1 sprite at depth 3 add_actions(mo, "note('Placed red sprite mc1 and black sprite mc2 at the same depth 4. Should both be visible, black on top.');"); xcheck_equals(mo, "typeof(mc1)", "'movieclip'"); check_equals(mo, "typeof(mc2)", "'movieclip'"); check(mo, "mc1._name != mc2._name"); check_equals(mo, "mc1.getDepth()", "mc2.getDepth()"); // TODO: use SWFMovie_replace and see if it would replace // only one or both DisplayObjects at target depth // (not that we can trust Ming stability here..) add_actions(mo, "_root.totals(7); stop();"); SWFMovie_nextFrame(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc1, mc2, dejagnuclip; SWFDisplayItem it1, it2; SWFShape sh1,sh2; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); //return 1; } Ming_init(); Ming_useSWFVersion (OUTPUT_VERSION); mo = newSWFMovie(); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate(mo, 6); // Frame 1: Place dejagnu clip dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); add_actions(mo, "mc1Constructed=0; mc2Constructed=0; mc3Constructed=0; mc4Constructed=0;"); SWFMovie_nextFrame(mo); // // Frame 2: // Place red static movieClip1 DisplayObject at depth 3 (-16381) // Place black static movieClip1 DisplayObject at depth 4 (-16380) // sh1 = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0); mc1 = newSWFMovieClip(); SWFMovieClip_add(mc1, (SWFBlock)sh1); SWFMovieClip_nextFrame(mc1); it1 = SWFMovie_add(mo, (SWFBlock)mc1); //add movieClip1 to the _root SWFDisplayItem_setDepth(it1, 3); SWFDisplayItem_setName(it1, "movieClip1"); //name movieClip1 SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' constructed');" "_root.mc1Constructed++;" ), SWFACTION_CONSTRUCT); sh2 = make_fill_square (330, 270, 120, 120, 0, 0, 0, 0, 0, 0); mc2 = newSWFMovieClip(); SWFMovieClip_add(mc2, (SWFBlock)sh2); SWFMovieClip_nextFrame(mc2); it2 = SWFMovie_add(mo, (SWFBlock)mc2); //add movieClip2 to the _root SWFDisplayItem_setDepth(it2, 4); SWFDisplayItem_setName(it2, "movieClip2"); //name movieClip2 SWFDisplayItem_addAction(it2, newSWFAction( "_root.note(this+' constructed');" "_root.mc2Constructed++;"), SWFACTION_CONSTRUCT); SWFMovie_nextFrame(mo); // Frame3: nothing new SWFMovie_nextFrame(mo); // Frame4: remove "movieClip1" and "movieClip2" SWFDisplayItem_remove(it1); SWFDisplayItem_remove(it2); SWFMovie_nextFrame(mo); // // Frame5: // Place red static movieClip3 DisplayObject at depth 3 (-16381) with ratio set to 2.0 // Place black static movieClip4 DisplayObject at depth4 (-16380) with ratio set to 0.0 // it1 = SWFMovie_add(mo, (SWFBlock)mc1); //add movieClip3 to the _root SWFDisplayItem_setDepth(it1, 3); SWFDisplayItem_setName(it1, "movieClip3"); //name movieClip3 SWFDisplayItem_setRatio(it1, 2.0); // It's important to set this, don't why yet. SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' constructed');" "_root.mc3Constructed++;" ), SWFACTION_CONSTRUCT); it2 = SWFMovie_add(mo, (SWFBlock)mc2); //add movieClip4 to the _root SWFDisplayItem_setDepth(it2, 4); SWFDisplayItem_setName(it2, "movieClip4"); //name movieClip4 SWFDisplayItem_setRatio(it2, 0.0); // It's important to set this, don't why yet. SWFDisplayItem_addAction(it2, newSWFAction( "_root.note(this+' constructed');" "_root.mc4Constructed++;" ), SWFACTION_CONSTRUCT); SWFMovie_nextFrame(mo); // // Frame4: check, gotoAndStop(3), check.. // check_equals(mo, "typeof(movieClip1)", "'undefined'"); check_equals(mo, "typeof(movieClip2)", "'undefined'"); check_equals(mo, "typeof(movieClip3)", "'movieclip'"); check_equals(mo, "typeof(movieClip4)", "'movieclip'"); check_equals(mo, "_root.mc1Constructed", "1"); check_equals(mo, "_root.mc2Constructed", "1"); check_equals(mo, "_root.mc3Constructed", "1"); check_equals(mo, "_root.mc4Constructed", "1"); SWFMovie_add(mo, (SWFBlock)newSWFAction( "gotoAndStop(3);")); check_equals(mo, "typeof(movieClip1)", "'movieclip'"); check_equals(mo, "typeof(movieClip2)", "'undefined'"); // the difference of movieClip3 and movieClip4 was caused by the ratio value check_equals(mo, "typeof(movieClip3)", "'undefined'"); check_equals(mo, "typeof(movieClip4)", "'movieclip'"); check_equals(mo, "_root.mc1Constructed", "2"); check_equals(mo, "_root.mc2Constructed", "1"); check_equals(mo, "_root.mc3Constructed", "1"); check_equals(mo, "_root.mc4Constructed", "1"); SWFMovie_add(mo, (SWFBlock)newSWFAction( "totals(); stop();" )); SWFMovie_nextFrame(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc1, mc2, dejagnuclip; SWFDisplayItem it1, it2; SWFShape sh_red; /* For the button duplication test */ #if MING_VERSION_CODE >= 00040400 SWFButton but; SWFButtonRecord br; #endif const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); add_actions(mo, "x1=0; x2=0; x3=0;"); SWFMovie_nextFrame(mo); /* 1st frame */ mc1 = newSWFMovieClip(); sh_red = make_fill_square (100, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc1, (SWFBlock)sh_red); add_clip_actions(mc1, "stop();"); SWFMovieClip_nextFrame(mc1); mc2 = newSWFMovieClip(); sh_red = make_fill_square (100, 200, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc2, (SWFBlock)sh_red); add_clip_actions(mc2, "stop();"); SWFMovieClip_nextFrame(mc2); it1 = SWFMovie_add(mo, (SWFBlock)mc1); SWFDisplayItem_setDepth(it1, 10); SWFDisplayItem_setName(it1, "mc1"); it2 = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setDepth(it2, 20); SWFDisplayItem_setName(it2, "mc2"); SWFDisplayItem_addAction(it2, compileSWFActionCode(" _root.note('onClipLoad triggered'); " " _root.x1 = _root.x1 + 1; "), SWFACTION_ONLOAD); SWFDisplayItem_addAction(it2, compileSWFActionCode(" _root.note('onClipEnterFrame triggered'); " " _root.x2 = _root.x2 + 1; "), SWFACTION_ENTERFRAME); SWFDisplayItem_addAction(it2, compileSWFActionCode(" _root.note('onClipUnload triggered'); " " _root.x3 = _root.x3 + 1; "), SWFACTION_UNLOAD); add_actions(mo, " mc1.onLoad = function () {}; " " mc1.prop1 = 10; " " duplicateMovieClip('mc1', 'dup1', 1); " " mc2.onLoad = function () {}; " " duplicateMovieClip('mc2', 'dup2', 2); " ); SWFMovie_nextFrame(mo); /* 2nd frame */ check_equals(mo, "mc1.prop1", "10"); check_equals(mo, "typeof(mc1.onLoad)", "'function'"); check_equals(mo, "mc1.getDepth()", "-16374"); /* user defined property will not be duplicated */ check_equals(mo, "dup1.prop1", "undefined"); /* user defined event handler will not be duplicated */ check_equals(mo, "typeof(dup1.onLoad)", "'undefined'"); check_equals(mo, "dup1.getDepth()", "1"); /* check user defined onLoad */ check_equals(mo, "typeof(mc2.onLoad)", "'function'"); /* onClipEvent does not define a function */ check_equals(mo, "typeof(mc2.onEnterFrame)", "'undefined'"); /* user defined event handler will not be duplicated */ check_equals(mo, "typeof(dup2.onLoad)", "'undefined'"); check_equals(mo, "_root.x1", "2"); check_equals(mo, "_root.x2", "2"); SWFMovie_nextFrame(mo); /* 3rd frame */ SWFDisplayItem_remove(it1); SWFDisplayItem_remove(it2); add_actions(mo, " dup2.removeMovieClip(); "); SWFMovie_nextFrame(mo); /* 4th frame */ #if MING_VERSION_CODE >= 00040400 /* Create a button, add it to mc1 */ but = newSWFButton(); br = SWFButton_addCharacter(but, (SWFCharacter)sh_red, SWFBUTTON_UP); SWFButtonRecord_setDepth(br, 10); it1 = SWFMovie_add(mo, (SWFBlock)but); SWFDisplayItem_setName(it1, "button"); /* Sanity check */ check_equals(mo, "typeof(button)", "'object'"); add_actions(mo, "trace(button);" "dupl = MovieClip.prototype.duplicateMovieClip;" "button.dupl = dupl;" "o = { x: 4 };" "d = button.dupl('buttdup', 201, o);" ); xcheck_equals(mo, "typeof(d)", "'object'"); xcheck_equals(mo, "'' + _root.buttdup", "'_level0.buttdup'"); check_equals(mo, "_root.buttdup", "d"); /* initobj not used */ check_equals(mo, "_root.buttdup.x", "undefined"); #endif add_actions(mo, "t = new Object();" "t.dupl = dupl;" "o2 = { x: 44 };" "d2 = t.dupl('objdup', 202, o2);" "trace(_root.objdup);" ); /* Does not work on plain objects */ check_equals(mo, "typeof(d2)", "'undefined'"); check_equals(mo, "typeof(_root.objdup)", "'undefined'"); SWFMovie_nextFrame(mo); /* 5th frame */ check_equals(mo, "_root.x1", "2"); check_equals(mo, "_root.x2", "3"); check_equals(mo, "_root.x3", "2"); add_actions(mo, " _root.totals(); stop(); "); SWFMovie_nextFrame(mo); /* 5th frame */ //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc1, mc2, mc3, mc4, mc5, dejagnuclip; SWFDisplayItem it1, it2, it3, it4, it5; SWFShape sh_red; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); add_actions(mo, " x2 += 'as_start+'; " " _root.OnLoad = function () { _root.note('_root onLoad called'); x2 += 'load_called+'; }; " " x2 += 'as_end+'; " " _root.onEnterFrame = function () { x3 += 'enterFrame_called+'; }; "); SWFMovie_nextFrame(mo); /* 1st frame */ mc1 = newSWFMovieClip(); sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc1, (SWFBlock)sh_red); add_clip_actions(mc1, " _root.note('actions in 1st frame of mc1'); " // Defining onLoad in first frame of a sprite doesn't work, but works for root " this.onLoad = function() { _root.note('mc1 onLoad called'); _root.x1 += 'YY'; };" " _root.x1 += '2+'; "); SWFMovieClip_nextFrame(mc1); /* mc1, 1st frame */ add_clip_actions(mc1, " _root.note('actions in 2nd frame of mc1'); " " _root.x1 += '12+'; " " stop(); "); SWFMovieClip_nextFrame(mc1); /* mc1, 2nd frame */ mc2 = newSWFMovieClip(); sh_red = make_fill_square (80, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc2, (SWFBlock)sh_red); add_clip_actions(mc2, " _root.note('actions in 1st frame of mc2'); " // Defining onLoad in first frame of a sprite doesn't work, but works for root " this.onLoad = function() { _root.note('mc2 onLoad called'); _root.x1 += 'XX'; };" " _root.x1 += '4+'; "); SWFMovieClip_nextFrame(mc2); /* mc2, 1st frame */ add_clip_actions(mc2, " _root.note('actions in 2nd frame of mc2'); " " _root.x1 += '10+'; " " stop(); "); SWFMovieClip_nextFrame(mc2); /* mc2, 2nd frame */ mc3 = newSWFMovieClip(); sh_red = make_fill_square (160, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc3, (SWFBlock)sh_red); add_clip_actions(mc3, " _root.note('actions in 1st frame of mc3'); " // Defining onLoad in first frame of a sprite doesn't work, but works for root " this.onLoad = function() { _root.note('mc3 onLoad called'); _root.x1 += 'ZZ'; };" " _root.x1 += '6+';"); SWFMovieClip_nextFrame(mc3); /* mc3, 1st frame */ add_clip_actions(mc3, " _root.note('actions in 2nd frame of mc3'); " " _root.x1 += '8+'; " " stop(); "); SWFMovieClip_nextFrame(mc3); /* mc3, 2nd frame */ /* add mc1 to _root and name it as "mc1" */ it1 = SWFMovie_add(mo, (SWFBlock)mc1); SWFDisplayItem_setDepth(it1, 10); SWFDisplayItem_setName(it1, "mc1"); /* Define Construct ClipEvent */ SWFDisplayItem_addAction(it1, compileSWFActionCode(" _root.note('mc1 Construct called');" " _root.x0 += '01+'; "), SWFACTION_CONSTRUCT); /* Define Load ClipEvent */ SWFDisplayItem_addAction(it1, compileSWFActionCode(" _root.note('mc1 Load called');" " _root.x1 += '1+'; "), SWFACTION_ONLOAD); /* Define Unload ClipEvent */ SWFDisplayItem_addAction(it1, compileSWFActionCode(" _root.note('mc1 Unload called'); " " _root.x1 += '13+'; "), SWFACTION_UNLOAD); /* Define EnterFrame ClipEvent */ SWFDisplayItem_addAction(it1, compileSWFActionCode(" _root.note('mc1 EnterFrame called'); " " _root.x1 += '11+'; "), SWFACTION_ENTERFRAME); /* add mc2 to _root and name it as "mc2" */ it2 = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setDepth(it2, 12); SWFDisplayItem_setName(it2, "mc2"); /* Define Construct ClipEvent */ SWFDisplayItem_addAction(it2, compileSWFActionCode(" _root.note('mc2 Construct called');" " _root.x0 += '02+'; "), SWFACTION_CONSTRUCT); /* Define Load ClipEvent */ SWFDisplayItem_addAction(it2, compileSWFActionCode(" _root.note('mc2 Load called'); " " _root.x1 += '3+'; "), SWFACTION_ONLOAD); /* Define Unload ClipEvent */ SWFDisplayItem_addAction(it2, compileSWFActionCode(" _root.note('mc2 Unload called'); " " _root.x1 += '14+'; "), SWFACTION_UNLOAD); /* Define EnterFrame ClipEvent */ SWFDisplayItem_addAction(it2, compileSWFActionCode(" _root.note('mc2 EnterFrame called'); " " _root.x1 += '9+'; "), SWFACTION_ENTERFRAME); /* add mc3 to _root and name it as "mc3" */ it3 = SWFMovie_add(mo, (SWFBlock)mc3); SWFDisplayItem_setDepth(it3, 11); SWFDisplayItem_setName(it3, "mc3"); /* Define Construct ClipEvent */ SWFDisplayItem_addAction(it3, compileSWFActionCode(" _root.note('mc3 Construct called');" " _root.x0 += '03+'; "), SWFACTION_CONSTRUCT); /* Define Load ClipEvent */ SWFDisplayItem_addAction(it3, compileSWFActionCode(" _root.note('mc3 Load called'); " " _root.x1 += '5+'; "), SWFACTION_ONLOAD); /* Define Unload ClipEvent */ SWFDisplayItem_addAction(it3, compileSWFActionCode(" _root.note('mc3 Unload called'); " " _root.x1 += '15+';" ), SWFACTION_UNLOAD); /* Define EnterFrame ClipEvent */ SWFDisplayItem_addAction(it3, compileSWFActionCode(" _root.note('mc3 EnterFrame called'); " " _root.x1 += '7+'; "), SWFACTION_ENTERFRAME); add_actions(mo, " _root.x3 += '_root_frm2_as+'; "); SWFMovie_nextFrame(mo); /* 2nd frame */ add_actions(mo, " _root.x3 += '_root_frm3_as+'; "); check_equals(mo, "_root.x3", "'enterFrame_called+_root_frm2_as+enterFrame_called+_root_frm3_as+'"); SWFMovie_nextFrame(mo); /* 3rd frame */ /* It's no use to change the order below. After compile, Ming will re-organize them as remove mc1; remove mc2; remove mc3;*/ SWFDisplayItem_remove(it3); SWFDisplayItem_remove(it1); SWFDisplayItem_remove(it2); SWFMovie_nextFrame(mo); /* 4th frame */ check_equals(mo, "_root.x0", "'01+02+03+'"); check_equals(mo, "_root.x1", "'1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+'"); check_equals(mo, "_root.x2", "'as_start+as_end+load_called+'"); add_actions(mo, " _root.totals(); stop(); "); SWFMovie_nextFrame(mo); /* 5th frame */ //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
SWFDisplayItem add_button(SWFMovie mo) { SWFDisplayItem it; SWFMovieClip mc; SWFShape sh1, sh2, sh3, sh4; SWFMovieClip bu = newSWFMovieClip(); mc = newSWFMovieClip(); sh1 = make_fill_square(0, 0, 40, 40, 0, 0, 0, 0, 0, 0); // black sh2 = make_fill_square(0, 0, 40, 40, 255, 0, 0, 255, 0, 0); // red sh3 = make_fill_square(0, 0, 40, 40, 0, 255, 0, 0, 255, 0); // green sh4 = make_fill_square(0, 0, 40, 40, 255, 255, 0, 255, 255, 0); // yellow SWFMovieClip_add(bu, (SWFBlock)sh2); // red when idle SWFMovieClip_add(bu, (SWFBlock)compileSWFActionCode( "onRollOut = function() {" " _root.note('onRollOut');" " updateAfterEvent();" " _root.msg='RollOut';" " gotoAndStop(1);" "};" "onRollOver = function() {" " _root.note('onRollOver');" " updateAfterEvent();" " _root.msg='RollOver';" " gotoAndStop(3);" "};" "onMouseDown = function() {" " _root.note('onMouseDown');" " updateAfterEvent();" " _root.msg2='MouseDown';" "};" "onMouseUp = function() {" " _root.note('onMouseUp');" " updateAfterEvent();" " _root.msg2='MouseUp';" "};" "onPress = function() {" " _root.note('onPress');" " updateAfterEvent();" " _root.msg='Press';" " gotoAndStop(2);" "};" "onRelease = function() {" " _root.note('onRelease');" " updateAfterEvent();" " _root.msg='Release';" " gotoAndStop(3);" "};" "onReleaseOutside = function() {" " _root.note('onReleaseOutside');" " updateAfterEvent();" " _root.msg='ReleaseOutside';" " gotoAndStop(1);" "};" "_root.onMouseWheel = function(delta, t) {" " _root.note('onMouseWheel: ' + delta + ', ' + t + ', ' + arguments.length);" " _root.note('onMouseWheel: ' + delta + ', ' + t);" " _root.msg='onMouseWheel: ' + delta + ', ' + t + ', ' + arguments.length;" "};" "Mouse.addListener(_root);" "stop();" )); SWFMovieClip_nextFrame(bu); SWFMovieClip_add(bu, (SWFBlock)sh3); // green on button press SWFMovieClip_add(bu, (SWFBlock)newSWFAction("stop();")); SWFMovieClip_nextFrame(bu); SWFMovieClip_add(bu, (SWFBlock)sh4); // yellow on mouse over SWFMovieClip_add(bu, (SWFBlock)newSWFAction("stop();")); SWFMovieClip_nextFrame(bu); it = SWFMovieClip_add(mc, (SWFBlock)bu); SWFDisplayItem_setName(it, "button"); SWFMovieClip_nextFrame(mc); /* showFrame */ it = SWFMovie_add(mo, (SWFBlock)mc); return it; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip dejagnuclip; SWFShape static1, static2; SWFDisplayItem it1; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); //return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 2); static1 = get_shape(60, 60, 255, 0, 0); static2 = get_shape(60, 60, 0, 255, 0); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFMovie_nextFrame(mo); // Frame 2: place DisplayObject at depth 3 (-16381) it1 = SWFMovie_add(mo, (SWFBlock)static1); SWFDisplayItem_setDepth(it1, 3); SWFDisplayItem_moveTo(it1, 100, 300); SWFDisplayItem_setName(it1, "static1"); SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' onClipConstruct');" " _root.check_equals(typeof(_root), 'movieclip');" " if ( isNaN(_root.depth3Constructed) ) {" " _root.depth3Constructed=1; " " } else {" " _root.depth3Constructed++;" " }" " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);" ), SWFACTION_CONSTRUCT); add_actions(mo, "static1.name='static1';"); check_equals(mo, "typeof(static1)", "'movieclip'"); check_equals(mo, "static1", "_root"); check_equals(mo, "static1.name", "'static1'"); check_equals(mo, "_root.name", "'static1'"); // Gnash allows custom members to shape DisplayObjects... // this is important to verify, see next check for it after REPLACE check_equals(mo, "static1.name", "'static1'"); check_equals(mo, "static1._target", "'/'"); SWFMovie_nextFrame(mo); // Frame 3: replace instance at depth -16381 with DisplayObject 2 if ( SWFMovie_replace(mo, it1, (SWFBlock)static2) ) { abort(); // grace and beauty... } SWFDisplayItem_moveTo(it1, 130, 330); SWFDisplayItem_setName(it1, "static2"); SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' onClipConstruct');" " _root.check_equals(typeof(_root), 'movieclip');" " if ( isNaN(_root.depth3Constructed) ) {" " _root.depth3Constructed=1; " " } else {" " _root.depth3Constructed++;" " }" " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);" ), SWFACTION_CONSTRUCT); // Can still reference the old DisplayObject and it's variables, after replace xcheck_equals(mo, "typeof(static1)", "'movieclip'"); xcheck_equals(mo, "static1", "_root"); xcheck_equals(mo, "static1.name", "'static1'"); check_equals(mo, "_root.name", "'static1'"); // While the new name results undefined... xcheck_equals(mo, "typeof(static2)", "'undefined'"); // the name wasn't changed // Everything suggests that a new instance is NOT created on replace !!! // Gnash here fails because it creates a NEW instance // We can't check the color or the _x in a self-contained testcase unfortunately, // we'll need a MovieTester-based runner for this. // It is expected the color of the current instane is GREEN, and the boundaries // are from 130 to 190 for X and 330 to 390 for Y. // TODO: implement a MovieTester based runner !! SWFMovie_nextFrame(mo); // Frame 4: jump to frame 2, stop and check add_actions(mo, "gotoAndStop(2); " // Shapes don't get their onConstruct event invoked ! "check_equals(typeof(_root.depth3Constructed), 'undefined');" // Original DisplayObject name is still referenceable "check_equals(typeof(static1), 'movieclip');" // And it still has it's user-provided property "check_equals(static1.name, 'static1');" // We can't check the color or the _x in a self-contained testcase unfortunately, // we'll need a MovieTester-based runner for this. // It is expected the color of the current instance is RED, and the boundaries // are from 100 to 120 for both X and Y. // TODO: implement a MovieTester based runner !! "totals();" ); SWFMovie_nextFrame(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc3, mc2, dejagnuclip; SWFAction ac, ac1, initac; SWFDisplayItem it; SWFShape sha; const char *srcdir="."; if (argc > 1) srcdir = argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); sha = newSWFShape(); // Character ID 2. Has 1 showframe. Is exported first. mc2 = newSWFMovieClip(); SWFMovieClip_add(mc2, (SWFBlock)sha); SWFMovieClip_nextFrame(mc2); // Export it. SWFMovie_addExport(mo, (SWFBlock)mc2, "C2"); SWFMovie_writeExports(mo); // Main timeline actions for frame 1 add_actions(mo, "var c = 0; var i = 0; trace('frame 1'); gotoAndStop(3);"); initac = newSWFAction("trace('onInitialize'); _root.i++;"); // ID 3 is defined here. It has no showframe. It is exported immediately. mc3 = newSWFMovieClip(); SWFMovie_addExport(mo, (SWFBlock)mc3, "ctor"); SWFMovie_writeExports(mo); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); // Init actions for ID 3. This only exists to create the constructor // for mc2 in its initactions. ac = newSWFAction( " _global.ctor = function () {" " super();" " trace('Object ID 2 is constructed');" " c += 1;" " };" ); SWFInitAction ia = newSWFInitAction_withId(ac, 3); SWFMovie_add(mo, (SWFBlock)ia); // Init actions for ID 2 (registered class) ac1 = newSWFAction("Object.registerClass('C2', ctor); " "trace('Registered class');"); ia = newSWFInitAction_withId(ac1, 2); SWFMovie_add(mo, (SWFBlock)ia); // Frame 2 SWFMovie_nextFrame(mo); add_actions(mo, "trace('Frame 2');"); // Place object ID 2. it = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setName(it, "mc2"); SWFDisplayItem_addAction(it, initac, SWFACTION_INIT); // Frame 3 SWFMovie_nextFrame(mo); // Remove object ID 2 SWFMovie_remove(mo, it); add_actions(mo, "trace('frame 3');"); // The class should not be constructed if the object is removed after // being placed. It should be constructed if it's not removed. MovieClips // with an onUnload handler are always constructed. check_equals(mo, "c", "0"); check_equals(mo, "i", "0"); check(mo, "_root.mc2 == undefined"); add_actions(mo, "gotoAndPlay(5);"); // Frame 4 SWFMovie_nextFrame(mo); add_actions(mo, "trace('Frame 4');"); // Place object ID 2 again it = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setName(it, "mc2a"); SWFDisplayItem_addAction(it, initac, SWFACTION_INIT); // Frame 5 SWFMovie_nextFrame(mo); // This time the MovieClip was not removed before we get here, // so it should be present and the constructor should be // called. add_actions(mo, "trace('frame 5');"); check_equals(mo, "c", "1"); check_equals(mo, "i", "1"); check(mo, "typeof(_root.mc2a) == 'movieclip'"); add_actions(mo, "stop();"); SWFMovie_nextFrame(mo); puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc1, mc2, dejagnuclip; SWFDisplayItem it; SWFShape sh1,sh2; SWFAction ac1, ac2; int i; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); //return 1; } Ming_init(); mo = newSWFMovie(); SWFMovie_setDimension(mo, 800, 600); //SWFMovie_setRate (mo, 1.0); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFMovie_nextFrame(mo); sh1 = make_fill_square (100, 300, 60, 60, 255, 0, 0, 255, 0, 0); sh2 = make_fill_square (300, 300, 60, 60, 255, 0, 0, 0, 0, 0); it = SWFMovie_add(mo, (SWFBlock)sh1); SWFDisplayItem_setName(it, "sh1"); SWFDisplayItem_setDepth(it, 3); //place the sh1 DisplayObject at depth 3; it = SWFMovie_add(mo, (SWFBlock)sh2); SWFDisplayItem_setName(it, "sh2"); SWFDisplayItem_setDepth(it, 4); //place the sh2 DisplayObject at depth 4; check(mo, "sh1 != undefined"); check(mo, "sh2 != undefined"); // Do these checks mean that shapes are movieclips? // seems not. check_equals(mo, "typeof(sh1)", "'movieclip'"); check_equals(mo, "typeof(sh2)", "'movieclip'"); check_equals(mo, "typeof(_root)", "'movieclip'"); add_actions(mo, "sh1.var1 = 10;" "sh2.var2 = 20;" ); // Do these checks mean that we can add variables to shapes? // seems not, variable are added to the _root, interesting. check_equals(mo, "sh1.var1", "10"); check_equals(mo, "sh2.var2", "20"); check_equals(mo, "_root.var1", "10"); check_equals(mo, "_root.var2", "20"); check_equals(mo, "sh1._x", "0"); check_equals(mo, "sh2._x", "0"); add_actions(mo, "sh1._x = 0;" "sh2._x = 400;" ); check_equals(mo, "sh1._x", "400"); check_equals(mo, "sh2._x", "400"); check_equals(mo, "_root._x", "400"); add_actions(mo, "_root._x = 0;" ); /* cleanup */ // Do these checks mean that shapes are *not* movieclips? check_equals(mo, "typeof(sh1.getDepth())", "'undefined'"); check_equals(mo, "typeof(sh2.getDepth())", "'undefined'"); // Do these checks mean that shapes are *not* movieclips? check_equals(mo, "typeof(getInstanceAtDepth(-16381))", "'undefined'"); check_equals(mo, "typeof(getInstanceAtDepth(-16380))", "'undefined'"); SWFMovie_nextFrame(mo); /* * UdoG's drawing * * See DrawingApiTest.as (inv8) * */ { /* using left fill, non-closed paths */ SWFDisplayItem it1, it2; SWFShape sh = newSWFShape(); SWFMovieClip mc = newSWFMovieClip(); SWFShape_setLineStyle(sh, 1, 0, 0, 0, 255); SWFShape_setLeftFillStyle(sh, SWFShape_addSolidFillStyle(sh, 0, 255, 0, 255)); SWFShape_movePenTo(sh, 20, 10); /* 0 */ SWFShape_drawLineTo(sh, 40, 10); /* 1 */ SWFShape_drawLineTo(sh, 40, 40); /* 2 */ SWFShape_drawLineTo(sh, 20, 40); /* 3 */ SWFShape_drawLineTo(sh, 20, 10); /* 4 */ SWFShape_drawLineTo(sh, 10, 10); /* 5 */ SWFShape_drawLineTo(sh, 10, 20); /* 6 */ SWFShape_drawLineTo(sh, 30, 20); /* 7 */ SWFShape_drawLineTo(sh, 30, 30); /* 8 */ SWFShape_drawLineTo(sh, 20, 30); /* 9 */ it1 = SWFMovieClip_add(mc, (SWFBlock)sh); // Test that clip events are not invoked for shapes #if 0 // current Ming HEAD chokes if we add an onClipConstruct event... SWFDisplayItem_addAction(it1, newSWFAction( "_root.check(false && 'clip event for shape should not be executed');" SWFACTION_CONSTRUCT); #endif SWFDisplayItem_addAction(it1, newSWFAction( "_root.check(false && 'clip event for shape should not be executed');" ), SWFACTION_ENTERFRAME); SWFDisplayItem_addAction(it1, newSWFAction( "_root.check(false && 'clip event for shape should not be executed');" ), SWFACTION_ONLOAD); SWFDisplayItem_addAction(it1, newSWFAction( "_root.check(false && 'clip event for shape should not be executed');" ), SWFACTION_UNLOAD); SWFDisplayItem_addAction(it1, newSWFAction( "_root.check(false && 'clip event for shape should not be executed');" ), SWFACTION_MOUSEMOVE); SWFDisplayItem_addAction(it1, newSWFAction( "_root.check(false && 'clip event for shape should not be executed');" ), SWFACTION_MOUSEDOWN); // None of these should be executed SWFDisplayItem_addAction(it1, newSWFAction( "_root.check(false && 'clip event for shape should not be executed');" ), SWFACTION_ONLOAD); SWFDisplayItem_moveTo(it1, 80, 120); SWFDisplayItem_scale(it1, 2, 2); SWFMovieClip_nextFrame(mc); it2 = SWFMovie_add(mo, (SWFBlock)mc); } { /* using right fill, non-closed paths */ SWFDisplayItem it; SWFShape sh = newSWFShape(); SWFMovieClip mc = newSWFMovieClip(); SWFShape_setLineStyle(sh, 1, 0, 0, 0, 255); SWFShape_setLeftFillStyle(sh, SWFShape_addSolidFillStyle(sh, 0, 255, 0, 255)); SWFShape_movePenTo(sh, 20, 10); /* 0 */ SWFShape_drawLineTo(sh, 40, 10); /* 1 */ SWFShape_drawLineTo(sh, 40, 40); /* 2 */ SWFShape_drawLineTo(sh, 20, 40); /* 3 */ SWFShape_drawLineTo(sh, 20, 10); /* 4 */ SWFShape_drawLineTo(sh, 10, 10); /* 5 */ SWFShape_drawLineTo(sh, 10, 20); /* 6 */ SWFShape_drawLineTo(sh, 30, 20); /* 7 */ SWFShape_drawLineTo(sh, 30, 30); /* 8 */ SWFShape_drawLineTo(sh, 20, 30); /* 9 */ it = SWFMovieClip_add(mc, (SWFBlock)sh); SWFDisplayItem_moveTo(it, 200, 120); SWFDisplayItem_scale(it, 2, 2); SWFMovieClip_nextFrame(mc); it = SWFMovie_add(mo, (SWFBlock)mc); } { /* using left fill, closed paths */ SWFDisplayItem it; SWFShape sh = newSWFShape(); SWFMovieClip mc = newSWFMovieClip(); SWFShape_setLineStyle(sh, 1, 0, 0, 0, 255); SWFShape_setLeftFillStyle(sh, SWFShape_addSolidFillStyle(sh, 255, 0, 0, 255)); SWFShape_movePenTo(sh, 20, 10); /* 0 */ SWFShape_drawLineTo(sh, 40, 10); /* 1 */ SWFShape_drawLineTo(sh, 40, 40); /* 2 */ SWFShape_drawLineTo(sh, 20, 40); /* 3 */ SWFShape_drawLineTo(sh, 20, 10); /* 4 */ SWFShape_drawLineTo(sh, 10, 10); /* 5 */ SWFShape_drawLineTo(sh, 10, 20); /* 6 */ SWFShape_drawLineTo(sh, 30, 20); /* 7 */ SWFShape_drawLineTo(sh, 30, 30); /* 8 */ SWFShape_drawLineTo(sh, 20, 30); /* 9 */ SWFShape_drawLineTo(sh, 20, 10); /* 0 */ it = SWFMovieClip_add(mc, (SWFBlock)sh); SWFDisplayItem_moveTo(it, 80, 200); SWFDisplayItem_scale(it, 2, 2); SWFMovieClip_nextFrame(mc); it = SWFMovie_add(mo, (SWFBlock)mc); } { /* using right fill, closed paths */ SWFDisplayItem it; SWFShape sh = newSWFShape(); SWFMovieClip mc = newSWFMovieClip(); SWFShape_setLineStyle(sh, 1, 0, 0, 0, 255); SWFShape_setRightFillStyle(sh, SWFShape_addSolidFillStyle(sh, 255, 0, 0, 255)); SWFShape_movePenTo(sh, 20, 10); /* 0 */ SWFShape_drawLineTo(sh, 40, 10); /* 1 */ SWFShape_drawLineTo(sh, 40, 40); /* 2 */ SWFShape_drawLineTo(sh, 20, 40); /* 3 */ SWFShape_drawLineTo(sh, 20, 10); /* 4 */ SWFShape_drawLineTo(sh, 10, 10); /* 5 */ SWFShape_drawLineTo(sh, 10, 20); /* 6 */ SWFShape_drawLineTo(sh, 30, 20); /* 7 */ SWFShape_drawLineTo(sh, 30, 30); /* 8 */ SWFShape_drawLineTo(sh, 20, 30); /* 9 */ SWFShape_drawLineTo(sh, 20, 10); /* 0 */ it = SWFMovieClip_add(mc, (SWFBlock)sh); SWFDisplayItem_moveTo(it, 200, 200); SWFDisplayItem_scale(it, 2, 2); SWFMovieClip_nextFrame(mc); it = SWFMovie_add(mo, (SWFBlock)mc); } add_actions(mo, "_root.totals(); stop();"); SWFMovie_nextFrame(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc_red1, mc_red2, mc_red3, mc_red4, mc_red5, dejagnuclip; SWFDisplayItem it_red1, it_red2, it_red3, it_red4, it_red5; SWFShape sh_red; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFMovie_nextFrame(mo); /* 1st frame */ mc_red1 = newSWFMovieClip(); sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc_red1, (SWFBlock)sh_red); add_clip_actions(mc_red1, " _root.x1 += \"depth10+\"; "); SWFMovieClip_nextFrame(mc_red1); /* mc_red1, 1st frame */ add_clip_actions(mc_red1, " _root.x2 += \"depth10+\"; stop(); "); SWFMovieClip_nextFrame(mc_red1); /* mc_red1, 2nd frame */ mc_red2 = newSWFMovieClip(); sh_red = make_fill_square (80, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc_red2, (SWFBlock)sh_red); add_clip_actions(mc_red2, " _root.x1 += \"depth12+\"; "); SWFMovieClip_nextFrame(mc_red2); /* mc_red2, 1st frame */ add_clip_actions(mc_red2, " _root.x2 += \"depth12+\"; stop(); "); SWFMovieClip_nextFrame(mc_red2); /* mc_red2, 2nd frame */ mc_red3 = newSWFMovieClip(); sh_red = make_fill_square (160, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc_red3, (SWFBlock)sh_red); add_clip_actions(mc_red3, " _root.x1 += \"depth11+\"; "); SWFMovieClip_nextFrame(mc_red3); /* mc_red3, 1st frame */ add_clip_actions(mc_red3, " _root.x2 += \"depth11+\"; stop();"); SWFMovieClip_nextFrame(mc_red3); /* mc_red3, 2nd frame */ /* add mc_red1 to _root and name it as "mc_red1" */ it_red1 = SWFMovie_add(mo, (SWFBlock)mc_red1); SWFDisplayItem_setDepth(it_red1, 10); SWFDisplayItem_setName(it_red1, "mc_red1"); /* add mc_red2 to _root and name it as "mc_red2" */ it_red2 = SWFMovie_add(mo, (SWFBlock)mc_red2); SWFDisplayItem_setDepth(it_red2, 12); SWFDisplayItem_setName(it_red2, "mc_red2"); /* add mc_red3 to _root and name it as "mc_red3" */ it_red3 = SWFMovie_add(mo, (SWFBlock)mc_red3); SWFDisplayItem_setDepth(it_red3, 11); SWFDisplayItem_setName(it_red3, "mc_red3"); SWFMovie_nextFrame(mo); /* 2nd frame */ /* Action order is not dependent on DisplayList depth here! */ check_equals(mo, "_root.x1", "'depth10+depth12+depth11+'"); SWFMovie_nextFrame(mo); /* 3rd frame */ mc_red4 = newSWFMovieClip(); sh_red = make_fill_square (240, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc_red4, (SWFBlock)sh_red); add_clip_actions(mc_red4, " _root.x2 += \"depth9+\"; "); SWFMovieClip_nextFrame(mc_red4); /* mc_red4, 1st frame */ /* add mc_red4 to _root and name it as "mc_red4" */ it_red4 = SWFMovie_add(mo, (SWFBlock)mc_red4); SWFDisplayItem_setDepth(it_red4, 9); SWFDisplayItem_setName(it_red4, "mc_red4"); mc_red5 = newSWFMovieClip(); sh_red = make_fill_square (240, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc_red5, (SWFBlock)sh_red); add_clip_actions(mc_red5, " _root.x2 += \"depth13+\"; "); SWFMovieClip_nextFrame(mc_red5); /* mc_red4, 1st frame */ /* add mc_red5 to _root and name it as "mc_red5" */ it_red5 = SWFMovie_add(mo, (SWFBlock)mc_red5); SWFDisplayItem_setDepth(it_red5, 13); SWFDisplayItem_setName(it_red5, "mc_red4"); SWFMovie_nextFrame(mo); /* 4th frame */ check_equals(mo, "_root.x2", "'depth11+depth12+depth10+depth9+depth13+'"); add_actions(mo, " _root.totals(); stop(); "); SWFMovie_nextFrame(mo); /* 5th frame */ //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip dejagnuclip, static3; int i; SWFDisplayItem it1; const char *srcdir="."; if ( argc>1 ) srcdir=argv[1]; else { //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); //return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 2); static3 = get_static_mc(20, 20); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFMovie_nextFrame(mo); // Frame 2: place a static DisplayObject at depth 3 (-16381) it1 = SWFMovie_add(mo, (SWFBlock)static3); SWFDisplayItem_setDepth(it1, 3); SWFDisplayItem_setName(it1, "static1"); SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' onClipConstruct');" " _root.check_equals(typeof(_root), 'movieclip');" " if ( isNaN(_root.depth3Constructed) ) {" " _root.depth3Constructed=1; " " } else {" " _root.depth3Constructed++;" " }" " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);" ), SWFACTION_CONSTRUCT); SWFMovie_nextFrame(mo); // Frame 3: remove DisplayObject at depth -16381 SWFDisplayItem_remove(it1); add_actions(mo, "check_equals(typeof(static1), 'undefined');"); // the replacement failed SWFMovie_nextFrame(mo); // Frame 4: place same static DisplayObject at depth 3 (-16381) it1 = SWFMovie_add(mo, (SWFBlock)static3); SWFDisplayItem_setDepth(it1, 3); SWFDisplayItem_setName(it1, "static2"); SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' onClipConstruct');" " _root.check_equals(typeof(_root), 'movieclip');" " if ( isNaN(_root.depth3Constructed) ) {" " _root.depth3Constructed=1; " " } else {" " _root.depth3Constructed++;" " }" " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);" ), SWFACTION_CONSTRUCT); // Frame 5: jump to frame 2, stop and check add_actions(mo, "check_equals(typeof(static1), 'undefined');" "check_equals(typeof(static2), 'movieclip');" "gotoAndStop(2); " // two instances were placed in total, the second instance is not // supposed to be removed on jump back, being on a depth supposed // to contain a timeline instance at that time // Gnash fails here by removing the instance placed in a later frame "check_equals(_root.depth3Constructed, 2);" // Gnash fails here by removing the instance placed in a later frame "check_equals(typeof(static1), 'undefined');" // Gnash fails here by removing the instance placed in a later frame // (thus placing a new instance) "check_equals(typeof(static2), 'movieclip');" "totals();" ); SWFMovie_nextFrame(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; int frames; SWFVideoStream stream; SWFDisplayItem item; SWFMovieClip dejagnuclip; FILE *flv, *font_file; SWFFont font; char filename[256]; char fdbfont[1024]; if ( argc>1 ) mediadir=argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } sprintf(filename, "%s/square.flv", mediadir); flv = fopen(filename, "rb"); if (flv == NULL) { perror(filename); return -1; } sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", mediadir); font_file = fopen(fdbfont, "r"); if ( font_file == NULL ) { perror(fdbfont); exit(1); } Ming_init(); Ming_useSWFVersion (OUTPUT_VERSION); font = loadSWFFontFromFile(font_file); mo = newSWFMovie(); SWFMovie_setDimension(mo, 320, 96); if (mo == NULL) return -1; SWFMovie_setRate(mo, 5); dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 200, 200); item = SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFDisplayItem_setDepth(item, 200); SWFDisplayItem_move(item, 140, 0); stream = newSWFVideoStream_fromFile(flv); item = SWFMovie_add(mo, (SWFBlock)stream); SWFDisplayItem_setName(item, "vid"); // A bug in Ming prevents this from working the // way I liked it to. It was useful to try this // out as it exposed a bad bug in gnash eating up // all memory and a few other issues. // // In order to keep the test *runner* untouched // this will be commented out for now. When Ming // is fixed I'll like to have two instances of // the definition playing one near the other, // both playing all frames. // //item = SWFMovie_add(mo, (SWFBlock)stream); //SWFDisplayItem_move(item, 150, 0); // Mouse clicks toggle play/stop add_actions(mo, "_root.onMouseDown = function() {" " if (stopped) { play(); stopped=false; }" " else { stop(); stopped=true; }" "};"); // Pressing a number jumps to the specified frame add_actions(mo, "_root.onKeyDown = function() {" " var fnum = Key.getAscii() - 47;" //" trace('going to frame '+fnum);" " _root.gotoAndPlay(fnum);" "}; Key.addListener(_root);"); // TODO: dynamic frame rate adjust frames = SWFVideoStream_getNumFrames(stream); for(; frames > 0; frames--) { SWFMovie_nextFrame(mo); } /// Video.clear() should not work on embedded Videos. add_actions(mo, "stop(); vid.clear(); trace(vid);"); add_actions(mo, "note('You should still see the video frame." " Click to replay');" "o = {};" "o.onMouseDown = function() { _root.play(); };" "Mouse.addListener(o);" ); SWFMovie_nextFrame(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }