EXPORT BOOL WINAPI mhsp_SWFButton(SWFButton *p1, int p2, int p3, int p4) { lstrcpy(funcname, "SWFButton"); *p1 = newSWFButton(); if (!mhsp_button) { mhsp_button = *p1; } return 0; }
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; }
int main() { SWFMovie m; SWFShape shape; SWFButton b; SWFDisplayItem item; SWFBlur blur; SWFFilter f; SWFShadow shadow; SWFColor c1, c2; Ming_init(); m = newSWFMovieWithVersion(7); if(m == NULL) return EXIT_FAILURE; shape = newSWFShape(); SWFShape_setLine(shape, 4, 25, 0, 0, 128); SWFShape_movePenTo(shape, 5, 5); SWFShape_drawLineTo(shape, 0, 10); blur = newSWFBlur(5,5,2); shadow = newSWFShadow(0.79, 5, 1.0); c1.red = 0; c1.green = 0; c1.blue = 0; c1.alpha = 0xff; c2.red = 0xff; c2.green = 0xff; c2.blue = 0xff; c2.alpha = 0xff; f = newBevelFilter(c1, c2, blur, shadow, FILTER_MODE_INNER | FILTER_MODE_KO); b = newSWFButton(); SWFButton_addCharacter(b, (SWFCharacter)shape, SWFBUTTON_UP | SWFBUTTON_HIT | SWFBUTTON_OVER | SWFBUTTON_DOWN); item = SWFMovie_add(m, (SWFBlock)b); SWFDisplayItem_addFilter(item, f); SWFMovie_save(m, "test04.swf"); 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; }
void SWF_addPlayerControls(double *x, double *y){ //Get the device info by pointer since this can be called from R pDevDesc deviceInfo = GEcurrentDevice()->dev; // Shortcut pointers to variables of interest. swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific; // General variables SWFDisplayItem playd; SWFDisplayItem stopd; // Fill styles we create SWFFillStyle dark_blue_fill; SWFFillStyle red_fill; SWFFillStyle green_fill; // Variables used for the play button SWFAction play_action; SWFButton play_button; SWFButtonRecord play_record_down; SWFButtonRecord play_record_up; SWFShape play_shape_down; SWFShape play_shape_up; // Variables used for the stop button SWFAction stop_action; SWFButton stop_button; SWFButtonRecord stop_record_down; SWFButtonRecord stop_record_up; SWFShape stop_shape_down; SWFShape stop_shape_up; if(swfInfo->haveControls == FALSE){ swfInfo->haveControls = TRUE; // Ensure the movie starts out in the "stopped" state SWFMovie_add(swfInfo->m, (SWFBlock) newSWFAction("_root.stop();")); } swfInfo->ControlsX = *x; swfInfo->ControlsY = deviceInfo->top - *y; // Create the fill styles we'll be using red_fill = newSWFSolidFillStyle(0xf0, 0x00, 0x00, 0x99); dark_blue_fill = newSWFSolidFillStyle(0x00, 0x00, 0x90, 0x99); green_fill = newSWFSolidFillStyle(0x00, 0xcc, 0x00, 0x99); // *** Create the Play button *** // Create a shape to be used in the play button for its "UP" state play_shape_up = newSWFShape(); // Use the dark blue fill SWFShape_setRightFillStyle(play_shape_up, green_fill); SWFShape_setLine(play_shape_up, 1, 0x00, 0x00, 0x00, 0xff); SWFShape_movePenTo(play_shape_up, swfInfo->ControlsX-25, swfInfo->ControlsY); SWFShape_drawLine(play_shape_up, 20, 15); SWFShape_drawLine(play_shape_up, -20, 15); SWFShape_drawLine(play_shape_up, 0, -30); // Create a shape to be used in the play button for its "DOWN" state play_shape_down = newSWFShape(); // Use the green fill SWFShape_setRightFillStyle(play_shape_down, dark_blue_fill); SWFShape_setLine(play_shape_down, 1, 0x00, 0x00, 0x00, 0xff); SWFShape_movePenTo(play_shape_down, swfInfo->ControlsX-25, swfInfo->ControlsY); SWFShape_drawLine(play_shape_down, 20, 15); SWFShape_drawLine(play_shape_down, -20, 15); SWFShape_drawLine(play_shape_down, 0, -30); // Create an empty button object we can use play_button = newSWFButton(); // Add the shapes to the button for its various states play_record_up = SWFButton_addCharacter(play_button, (SWFCharacter) play_shape_up, SWFBUTTON_UP|SWFBUTTON_HIT|SWFBUTTON_OVER); play_record_down = SWFButton_addCharacter(play_button, (SWFCharacter) play_shape_down, SWFBUTTON_DOWN); // Add the Play action to the play button play_action = newSWFAction("_root.play();"); SWFButton_addAction(play_button, play_action, SWFBUTTON_MOUSEUP); // *** Create the Stop button *** // Create a shape to be used in the stop button for its "UP" state stop_shape_up = newSWFShape(); // Use the green fill SWFShape_setRightFillStyle(stop_shape_up, red_fill); SWFShape_setLine(stop_shape_up, 1, 0x00, 0x00, 0x00, 0xff); SWFShape_movePenTo(stop_shape_up, swfInfo->ControlsX , swfInfo->ControlsY + 2.5); SWFShape_drawLine(stop_shape_up, 25, 0); SWFShape_drawLine(stop_shape_up, 0, 25); SWFShape_drawLine(stop_shape_up, -25, 0); SWFShape_drawLine(stop_shape_up, 0, -25); // Create a shape to be used in the stop button for its "DOWN" state stop_shape_down = newSWFShape(); // Use the dark blue fill SWFShape_setRightFillStyle(stop_shape_down, dark_blue_fill); SWFShape_setLine(stop_shape_down, 1, 0x00, 0x00, 0x00, 0xff); SWFShape_movePenTo(stop_shape_down, swfInfo->ControlsX , swfInfo->ControlsY + 2.5); SWFShape_drawLine(stop_shape_down, 25, 0); SWFShape_drawLine(stop_shape_down, 0, 25); SWFShape_drawLine(stop_shape_down, -25, 0); SWFShape_drawLine(stop_shape_down, 0, -25); // Create an empty button object we can use stop_button = newSWFButton(); // Add the shapes to the button for its various states stop_record_up = SWFButton_addCharacter(stop_button, (SWFCharacter) stop_shape_up, SWFBUTTON_UP | SWFBUTTON_HIT | SWFBUTTON_OVER); stop_record_down = SWFButton_addCharacter(stop_button, (SWFCharacter) stop_shape_down, SWFBUTTON_DOWN); // Add the Stop action to the stop button stop_action = newSWFAction("_root.stop();"); SWFButton_addAction(stop_button, stop_action, SWFBUTTON_MOUSEUP); // *** Create the movie clip container for the buttons *** // Embed the buttons in a movie clip //movie_clip = newSWFMovieClip(); playd = SWFMovie_add(swfInfo->m, (SWFBlock) play_button); stopd = SWFMovie_add(swfInfo->m, (SWFBlock) stop_button); addToDisplayList( playd ); addToDisplayList( stopd ); // Advance the movie clip one frame, else it doesn't get displayed //SWFMovieClip_nextFrame(movie_clip); // Add the movie clip to the main movie //buttons_display_item = SWFMovie_add(swfInfo->m, movie_clip); //addToDisplayList( buttons_display_item ); // Set the movie clip to be shown higher // in the display stack than the main movie //SWFDisplayItem_setDepth(buttons_display_item, 100); }
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; }