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; }
SWFShape get_shape(int width, int height, int r, int g, int b) { SWFShape sh; /*sh = make_fill_square (-(width/2), -(height/2), width, height, r, g, b, r, g, b);*/ sh = make_fill_square (0, 0, width, height, r, g, b, r, g, b); return sh; }
SWFButton get_button(int width, int height, int r, int g, int b) { SWFButton bu = newSWFButton(); SWFShape sh; sh = make_fill_square (0, 0, width, height, r, g, b, r, g, b); SWFButton_addCharacter(bu, (SWFCharacter)sh, SWFBUTTON_UP ); return bu; }
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; }
SWFMovieClip get_static_mc(int width, int height) { SWFShape sh; SWFMovieClip mc; 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); return mc; }
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 addRedSquareExport(SWFMovie mo) { SWFShape sh; SWFMovieClip mc; sh = make_fill_square (0, 0, 60, 60, 255, 0, 0, 255, 0, 0); mc = newSWFMovieClip(); SWFMovieClip_add(mc, (SWFBlock)sh); /* This is here just to turn the clip into an active one */ add_clip_actions(mc, "onRollOver = function() {};"); SWFMovieClip_nextFrame(mc); SWFMovie_addExport(mo, (SWFBlock)mc, "redsquare"); SWFMovie_writeExports(mo); }
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; }
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; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc1, mc2, dejagnuclip; SWFShape sh1, sh2; SWFDisplayItem it1, it2; 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, "testvar1 = 0; testvar2 = 0;"); SWFMovie_nextFrame(mo); // frame1 // // Define movieClips // mc1 = newSWFMovieClip(); sh1 = make_fill_square (100, 100, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc1, (SWFBlock)sh1); SWFMovieClip_nextFrame(mc1); mc2 = newSWFMovieClip(); sh2 = make_fill_square (300, 100, 60, 60, 255, 0, 0, 0, 255, 0); SWFMovieClip_add(mc2, (SWFBlock)sh2); SWFMovieClip_nextFrame(mc2); SWFMovie_nextFrame(mo); // frame2 // // Place mc1 at depth 3, place mc1 at depth3 again with a different name; // Observed behaviour: later place does not create a new DisplayObject // it1 = SWFMovie_add(mo, (SWFBlock)mc1); SWFDisplayItem_setDepth(it1, 3); SWFDisplayItem_setName(it1, "static_mc1"); SWFDisplayItem_addAction(it1, newSWFAction(" _root.testvar1++; trace(this); trace(_root.testvar1); "), SWFACTION_INIT | SWFACTION_CONSTRUCT | SWFACTION_ONLOAD); it2 = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setDepth(it2, 3); SWFDisplayItem_setName(it2, "static_mc2"); SWFDisplayItem_addAction(it2, newSWFAction(" _root.testvar2++; trace(this); trace(_root.testvar2); "), SWFACTION_INIT | SWFACTION_CONSTRUCT | SWFACTION_ONLOAD); check_equals(mo, "typeof(static_mc1)", "'movieclip'"); if(OUTPUT_VERSION > 5) { // check that "static_mc2" doesn't get placed check_equals(mo, "typeof(static_mc2)", "'undefined'"); } else { // check that "static_mc2" does get placed check_equals(mo, "typeof(static_mc2)", "'movieclip'"); } SWFMovie_nextFrame(mo); // frame3 if(OUTPUT_VERSION > 5) { check_equals(mo, "testvar1", "3"); check_equals(mo, "testvar2", "0"); } else { // swf5 does not support CONSTRUCT event check_equals(mo, "testvar1", "2"); check_equals(mo, "testvar2", "2"); } // // Place mc2 at depth 3 again. // Observed behaviour: no new DisplayObject gets created // it2 = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setDepth(it2, 3); SWFDisplayItem_setName(it2, "static_mc3"); check_equals(mo, "typeof(static_mc1)", "'movieclip'"); if(OUTPUT_VERSION > 5) { // check that "static_mc3" doesn't get placed check_equals(mo, "typeof(static_mc3)", "'undefined'"); } else { // check that "static_mc3" does get placed check_equals(mo, "typeof(static_mc3)", "'movieclip'"); } SWFMovie_nextFrame(mo); // frame4 // // Place mc1 at depth 3 again with ratio set to 0.2 // Observed behaviour: no new DisplayObject get placed(created). // it2 = SWFMovie_add(mo, (SWFBlock)mc1); SWFDisplayItem_setDepth(it2, 3); SWFDisplayItem_setName(it2, "static_mc4"); SWFDisplayItem_setRatio(it2, 0.2); check_equals(mo, "typeof(static_mc1)", "'movieclip'"); if(OUTPUT_VERSION > 5) { // check that "static_mc4" doesn't get placed. check_equals(mo, "typeof(static_mc4)", "'undefined'"); } else { // check that "static_mc4" does get placed. check_equals(mo, "typeof(static_mc4)", "'movieclip'"); } SWFMovie_nextFrame(mo); // frame5 // // Place mc2 at depth 3 again with ratio set to 0.2 // Observed behaviour: no new DisplayObject get placed(created). // it2 = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setDepth(it2, 3); SWFDisplayItem_setName(it2, "static_mc5"); SWFDisplayItem_setRatio(it2, 0.2); check_equals(mo, "typeof(static_mc1)", "'movieclip'"); if(OUTPUT_VERSION > 5) { // check that "static_mc5" doesn't get placed. check_equals(mo, "typeof(static_mc5)", "'undefined'"); } else { // check that "static_mc5" does get placed. check_equals(mo, "typeof(static_mc5)", "'movieclip'"); } SWFMovie_nextFrame(mo); // frame6 // // Odd, where are the movieclips now? // Note that all those movieclips are defined above but not now. // if(OUTPUT_VERSION <= 5) { add_actions(mo, "check_equals(typeof(static_m1), 'undefined');" "check_equals(typeof(static_m2), 'undefined');" "check_equals(typeof(static_m3), 'undefined');" "check_equals(typeof(static_m4), 'undefined');" "check_equals(typeof(static_m5), 'undefined');" ); } add_actions(mo, " _root.totals(); stop(); "); SWFMovie_nextFrame(mo); // frame7 //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 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 mc1, mc2, dejagnuclip; 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(); 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, " _root.x = '0+'; "); SWFMovie_nextFrame(mo); /* 1st frame */ mc1 = newSWFMovieClip(); sh1 = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc1, (SWFBlock)sh1); /* add init actions */ add_clip_init_actions(mc1, " _root.note('mc1.init_actions'); " " _root.x += '1+'; " " y = 'var_of_root'; " ); /* add actions */ add_clip_actions(mc1, " _root.note('mc1.actions'); _root.x += '9+'; "); SWFMovieClip_nextFrame(mc1);//1st frame mc2 = newSWFMovieClip(); sh2 = make_fill_square (600, 600, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc2, (SWFBlock)sh2); /* add init actions */ add_clip_init_actions(mc2, " _root.note('mc2.init_actions'); _root.x += '3+'; "); /* add actions */ add_clip_actions(mc2, " _root.note('mc2.actions'); _root.x += '11+'; "); SWFMovieClip_nextFrame(mc2);//1st frame /* add mc1 to _root */ SWFDisplayItem it1; it1 = SWFMovie_add(mo, (SWFBlock)mc1); SWFDisplayItem_setDepth(it1, 10); SWFDisplayItem_setName(it1, "mc1"); SWFDisplayItem_addAction(it1, newSWFAction(" _root.note('mc1.onClipInitialize'); _root.x += '2+'; " "_root.check_equals(this.__proto__, MovieClip.prototype);" ), SWFACTION_INIT); SWFDisplayItem_addAction(it1, newSWFAction(" _root.note('mc1.onClipConstruct'); _root.x += '5+'; "), SWFACTION_CONSTRUCT); SWFDisplayItem_addAction(it1, newSWFAction(" _root.note('mc1.onClipLoad'); _root.x += '8+'; "), SWFACTION_ONLOAD); /* add mc2 to _root */ SWFDisplayItem it2; it2 = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setDepth(it2, 11); SWFDisplayItem_setName(it2, "mc2"); SWFDisplayItem_addAction(it2, newSWFAction(" _root.note('mc2.onClipInitialize'); _root.x += '4+'; "), SWFACTION_INIT); SWFDisplayItem_addAction(it2, newSWFAction(" _root.note('mc2.onClipConstruct'); _root.x += '6+'; "), SWFACTION_CONSTRUCT); SWFDisplayItem_addAction(it2, newSWFAction(" _root.note('mc2.onClipLoad'); _root.x += '10+'; "), SWFACTION_ONLOAD); /* add main timeline actions */ add_actions(mo, "_root.note('_root.actions'); _root.x += '7+'; "); SWFMovie_nextFrame(mo); /* 2nd frame */ /* The check below used to succeeds, and started failing when * executing init actions "after" DLIST tags. * Should be fixed if we postpone the call to ::construct * to "after" init actions are executed, which would require * some book keeping in sprite_instance class */ check_equals(mo, "_root.x", "'0+1+2+3+4+5+6+7+8+9+10+11+'"); check_equals(mo, "_root.y", "'var_of_root'"); add_actions(mo, " _root.totals(); stop(); "); SWFMovie_nextFrame(mo); /* 3rd frame */ //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; }
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; SWFDisplayItem it; const char *srcdir="."; char fdbfont[256]; SWFMovieClip dejagnuclip; /********************************************* * * Initialization * *********************************************/ puts("Setting things up"); Ming_init(); Ming_useSWFVersion (OUTPUT_VERSION); Ming_setScale(20.0); mo = newSWFMovie(); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate(mo, 1); if ( argc>1 ) srcdir=argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir); FILE *font_file = fopen(fdbfont, "r"); if ( font_file == NULL ) { perror(fdbfont); exit(1); } /*SWFBrowserFont bfont = newSWFBrowserFont("_sans");*/ font = loadSWFFontFromFile(font_file); /* Dejagnu equipment */ dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 800, 600); it = SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFDisplayItem_setDepth(it, 200); SWFDisplayItem_move(it, 200, 0); add_text_field(mo, "textfield", "_root.msg", "Button events", 10, 0, 5); add_text_field(mo, "textfield2", "_root.msg2", "Mouse events", 11, 0, 100); add_text_field(mo, "textfield3", "_root.msg3", "Key events", 12, 0, 80); SWFMovie_nextFrame(mo); /***************************************************** * * Add button * *****************************************************/ it = add_button(mo); SWFDisplayItem_moveTo(it, 40, 30); SWFDisplayItem_setName(it, "square1"); SWFDisplayItem_setDepth(it, 2); // Mouse pointer events //add_actions(mo, "square1.button.onRollOver = function() { _root.msg2 = 'RollOver'; };"); //add_actions(mo, "square1.button.onRollOut = function() { _root.msg2 = 'RollOut'; };"); // Mouse buttons events //add_actions(mo, "square1.button.onPress = function() { _root.msg2 = 'Press'; };"); //add_actions(mo, "square1.button.onRelease = function() { _root.msg2 = 'Release'; gotoAndStop(1); };"); //add_actions(mo, "square1.button.onReleaseOutside = function() { _root.msg2 = 'ReleaseOutside'; };"); // Focus events add_actions(mo, "square1.button.onSetFocus = function() { _root.msg3 = 'SetFocus'; };"); // Key events - button needs focus for these to work add_actions(mo, "square1.button.onKeyDown = function() { _root.msg3 = 'KeyDown'; };"); add_actions(mo, "square1.button.onKeyUp = function() { _root.msg3 = 'KeyUp'; };"); SWFMovie_nextFrame(mo); /* showFrame */ /***************************************************** * * On second frame, add a shape at lower depth * *****************************************************/ { SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0); SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh); SWFDisplayItem_setDepth(itsh, 1); SWFMovie_nextFrame(mo); /* showFrame */ } /***************************************************** * * On third frame, add a shape at higher depth * *****************************************************/ { SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0); SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh); SWFDisplayItem_setDepth(itsh, 3); SWFDisplayItem_setColorAdd(itsh, 0, 0, 0, -128); SWFMovie_nextFrame(mo); /* showFrame */ } /***************************************************** * * On third frame, add a shape at higher depth * *****************************************************/ { add_actions(mo, "square1.button.enabled = false;" //"_root.msg = _root.msg2 = _root.msg3 = 'Idle';" "stop();" "totals();" ); SWFMovie_nextFrame(mo); /* showFrame */ } /***************************************************** * * Save it... * *****************************************************/ puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFDisplayItem it1, it2, it3; SWFDisplayItem it41; SWFDisplayItem it51; SWFMovieClip mc1, mc2, mc3, dejagnuclip; SWFMovieClip mc4, mc41; SWFMovieClip mc5, mc51; SWFShape sh1, sh2, sh3; 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, 12); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); add_actions(mo, " haslooped1=false; haslooped2=false; haslooped3=false;" " mc1Initialized=0; mc1Unloaded=0;" " mc2Initialized=0; mc2Unloaded=0;" " mc3Initialized=0; mc3Unloaded=0;" " asOrder='0+';"); SWFMovie_nextFrame(mo); // frame1 sh1 = make_fill_square (100, 100, 60, 60, 255, 0, 0, 255, 0, 0); mc1 = newSWFMovieClip(); SWFMovieClip_add(mc1, (SWFBlock)sh1); SWFMovieClip_nextFrame(mc1); sh2 = make_fill_square (200, 200, 60, 60, 0, 0, 0, 0, 0, 0); mc2 = newSWFMovieClip(); SWFMovieClip_add(mc2, (SWFBlock)sh2); SWFMovieClip_nextFrame(mc2); sh3 = make_fill_square (300, 300, 60, 60, 0, 0, 0, 0, 0, 0); mc3 = newSWFMovieClip(); SWFMovieClip_add(mc3, (SWFBlock)sh3); SWFMovieClip_nextFrame(mc3); it1 = SWFMovie_add(mo, (SWFBlock)mc1); SWFDisplayItem_setName(it1, "mc1"); SWFDisplayItem_setDepth(it1, 100); SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' initialized');" "_root.mc1Initialized++;" "_root.asOrder += '1+';" ), SWFACTION_INIT); SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' unloaded');" "_root.mc1Unloaded++;" "_root.asOrder += '3+';" ), SWFACTION_UNLOAD); SWFMovie_nextFrame(mo); // frame2 SWFDisplayItem_remove(it1); it2 = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setName(it2, "mc2"); SWFDisplayItem_setRatio(it2, 0.1); SWFDisplayItem_setDepth(it2, 100); SWFDisplayItem_addAction(it2, newSWFAction( "_root.note(this+' initialized');" "_root.mc2Initialized++;" "_root.asOrder += '2+';" ), SWFACTION_INIT); SWFDisplayItem_addAction(it2, newSWFAction( "_root.note(this+' unloaded');" "_root.mc2Unloaded++;" "_root.asOrder += '5+';" ), SWFACTION_UNLOAD); SWFMovie_nextFrame(mo); // frame3 SWFDisplayItem_remove(it2); it3 = SWFMovie_add(mo, (SWFBlock)mc3); SWFDisplayItem_setName(it3, "mc3"); SWFDisplayItem_setRatio(it3, 0.2); SWFDisplayItem_setDepth(it3, 100); SWFDisplayItem_addAction(it3, newSWFAction( "_root.note(this+' initialized');" "_root.mc3Initialized++;" "_root.asOrder += '4+';" ), SWFACTION_INIT); SWFDisplayItem_addAction(it3, newSWFAction( "_root.note(this+' unloaded');" "_root.mc3Unloaded++;" ), SWFACTION_UNLOAD); SWFMovie_nextFrame(mo); // frame4 SWFMovie_nextFrame(mo); // frame 5 add_actions(mo, "if(! haslooped1) {" " gotoAndPlay(5);" " haslooped1 = true;" "}" ); SWFMovie_nextFrame(mo); // frame 6 check_equals(mo, "mc1Initialized", "2"); check_equals(mo, "mc2Initialized", "2"); check_equals(mo, "mc3Initialized", "1"); check_equals(mo, "mc1Unloaded", "2"); check_equals(mo, "mc2Unloaded", "2"); check_equals(mo, "mc3Unloaded", "0"); xcheck_equals(mo, "asOrder", "'0+1+2+3+4+5+1+2+3+5+'"); SWFMovie_nextFrame(mo); // frame 7 // // ==case 2== // mc4 = newSWFMovieClip(); mc41 = newSWFMovieClip(); SWFMovieClip_nextFrame(mc41); it41 = SWFMovieClip_add(mc4, (SWFBlock)mc41); add_clip_actions(mc4, "_root.check_equals(this._target, '/instance3');" "inst = this.getInstanceAtDepth(-16383);" "if(! haslooped2) {" " haslooped2 = true;" " _root.check_equals(inst._target, '/instance3/instance4');" "} else {" " _root.check_equals(inst._target, '/instance3/instance5');" " stop();" "}" ); SWFMovieClip_nextFrame(mc4); SWFDisplayItem_remove(it41); SWFMovieClip_nextFrame(mc4); SWFMovie_add(mo, mc4); SWFMovie_nextFrame(mo); // frame 9 SWFMovie_nextFrame(mo); // frame 10 // // ==case 3== // mc5 = newSWFMovieClip(); mc51 = newSWFMovieClip(); SWFMovieClip_nextFrame(mc51); it51 = SWFMovieClip_add(mc5, (SWFBlock)mc51); add_clip_actions(mc5, "_root.check_equals(this._target, '/instance6');" "inst = this.getInstanceAtDepth(-16383);" "if(! haslooped3) {" " haslooped3 = true;" " _root.check_equals(inst._target, '/instance6/instance7');" "} else {" " _root.check_equals(inst._target, '/instance6/instance7');" " stop();" "}" ); SWFMovieClip_nextFrame(mc5); SWFMovieClip_nextFrame(mc5); SWFMovie_add(mo, mc5); SWFMovie_nextFrame(mo); // frame 11 SWFMovie_nextFrame(mo); // frame 12 SWFMovie_nextFrame(mo); // frame 13 mc5 = newSWFMovieClip(); add_clip_actions(mc5, "_root.check_equals(this._target, '/instance9');"); SWFMovieClip_nextFrame(mc5); SWFMovie_add(mo, mc5); SWFMovie_nextFrame(mo); // frame 14 add_actions(mo, "totals(16); stop();"); SWFMovie_nextFrame(mo); // frame 15 //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 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 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 mc_red, dejagnuclip; 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, 1.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 - so we can use _root.note */ mc_red = newSWFMovieClip(); sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0); SWFMovieClip_add(mc_red, (SWFBlock)sh_red); add_clip_actions(mc_red, " _root.note('frm1 of mc_red - gotoAndStop(2)'); " "x = 'as_in_frm1_of_mc_red'; " "gotoAndStop(2); "); SWFMovieClip_nextFrame(mc_red); /* 1st frame */ add_clip_actions(mc_red, " _root.note('frm2 of mc_red - gotoAndStop(3)'); " "x = 'as_in_frm2_of_mc_red'; " "gotoAndStop(3); "); SWFMovieClip_nextFrame(mc_red); /* 2nd frame */ add_clip_actions(mc_red, " _root.note('frm3 of mc_red - gotoAndStop(4)'); " "x = 'as_in_frm3_of_mc_red'; " "gotoAndStop(4); "); SWFMovieClip_nextFrame(mc_red); /* 3rd frame */ SWFMovieClip_nextFrame(mc_red); /* 4th frame */ SWFDisplayItem it_red; it_red = SWFMovie_add(mo, (SWFBlock)mc_red); SWFDisplayItem_setDepth(it_red, 3); SWFDisplayItem_setName(it_red, "mc_red"); add_actions(mo, " _root.note('frm2 of root - gotoAndStop(3)'); " "mc_red.x = 'as_in_frm2_of_root'; " "gotoAndStop(3); "); SWFMovie_nextFrame(mo); /* 2nd frame */ /* mc_red.x has been set after playing the 1st frame, check it here */ add_actions(mo, " check_equals(mc_red.x, 'as_in_frm1_of_mc_red'); " " _root.note('frm3 of root - gotoAndStop(4)');" "mc_red.x = 'as_in_frm3_of_root'; " "gotoAndStop(4); "); SWFMovie_nextFrame(mo); /* 3rd frame */ /* mc_red.x has been set again after playing the 2nd frame, check it again */ add_actions(mo, " check_equals(mc_red.x, 'as_in_frm2_of_mc_red'); " " _root.note('frm4 of root - gotoAndStop(5)');" " mc_red.x = \"as_in_frm4_of_root\"; " " gotoAndStop(5); "); SWFMovie_nextFrame(mo); /* 4th frame */ /* mc_red.x has been set again after playing the 3rd frame, check it again */ check_equals(mo, "mc_red.x", "'as_in_frm3_of_mc_red'"); 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; SWFDisplayItem it; const char *srcdir="."; SWFMovieClip dejagnuclip; /********************************************* * * Initialization * *********************************************/ puts("Setting things up"); Ming_init(); Ming_useSWFVersion (OUTPUT_VERSION); Ming_setScale(20.0); mo = newSWFMovie(); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate(mo, 12); if ( argc>1 ) srcdir=argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } font = get_default_font(srcdir); /* Dejagnu equipment */ dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 800, 600); it = SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFDisplayItem_setDepth(it, 200); SWFDisplayItem_move(it, 200, 0); add_text_field(mo, "textfield", "_root.msg", "Button events", 10, 0, 5); add_text_field(mo, "textfield2", "_root.msg2", "Mouse events", 11, 0, 100); add_text_field(mo, "textfield3", "_root.msg3", "Key events", 12, 0, 80); SWFMovie_nextFrame(mo); /* showFrame */ /***************************************************** * * Add button * *****************************************************/ it = add_button(mo); SWFDisplayItem_moveTo(it, 40, 30); SWFDisplayItem_setName(it, "square1"); SWFDisplayItem_setDepth(it, 2); add_actions(mo, "function printBounds(b) {" " return ''+Math.round(b.xMin*100)/100+','+Math.round(b.yMin*100)/100+' '+Math.round(b.xMax*100)/100+','+Math.round(b.yMax*100)/100;" "}" ); // // Mouse pointer events // add_actions(mo, "square1.button.onRollOver = function() { " " _root.msg2 = 'RollOver'; " // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); add_actions(mo, "square1.button.onRollOut = function() {" " _root.msg2 = 'RollOut'; " // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); // // Mouse buttons events // add_actions(mo, "square1.button.onPress = function() {" " _root.msg2 = 'Press'; " // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); add_actions(mo, "square1.button.onRelease = function() {" " _root.msg2 = 'Release'; " // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); add_actions(mo, "square1.button.onReleaseOutside = function() {" " _root.msg2 = 'ReleaseOutside'; " // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); // // Focus events // add_actions(mo, "square1.button.onSetFocus = function() {" " _root.msg3 = 'SetFocus';" // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); // // Key events - button needs focus for these to work // add_actions(mo, "square1.button.onKeyDown = function() {" " _root.msg3 = 'KeyDown';" // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); add_actions(mo, "square1.button.onKeyUp = function() {" " _root.msg3 = 'KeyUp';" // Target is the one this function was defined in " check_equals(_target, '/');" "};" ); SWFMovie_nextFrame(mo); /* showFrame */ /***************************************************** * * On second frame, check construction of the button * DisplayObject states and give instructions to proceed * * *****************************************************/ add_actions(mo, "Array.prototype.realLength = function() {" " var l=0; for (var i in this) { " " if (Number(i) == i) l++;" /* count only numbers */ " };" " return l;" "};"); /* buttonChild was initialized with 2 elements */ check_equals(mo, "typeof(_root.buttonChild)", "'object'"); check(mo, "_root.buttonChild instanceof Array"); check_equals(mo, "_root.buttonChild.realLength()", "2"); /* UP and ALL states */ /* sprite for ALL states */ check_equals(mo, "typeof(_root.buttonChild[10])", "'object'"); check_equals(mo, "(_root.buttonChild[10].nam)", "'_level0.square1.button.instance5'"); check_equals(mo, "(_root.buttonChild[10].exe)", "1"); check_equals(mo, "(_root.buttonChild[10].uld)", "0"); /* sprite for UP state */ check_equals(mo, "typeof(_root.buttonChild[12])", "'object'"); check_equals(mo, "(_root.buttonChild[12].nam)", "'_level0.square1.button.instance6'"); check_equals(mo, "(_root.buttonChild[12].exe)", "1"); check_equals(mo, "(_root.buttonChild[12].uld)", "0"); check_equals(mo, "_level0.square1.button.instance6._name", "'instance6'"); check_equals(mo, "_level0.square1.button.instance6.getDepth()", "-16371"); /* sprite for HIT state not constructed */ check_equals(mo, "typeof(_root.buttonChild[11])", "'undefined'"); /* sprite for DOWN state not constructed */ check_equals(mo, "typeof(_root.buttonChild[13])", "'undefined'"); add_actions(mo, "stop();" /*"_root.note('buttonChild is '+dumpObj(_root.buttonChild));"*/ "_root.testno=0;" "_root.square1.onRollOut = function() { _root.testno++; delete _root.square1.onRollOut; nextFrame(); };" "_root.note('" "0. Roll over and out the red square, not touching the small dark-red square in it." "');"); /* hitTest should work on every child, not just first added */ check(mo, "_level0.square1.hitTest(60,60,true)"); SWFMovie_nextFrame(mo); /* showFrame */ /***************************************************** * * On third frame, start the button event test * *****************************************************/ add_actions(mo, "stop();" /*"_root.note('buttonChild is '+dumpObj(_root.buttonChild));"*/ "_root.testno=1;" "_root.note('" "1. Roll over the red square." "');"); SWFMovie_nextFrame(mo); /* showFrame */ /***************************************************** * * On fourth frame, add a shape at lower depth, * and check bounds of square1 * * *****************************************************/ { SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0); SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh); SWFDisplayItem_setDepth(itsh, 1); check_equals(mo, "printBounds(square1.getBounds())", "'-0.05,-0.05 40.05,40.05'"); /* buttonChild should now have a total of 4 elements (UP,DOWN, OVER and ALL states) */ check_equals(mo, "typeof(_root.buttonChild)", "'object'"); check(mo, "_root.buttonChild instanceof Array"); check_equals(mo, "_root.buttonChild.realLength()", "4"); /* sprite for ALL states */ check_equals(mo, "typeof(_root.buttonChild[10])", "'object'"); check_equals(mo, "(_root.buttonChild[10].nam)", "'_level0.square1.button.instance5'"); check_equals(mo, "(_root.buttonChild[10].exe)", "1"); check_equals(mo, "(_root.buttonChild[10].uld)", "0"); /* sprite for UP state */ check_equals(mo, "typeof(_root.buttonChild[12])", "'object'"); check_equals(mo, "(_root.buttonChild[12].nam)", "'_level0.square1.button.instance6'"); check_equals(mo, "(_root.buttonChild[12].exe)", "3"); check_equals(mo, "(_root.buttonChild[12].uld)", "2"); /* sprite for OVER state */ check_equals(mo, "typeof(_root.buttonChild[13])", "'object'"); check_equals(mo, "(_root.buttonChild[13].nam)", "'_level0.square1.button.instance7'"); check_equals(mo, "(_root.buttonChild[13].exe)", "4"); check_equals(mo, "(_root.buttonChild[13].uld)", "4"); /* sprite for DOWN state */ check_equals(mo, "typeof(_root.buttonChild[14])", "'object'"); check_equals(mo, "(_root.buttonChild[14].nam)", "'_level0.square1.button.instance8'"); check_equals(mo, "(_root.buttonChild[14].exe)", "2"); check_equals(mo, "(_root.buttonChild[14].uld)", "2"); /* sprite for HIT state never constructed */ check_equals(mo, "typeof(_root.buttonChild[11])", "'undefined'"); add_actions(mo, "stop();" "_root.note('-- Added shape at lower depth --');" "_root.testno++;" "_root.note(_root.testno+'. Roll over the square.');" ); SWFMovie_nextFrame(mo); /* showFrame */ } /***************************************************** * * On fifth frame, add a shape at higher depth * *****************************************************/ { SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0); SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh); SWFDisplayItem_setDepth(itsh, 3); SWFDisplayItem_setColorAdd(itsh, 0, 0, 0, -128); /* buttonChild should now have a total of 4 elements (UP,DOWN, OVER and ALL states) */ check_equals(mo, "typeof(_root.buttonChild)", "'object'"); check(mo, "_root.buttonChild instanceof Array"); check_equals(mo, "_root.buttonChild.realLength()", "4"); /* sprite for ALL states */ check_equals(mo, "typeof(_root.buttonChild[10])", "'object'"); check_equals(mo, "(_root.buttonChild[10].nam)", "'_level0.square1.button.instance5'"); check_equals(mo, "(_root.buttonChild[10].exe)", "1"); check_equals(mo, "(_root.buttonChild[10].uld)", "0"); /* sprite for UP state */ check_equals(mo, "typeof(_root.buttonChild[12])", "'object'"); check_equals(mo, "(_root.buttonChild[12].nam)", "'_level0.square1.button.instance6'"); check_equals(mo, "(_root.buttonChild[12].exe)", "5"); check_equals(mo, "(_root.buttonChild[12].uld)", "4"); /* sprite for OVER state */ check_equals(mo, "typeof(_root.buttonChild[13])", "'object'"); check_equals(mo, "(_root.buttonChild[13].nam)", "'_level0.square1.button.instance7'"); check_equals(mo, "(_root.buttonChild[13].exe)", "8"); check_equals(mo, "(_root.buttonChild[13].uld)", "8"); /* sprite for DOWN state */ check_equals(mo, "typeof(_root.buttonChild[14])", "'object'"); check_equals(mo, "(_root.buttonChild[14].nam)", "'_level0.square1.button.instance8'"); check_equals(mo, "(_root.buttonChild[14].exe)", "4"); check_equals(mo, "(_root.buttonChild[14].uld)", "4"); /* sprite for HIT state never constructed */ check_equals(mo, "typeof(_root.buttonChild[11])", "'undefined'"); add_actions(mo, "stop();" "_root.note('-- Added shape at higher depth --');" "_root.testno++;" "_root.note(_root.testno+'. Roll over the square.');" ); SWFMovie_nextFrame(mo); /* showFrame */ } /***************************************************** * * On sixth frame, disable the button * and check total tests so far * *****************************************************/ { add_actions(mo, "check_equals(square1.button.enabled, true);" "square1.button.enabled = 6;" "check_equals(square1.button.enabled, 6);" "square1.button.enabled = 'string';" "check_equals(square1.button.enabled, 'string');" "square1.button._visible = false;" "check_equals(square1.button.enabled, 'string');" "square1.button._visible = true;" "square1.button.enabled = false;" "stop();" "_root.totals(160);" "_root.note('-- Button disabled, try playing with it, nothing should happen --');" ); SWFMovie_nextFrame(mo); /* showFrame */ } /***************************************************** * * Save it... * *****************************************************/ puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
SWFDisplayItem add_button(SWFMovie mo) { SWFDisplayItem it; SWFMovieClip mc; SWFButtonRecord br; SWFShape sh1, sh2, sh3, sh4, sh1a, sh2a, sh3a, sh4a; SWFButton bu = newSWFButton(); static SWFMovieClip ermc; /* Events-reporting mc */ mc = newSWFMovieClip(); if ( ! ermc ) { ermc = newSWFMovieClip(); SWFMovieClip_add(ermc, newSWFAction( "_global.dumpObj = function(o,indent) {" " var s = '';" " if ( typeof(o) == 'object' ) {" " s += '{';" " var first=1;" " for (var i in o) {" " if (!first) s+=',';" " s+= i+':'+dumpObj(o[i]);" " first=0;" " }" " s += '}';" " } else {" " s += o;" " }" " return s;" "};" "if ( _root.buttonChild == undefined ) _root.buttonChild = [];" "var myDepth = getDepth()+16383;" "var myName = ''+this;" "if ( _root.buttonChild[myDepth] == undefined ) _root.buttonChild[myDepth] = {nam:myName,exe:1,uld:0};" "else _root.buttonChild[myDepth]['exe']++;" //"_root.note('Actions in frame0 of '+this+' at depth '+myDepth+' executed.');" "this.onUnload = function() {" " var myDepth = -(getDepth()+32769-16383);" //" _root.note(''+this+' at depth '+myDepth+' unloaded.');" " _root.buttonChild[myDepth]['uld']++;" "};" "for (i in _level0.square1.button) { trace (i); };" //"_root.note('buttonChilds:'+dumpObj(_root.buttonChild));" )); SWFMovieClip_nextFrame(ermc); } 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); /* Higher depth DisplayObject is intentionally added before lower depth one */ br = SWFButton_addCharacter(bu, (SWFCharacter)sh3a, SWFBUTTON_DOWN ); SWFButtonRecord_setDepth(br, 2); br = SWFButton_addCharacter(bu, (SWFCharacter)sh3, SWFBUTTON_DOWN ); SWFButtonRecord_setDepth(br, 1); /* Higher depth DisplayObject is intentionally added before lower depth one */ br = SWFButton_addCharacter(bu, (SWFCharacter)sh4a, SWFBUTTON_OVER ); SWFButtonRecord_setDepth(br, 2); br = SWFButton_addCharacter(bu, (SWFCharacter)sh4, SWFBUTTON_OVER ); SWFButtonRecord_setDepth(br, 1); /* Add events reported DisplayObject in all states at depth 10 */ br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_HIT|SWFBUTTON_DOWN|SWFBUTTON_OVER|SWFBUTTON_UP); SWFButtonRecord_setDepth(br, 10); /* Add events reported DisplayObject just HIT state at depth 11 */ br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_HIT); SWFButtonRecord_setDepth(br, 11); /* Add events reported DisplayObject just UP state at depth 12 */ br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_UP); SWFButtonRecord_setDepth(br, 12); /* Add events reported DisplayObject just OVER state at depth 13 */ br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_OVER); SWFButtonRecord_setDepth(br, 13); /* Add events reported DisplayObject just DOWN state at depth 14 */ br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_DOWN); SWFButtonRecord_setDepth(br, 14); SWFButton_addAction(bu, compileSWFActionCode( "_root.msg='MouseOut';" "if ( _root.testno == 4 || _root.testno == 9 || _root.testno == 14 ) {" " _root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');" /* Target of button action is the button's parent sprite */ " _root.check_equals(_target, '/square1');" " setTarget('/');" " _root.check_equals(_target, '/');" " _root.testno++;" " _root.note(_root.testno+'. Press mouse button inside the square, and release it outside.');" "} else {" //" _root.note('SWFBUTTON_MOUSEOUT');" " _root.xfail('Unexpectedly got SWFBUTTON_MOUSEOUT event (testno:'+_root.testno+')');" "}" ), SWFBUTTON_MOUSEOUT); SWFButton_addAction(bu, compileSWFActionCode( "_root.msg='MouseOver';" "if ( _root.testno == 1 ) {" /* ONLY CHECK buttonChild on first frame */ /* "_root.note('buttonChild is '+dumpObj(_root.buttonChild));" */ /* added OVER state char */ " _root.check_equals(_root.buttonChild.realLength(), 3);" /* OVER state char loaded */ " _root.check_equals(typeof(_root.buttonChild[13]), 'object');" " _root.check_equals(_root.buttonChild[13].nam, '_level0.square1.button.instance7');" " _root.check_equals(_root.buttonChild[13].exe, 1);" /* OVER state char */ " _root.check_equals(_root.buttonChild[13].uld, 0);" /* OVER state char */ /* UP state char unloaded */ " _root.check_equals(_root.buttonChild[12].exe, 1);" " _root.check_equals(_root.buttonChild[12].uld, 1);" " _root.check_equals(typeof(_level0.square1.button.instance6), 'movieclip');" " _root.check_equals(_level0.square1.button.instance6._name, 'instance6');" " _root.check_equals(_level0.square1.button.instance6.getDepth(), -16398);" /* ALL state char still there, not reloaded, not unloaded */ " _root.check_equals(_root.buttonChild[10].exe, 1);" " _root.check_equals(_root.buttonChild[10].uld, 0);" "}" "if ( _root.testno == 1 || _root.testno == 6 || _root.testno == 11 ) {" //" _root.note('buttonChild is '+dumpObj(_root.buttonChild));" " _root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');" /* Target of button action is the button's parent sprite */ " _root.check_equals(_target, '/square1');" " setTarget('/');" " _root.check_equals(_target, '/');" " _root.testno++;" " _root.note(_root.testno+'. Press (and keep pressed) the mouse button inside the square.');" "} else {" //" _root.note('SWFBUTTON_MOUSEOVER');" // need MOUSEOVER for MOUSEUPOUTSIDE " if ( _root.testno != 5 && _root.testno != 10 && _root.testno != 15 ) {" " _root.fail('Unexpectedly got SWFBUTTON_MOUSEOVER event (testno:'+_root.testno+')');" " }" "}" ), SWFBUTTON_MOUSEOVER); SWFButton_addAction(bu, compileSWFActionCode( "_root.msg='MouseDown';" "if ( _root.testno == 2 ) {" /* ONLY CHECK buttonChild on first frame */ /* Added DOWN state char */ " _root.check_equals(_root.buttonChild.realLength(), 4);" /* DOWN state char loaded */ " _root.check_equals(typeof(_root.buttonChild[14]), 'object');" " _root.check_equals(_root.buttonChild[14].nam, '_level0.square1.button.instance8');" " _root.check_equals(_root.buttonChild[14].exe, 1);" " _root.check_equals(_root.buttonChild[14].uld, 0);" /* OVER state char unloaded */ " _root.check_equals(_root.buttonChild[13].exe, 1);" " _root.check_equals(_root.buttonChild[13].uld, 1);" /* ALL state char still there, not reloaded, not unloaded */ " _root.check_equals(_root.buttonChild[10].exe, 1);" " _root.check_equals(_root.buttonChild[10].uld, 0);" "}" "if ( _root.testno == 2 || _root.testno == 7 || _root.testno == 12 ) {" " _root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');" /* Target (and name) of button action is the button's parent sprite */ " _root.check_equals(_target, '/square1');" " _root.check_equals(_name, 'square1');" " setTarget('/');" " _root.check_equals(_target, '/');" " _root.check_equals(typeof(_name), 'string');" " _root.check_equals(_name, '');" " _root.testno++;" " _root.note(_root.testno+'. Depress the mouse button inside the square.');" "} else {" //" _root.note('SWFBUTTON_MOUSEDOWN');" // need MOUSEDOWN for MOUSEUPOUTSIDE " if ( _root.testno != 5 && _root.testno != 10 && _root.testno != 15 ) {" " _root.fail('Unexpectedly got SWFBUTTON_MOUSEDOWN event (testno:'+_root.testno+')');" " }" "}" ), SWFBUTTON_MOUSEDOWN); SWFButton_addAction(bu, compileSWFActionCode( "_root.msg='MouseUp';" "if ( _root.testno == 3 || _root.testno == 8 || _root.testno == 13 ) {" " _root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');" /* Target of button action is the button's parent sprite */ " _root.check_equals(_target, '/square1');" " setTarget('/');" " _root.check_equals(_target, '/');" " _root.testno++;" " _root.note(_root.testno+'. Move the mouse pointer off the square.');" "} else {" //" _root.note('SWFBUTTON_MOUSEUP');" " _root.fail('Unexpectedly got SWFBUTTON_MOUSEUP event (testno:'+_root.testno+')');" "}" ), SWFBUTTON_MOUSEUP); /* SWFBUTTON_MOUSEUPOUTSIDE *should* be invoked !! */ SWFButton_addAction(bu, compileSWFActionCode( "_root.msg='MouseUpOutside';" "if ( _root.testno == 5 || _root.testno == 10 || _root.testno == 15 ) {" " _root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');" /* Target of button action is the button's parent sprite */ " _root.check_equals(_target, '/square1');" " _root.check_equals(_name, 'square1');" " setTarget('/');" " _root.check_equals(_target, '/');" " _root.nextFrame();" "} else {" //" _root.note('SWFBUTTON_MOUSEUPOUTSIDE');" " _root.fail('Unexpectedly got SWFBUTTON_MOUSEUPOUTSIDE event (testno:'+_root.testno+')');" "}" ), SWFBUTTON_MOUSEUPOUTSIDE); /* Keypress */ SWFButton_addAction(bu, compileSWFActionCode( "_root.note('KeyPress: a');" //"_root.check(Key.isDown('a'));" ), SWFBUTTON_KEYPRESS('a')); SWFButton_addAction(bu, compileSWFActionCode( "_root.note('KeyPress: b');" //"_root.check(Key.isDown('b'));" ), SWFBUTTON_KEYPRESS('b')); it = SWFMovieClip_add(mc, (SWFBlock)bu); SWFDisplayItem_setName(it, "button"); SWFMovieClip_nextFrame(mc); /* showFrame */ it = SWFMovie_add(mo, (SWFBlock)mc); return it; }
/// This test checks the event order of key events. // /// Known listeners are: /// 1. MovieClips with a defined key event /// 2. Button with a defined key event /// 3. Anything added to Key listeners in ActionScript. // /// The test adds objects in this order: // /// Frame 1: /// 1. mc1 /// 3. button1 (responds to 'a') /// 3. o1 (actionscript key listener object) /// 4. mc2 /// /// Frame 2: /// 5. button2 (responds to 'a') /// 6. button3 (responds to 'b') /// 3. o2 (actionscript key listener object) // /// The test shows that, irrespective of construction order: /// 1. MovieClips are notified first /// 2. ActionScript listeners are notified second. /// 3. Buttons are notified last. // /// Additionally: // /// 1. Only one button action can respond to any key. int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc, dejagnuclip; SWFButtonRecord br; SWFButton bu; SWFDisplayItem it1, it, 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(); 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); add_actions(mo, "_root.order = '';" "_root.note('Press \"a\" then \"b\"');" "_root.note('Do not press any other keys!');" ); mc = newSWFMovieClip(); it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setName(it, "mc1"); SWFDisplayItem_addAction(it, newSWFAction("trace('mc1'); _root.order += 'mc1,';"), SWFACTION_KEYDOWN); bu = newSWFButton(); sh1 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 0, 0); sh2 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 255, 0); br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT); SWFButtonRecord_setDepth(br, 3); br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP); SWFButtonRecord_setDepth(br, 4); br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER); SWFButtonRecord_setDepth(br, 5); SWFButton_addAction(bu, newSWFAction("trace('button1'); _root.order += 'button1,';"), SWFBUTTON_KEYPRESS('a')); it1 = SWFMovie_add(mo, (SWFBlock)bu); SWFDisplayItem_setName(it, "button1"); SWFMovie_add(mo, newSWFAction( "o1 = {};" "o1.onKeyDown = function() {" " trace('o1'); " " _root.order += 'o1,';" "};" "Key.addListener(o1);" )); mc = newSWFMovieClip(); it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_setName(it, "mc2"); SWFDisplayItem_addAction(it, newSWFAction("trace('mc2'); _root.order += 'mc2,';"), SWFACTION_KEYDOWN); SWFMovie_nextFrame(mo); // Frame 2 bu = newSWFButton(); sh1 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 0, 0); sh2 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 255, 0); br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT); SWFButtonRecord_setDepth(br, 3); br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP); SWFButtonRecord_setDepth(br, 4); br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER); SWFButtonRecord_setDepth(br, 5); SWFButton_addAction(bu, newSWFAction("trace('button2'); _root.order += 'button2,';"), SWFBUTTON_KEYPRESS('a')); it2 = SWFMovie_add(mo, (SWFBlock)bu); SWFDisplayItem_setName(it, "button2"); bu = newSWFButton(); sh1 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 0, 0); sh2 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 255, 0); br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT); SWFButtonRecord_setDepth(br, 3); br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP); SWFButtonRecord_setDepth(br, 4); br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER); SWFButtonRecord_setDepth(br, 5); SWFButton_addAction(bu, newSWFAction( "trace('button3'); " "_root.order += 'button3,';" "play();" ), SWFBUTTON_KEYPRESS('b')); it = SWFMovie_add(mo, (SWFBlock)bu); SWFDisplayItem_setName(it, "button3"); SWFMovie_add(mo, newSWFAction( "o2 = {};" "o2.onKeyDown = function() {" " trace('o2'); " " _root.order += 'o2,';" "};" "Key.addListener(o2);" "stop();" )); SWFMovie_nextFrame(mo); xcheck_equals(mo, "_root.order", "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'"); SWFMovie_nextFrame(mo); SWFDisplayItem_remove(it2); add_actions(mo, "_root.order = '';" "_root.note('Press \"a\" then \"b\" again');" "_root.note('Do not press any other keys!');" "stop();" ); SWFMovie_nextFrame(mo); // Check that removing the second button associated with 'a' does not // remove the key trigger for button2. There's no reason to think it should, // but it could happen if it's implemented badly! check_equals(mo, "_root.order", "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'"); SWFMovie_add(mo, newSWFAction("stop();")); //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 sh1,sh2; SWFAction ac; int i; 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) // 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); SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' unloaded');" "_root.mc1Unloaded++;" ), SWFACTION_UNLOAD); check_equals(mo, "typeof(movieClip1)", "'movieclip'"); check_equals(mo, "_root.mc1Constructed", "1"); SWFMovie_nextFrame(mo); // Frame3: Remove red square SWFDisplayItem_remove(it1); // After compile, the RemoveObject2 tag is *after* the DoAction tag which // contains the following check. So it's not surprise that we can still access // "movieClip1" here when considering the gloabal ActionQueue model! If the // RemoveObject2 is *before* the DoAction, then typeof(movieClip1) will reurn 'undefined'. // So Gnash fails here because of action execution order! // TODO: add testcase for this(RemoveObject2 placed *before* DoAction within the same frame). check_equals(mo, "typeof(movieClip1)", "'movieclip'"); // kept alive for calling onUnload! check_equals(mo, "_root.mc1Constructed", "1"); SWFMovie_nextFrame(mo); // Frame4: nothing new SWFMovie_nextFrame(mo); // Frame5: check, gotoAndStop(4), check.. check_equals(mo, "typeof(movieClip1)", "'undefined'"); SWFMovie_add(mo, (SWFBlock)newSWFAction( "gotoAndStop(4);")); check_equals(mo, "typeof(movieClip1)", "'movieclip'"); // onConstruct is called twice check_equals(mo, "_root.mc1Constructed", "2"); // this is due to action execution order, it's called twice, but // the second time it's called *after* the end of *this* DOACTION block .. check_equals(mo, "_root.mc1Unloaded", "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 dejagnuclip, staticSquare; SWFShape shape; SWFDisplayItem it; if ( argc>1 ) mediadir=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); if (mo == NULL) return -1; addRedSquareExport(mo); add_actions(mo, "_root.onKeyDown = _root.onMouseUp = function() {" "play(); }; " "Key.addListener(_root);"); SWFMovie_setRate(mo, 12); dejagnuclip = get_dejagnu_clip( (SWFBlock)get_default_font(mediadir), 10, 10, 150, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFMovie_nextFrame(mo); add_actions(mo, "BitmapData = flash.display.BitmapData;" "Rectangle = flash.geom.Rectangle;" "bmp = new BitmapData(150, 150, false);" "rect = new Rectangle(10, 10, 100, 100);" "bmp.fillRect(rect, 0x00ff00);" "mc = _root.createEmptyMovieClip('mc', getNextHighestDepth());" "d = mc.getNextHighestDepth();" "mc.attachBitmap(bmp, d);" "bmp2 = new BitmapData(20, 20, true);" "rect2 = new Rectangle (10, 10, 20, 20);" "bmp2.fillRect(rect2, 0xffffff00);" "d2 = mc.getNextHighestDepth();" "mc.attachBitmap(bmp2, d2);" "note('1. You should see a small yellow square in the top left " "corner of a larger green square. Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "rect = new Rectangle (90, 90, 120, 120);" "bmp.fillRect(rect, 0x0000FF);" "note('2. You should see a new blue square covering the " "bottom right corner of the large green square. Click" " to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "mc.createEmptyMovieClip('d', d);" "note('3. You should see just the small yellow square in the top " "left corner. Click to proceed.');"); add_actions(mo, "stop();"); SWFMovie_nextFrame(mo); // Place a dynamic DisplayObject at depth 4 add_actions(mo, "mc.removeMovieClip();" "_root.attachMovie('redsquare', 'rs', 4);"); // Place a static DisplayObject at depth 3 staticSquare = newSWFMovieClip(); shape = make_fill_square (300, 0, 60, 60, 255, 0, 255, 255, 0, 255); SWFMovieClip_add(staticSquare, (SWFBlock)shape); SWFMovieClip_nextFrame(staticSquare); it = SWFMovie_add(mo, (SWFBlock)staticSquare); SWFDisplayItem_setDepth(it, 3); SWFDisplayItem_setName(it, "staticSquare"); add_actions(mo, "note('4. You should see a red square in the top left and a " "purple square in the top right. Click to proceed.');"); add_actions(mo, "stop();"); SWFMovie_nextFrame(mo); add_actions(mo, "staticSquare.swapDepths(20);" "note('5. There should have been no change. Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "_root.attachBitmap(bmp, 2);" "note('6. You should see the green and blue squares " "under the red square. The purple square should still be there. " "Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "_root.attachBitmap(bmp, 3);" "note('7. There should have been no change. Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); SWFDisplayItem_remove(it); add_actions(mo, "_root.attachBitmap(bmp2, 20);" "note('8. The purple square should have gone. The small yellow " "square should have replaced the top left corner of the red " "square. The green and blue squares should still be there. " "Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "bmp.dispose(); bmp2.dispose();" "note('9. You should see just the red square. Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "bmp = new BitmapData(100, 100, false, 0x0000ff);" "note('10. There should have been no change. Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "bmp3 = new BitmapData(100, 100, false);" "rect3 = new Rectangle(20, 20, 90, 90);" "bmp3.fillRect(rect3, 0x0000ff);" "ch = _root.createEmptyMovieClip('original', 40);" "original.attachBitmap(bmp3, getNextHighestDepth());" "ch._name = 'duplicate';" "newch = _root.createEmptyMovieClip('original', " "getNextHighestDepth());" "note('11. You should see a large blue square only. " "Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "original.removeMovieClip();" "note('12. There should have been no change. Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "duplicate.removeMovieClip();" "note('13. You should see the red square again. Click to " "proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "_root.createEmptyMovieClip('mcLeft', getNextHighestDepth());" "mcLeft.duplicateMovieClip('mcMiddle', getNextHighestDepth()," " { _x: 300, _y: 0 } );" "mcLeft.attachBitmap(bmp3, getNextHighestDepth());" "mcMiddle.attachBitmap(bmp3, getNextHighestDepth());" "mcMiddle.duplicateMovieClip('mcRight', getNextHighestDepth()," " { _x: 600, _y: 0 } );" "note('14. You should see two blue squares. Click to proceed.');" "stop();" ); SWFMovie_nextFrame(mo); add_actions(mo, "bmp3.noise(293);" "note('15. You should see two noise patterns where the two " "squares were. Click to proceed.');" "stop();" ); add_actions(mo, "_root.onKeyDown = _root.onMouseUp = undefined;" "_root.eof = true;" // hook for test runner... "note(' - END OF TEST - thanks for flying with us ! ');" //"totals(6);" // no AS based tests... ); 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, mc3, dejagnuclip; SWFShape sh1, sh2, sh3; SWFDisplayItem it1, it2, it3; 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, 2); // Frame 1: Place dejagnu clip 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 two static DisplayObjects sh1 = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0); mc1 = newSWFMovieClip(); SWFMovieClip_add(mc1, (SWFBlock)sh1); SWFMovieClip_nextFrame(mc1); sh2 = make_fill_square (330, 270, 120, 120, 0, 0, 0, 0, 0, 0); mc2 = newSWFMovieClip(); SWFMovieClip_add(mc2, (SWFBlock)sh2); SWFMovieClip_nextFrame(mc2); sh3 = make_fill_square (330, 270, 120, 180, 0, 255, 0, 0, 255, 0); mc3 = newSWFMovieClip(); SWFMovieClip_add(mc3, (SWFBlock)sh3); SWFMovieClip_nextFrame(mc3); it1 = SWFMovie_add(mo, (SWFBlock)mc1); //add movieClip1 to the _root SWFDisplayItem_setName(it1, "movieClip1"); //name movieClip1 SWFDisplayItem_addAction(it1, newSWFAction( "_root.note(this+' constructed');" "_root.mc1Constructed++;" ), SWFACTION_CONSTRUCT); SWFDisplayItem_setDepth(it1, 3); // depth of movieClip1 is 3 (-16381) it2 = SWFMovie_add(mo, (SWFBlock)mc2); //add movieClip2 to the _root SWFDisplayItem_setName(it2, "movieClip2"); //name movieClip2 SWFDisplayItem_addAction(it2, newSWFAction( "_root.note(this+' constructed');" "_root.mc2Constructed++;"), SWFACTION_CONSTRUCT); SWFDisplayItem_setDepth(it2, 30000); // depth of movieClip2 is 30000 (13616) it3 = SWFMovie_add(mo, (SWFBlock)mc3); //add movieClip3 to the _root SWFDisplayItem_setName(it3, "movieClip3"); //name movieClip3 SWFDisplayItem_addAction(it3, newSWFAction( "_root.note(this+' constructed');" "_root.mc3Constructed++;"), SWFACTION_CONSTRUCT); SWFDisplayItem_setDepth(it3, 30001); // depth of movieClip3 is 30001 (13617) SWFMovie_add(mo, (SWFBlock)newSWFAction( "check_equals(movieClip3.getDepth(), 13617);" )); SWFMovie_nextFrame(mo); // Frame4: RemoveObject(mc3) - one of those out of static depth zone SWFDisplayItem_remove(it3); // Frame4: gotoAndStop(1), check.. SWFMovie_add(mo, (SWFBlock)newSWFAction( "var mc1_depth = movieClip1.getDepth();" "var mc2_depth = movieClip2.getDepth();" "movieClip1.secretCode = 'mc1';" "movieClip2.secretCode = 'mc2';" "check_equals(movieClip1.getDepth(), -16381);" "check_equals(movieClip2.getDepth(), 13616);" // movieClip3 was removed, despite it's depth is out of the static zone "check_equals(typeof(movieClip3), 'undefined');" "gotoAndStop(1);" // MC1 (in static depth zone) has been removed "check_equals(typeof(movieClip1), 'undefined');" // MC2 (in dynamic depth zone) has been kept "check_equals(typeof(movieClip2), 'movieclip');" // The kept instance wasn't detroyed "check_equals(movieClip2.secretCode, 'mc2');" // Both chars have been constructed once (consistency check) "check_equals(mc1Constructed, 1);" "check_equals(mc2Constructed, 1);" "totals(9);" )); SWFMovie_nextFrame(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }