void addSoundExport(SWFMovie mo) { SWFSound soundMP3a; SWFSound soundMP3b; SWFSound soundMP3c; SWFSound soundMP3d; FILE* f; FILE* f2; f = fopen(MEDIADIR"/mono44.mp2", "r"); if (!f) { perror(MEDIADIR"/mono44.mp2"); exit(EXIT_FAILURE); } soundMP3a = newSWFSound(f, SWF_SOUND_MP3_COMPRESSED | SWF_SOUND_44KHZ | SWF_SOUND_16BITS | SWF_SOUND_MONO); soundMP3b = newSWFSound(f, SWF_SOUND_MP3_COMPRESSED | SWF_SOUND_22KHZ | SWF_SOUND_16BITS | SWF_SOUND_STEREO); f2 = fopen(MEDIADIR"/stereo8.mp3", "r"); if (f2 == NULL) { perror(MEDIADIR"/stereo8.mp3"); exit(EXIT_FAILURE); } soundMP3c = newSWFSound(f2, SWF_SOUND_MP3_COMPRESSED | SWF_SOUND_44KHZ | SWF_SOUND_16BITS | SWF_SOUND_MONO); soundMP3d = newSWFSound(f2, SWF_SOUND_MP3_COMPRESSED | SWF_SOUND_5KHZ | SWF_SOUND_16BITS | SWF_SOUND_STEREO); SWFMovie_addExport(mo, (SWFBlock)soundMP3a, "mono22_mp2"); SWFMovie_addExport(mo, (SWFBlock)soundMP3b, "mono22_mp2b"); SWFMovie_addExport(mo, (SWFBlock)soundMP3c, "stereo8_mp3"); SWFMovie_addExport(mo, (SWFBlock)soundMP3d, "stereo8_mp3b"); SWFMovie_writeExports(mo); }
int main() { SWFMovie m = newSWFMovieWithVersion(8); SWFDBLBitmapData img = newSWFDBLBitmapData_fromPngFile(MEDIADIR "/image01.png"); if(img == NULL) return EXIT_FAILURE; SWFMovie_addExport(m, (SWFBlock)img, "BitmapExport"); SWFMovie_writeExports(m); SWFMovie_save(m, "test01.swf"); return 0; }
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); }
int main(int argc, char* argv[]) { SWFMovie mo; SWFMovieClip mc1, mc2, mc3, mc4, dejagnuclip; SWFDisplayItem it; SWFAction ac; SWFInitAction initac; const char *srcdir="."; if (argc > 1) srcdir = argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); add_actions(mo, "if (!_global.hasOwnProperty('arr')) { _global.arr = []; };" "_global.ch = function(a, b) {" " trace(a);" " if (typeof(b)=='undefined' || (typeof(b)=='boolean' && b)) {" " _global.arr.push(a);" " };" "};" "this.onEnterFrame = function() { " " _global.ch('onEnterFrame', false);" "};" ); SWFMovie_nextFrame(mo); // MovieClip 1 mc1 = newSWFMovieClip(); // 1 frames // SWF_EXPORTASSETS SWFMovie_addExport(mo, (SWFBlock)mc1, "Segments_Name"); SWFMovie_writeExports(mo); // MovieClip mc3 has two frames. In each frame a different MovieClip // is placed with the name Segments. mc3 = newSWFMovieClip(); // 2 frames // MovieClip 2 mc2 = newSWFMovieClip(); // 1 frames // Add mc2 it = SWFMovieClip_add(mc3, (SWFBlock)mc2); SWFDisplayItem_setDepth(it, 1); SWFDisplayItem_setName(it, "Segments"); // Frame 2 SWFMovieClip_nextFrame(mc3); // Remove mc2 SWFDisplayItem_remove(it); // Add mc1 it = SWFMovieClip_add(mc3, (SWFBlock)mc1); SWFDisplayItem_setDepth(it, 1); SWFDisplayItem_setName(it, "Segments"); SWFMovieClip_nextFrame(mc3); // End mc3 // This is frame 1 of the main timeline // Put our sprite mc3 on stage. it = SWFMovie_add(mo, (SWFBlock)mc3); SWFDisplayItem_setDepth(it, 1); SWFDisplayItem_setName(it, "mc"); // mc4 is just for executing init actions. mc4 = newSWFMovieClip(); SWFMovie_addExport(mo, (SWFBlock)mc4, "__Packages.Bug"); SWFMovie_writeExports(mo); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); ac = newSWFAction( "_global.loops = 0;" "_global.c = 0;" "if( !_global.Bug ) {" " _global.Bug = function () {" " this.onUnload = function() { " " _global.ch('dynamic unload: ' + this.c);" " }; " " this.onLoad = function() { " " _global.ch('dynamic load: ' + this.c);" " }; " " this.c = _global.c;" " _global.ch('ctor: ' + _global.c);" " _global.c++;" " };" "};" ); initac = newSWFInitAction_withId(ac, 4); SWFMovie_add(mo, (SWFBlock)initac); ac = newSWFAction("Object.registerClass('Segments_Name',Bug);"); initac = newSWFInitAction_withId(ac, 1); SWFMovie_add(mo, (SWFBlock)initac); add_actions(mo, "_global.ch('Frame ' + " "_level0._currentframe + ' actions: ' " "+ _level0.mc.Segments.c);"); // Frame 2 of the main timeline SWFMovie_nextFrame(mo); add_actions(mo, "_global.ch('Frame ' + " "_level0._currentframe + ' actions: ' " "+ _level0.mc.Segments.c);"); add_actions(mo, " if (_global.loops < 5) {" " _global.loops++;" " gotoAndPlay(2);" " }" " else {" " delete this.onEnterFrame;" " gotoAndPlay(4);" " };" ); SWFMovie_nextFrame(mo); check_equals(mo, "_global.arr.length", "20"); check_equals(mo, "_global.arr[0]", "'Frame 2 actions: undefined'"); check_equals(mo, "_global.arr[1]", "'ctor: 0'"); xcheck_equals(mo, "_global.arr[2]", "'Frame 3 actions: 0'"); xcheck_equals(mo, "_global.arr[3]", "'dynamic load: 0'"); check_equals(mo, "_global.arr[4]", "'Frame 2 actions: 0'"); check_equals(mo, "_global.arr[5]", "'Frame 3 actions: 0'"); check_equals(mo, "_global.arr[6]", "'Frame 2 actions: 0'"); check_equals(mo, "_global.arr[7]", "'ctor: 1'"); check_equals(mo, "_global.arr[8]", "'dynamic unload: 0'"); xcheck_equals(mo, "_global.arr[9]", "'Frame 3 actions: 0'"); check_equals(mo, "_global.arr[11]", "'Frame 2 actions: 0'"); check_equals(mo, "_global.arr[12]", "'Frame 3 actions: 1'"); check_equals(mo, "_global.arr[13]", "'Frame 2 actions: 1'"); check_equals(mo, "_global.arr[14]", "'ctor: 2'"); check_equals(mo, "_global.arr[15]", "'dynamic unload: 1'"); xcheck_equals(mo, "_global.arr[16]", "'Frame 3 actions: 1'"); xcheck_equals(mo, "_global.arr[17]", "'dynamic load: 2'"); check_equals(mo, "_global.arr[18]", "'Frame 2 actions: 1'"); check_equals(mo, "_global.arr[19]", "'Frame 3 actions: 2'"); xcheck_equals(mo, "_global.arr.toString()", "'Frame 2 actions: undefined,ctor: 0,Frame 3 actions: 0,dynamic load: 0,Frame 2 actions: 0,Frame 3 actions: 0,Frame 2 actions: 0,ctor: 1,dynamic unload: 0,Frame 3 actions: 0,dynamic load: 1,Frame 2 actions: 0,Frame 3 actions: 1,Frame 2 actions: 1,ctor: 2,dynamic unload: 1,Frame 3 actions: 1,dynamic load: 2,Frame 2 actions: 1,Frame 3 actions: 2'"); SWFMovie_nextFrame(mo); add_actions(mo, "totals(21); stop();"); SWFMovie_nextFrame(mo); // SWF_END SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFSound so; const char* soundFile; const char* srcdir; int frame; if (argc > 1) { soundFile = argv[1]; } else { soundFile = "brokenchord.wav"; } if (argc > 2) { srcdir = argv[2]; } else { srcdir = "."; } /* setup ming and basic movie properties */ Ming_init(); Ming_useSWFVersion(OUTPUT_VERSION); mo = newSWFMovie(); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate(mo, 0.5); setupMovie(mo, srcdir); so = setupSounds(soundFile); /// Add as an export so we can attach it. SWFMovie_addExport(mo, (SWFBlock)so, "es"); SWFMovie_writeExports(mo); add_actions(mo, "c = 0;"); SWFMovie_nextFrame(mo); add_actions(mo, "note('You will hear several short tests with a succession of sounds. " "Each frame is two seconds long.\n" "The movie will describe what you should hear at the beginning of " "the frame.');"); frame = 0; pauseForNextTest(mo); runMultipleSoundsTest(mo, so, &frame); pauseForNextTest(mo); runNoMultipleSoundsTest(mo, so, &frame); pauseForNextTest(mo); runTrimmedSoundsTest(mo, so, &frame); pauseForNextTest(mo); runAttachedSoundsTest(mo, so, &frame); // TODO: test start(<sec_offset>) (+ with loop ?) endOfTests(mo); //Output movie puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
int main(int argc, char** argv) { SWFMovie mo; SWFMovieClip mc3, mc2, dejagnuclip; SWFAction ac, ac1, initac; SWFDisplayItem it; SWFShape sha; const char *srcdir="."; if (argc > 1) srcdir = argv[1]; else { fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]); return 1; } Ming_init(); mo = newSWFMovieWithVersion(OUTPUT_VERSION); SWFMovie_setDimension(mo, 800, 600); SWFMovie_setRate (mo, 12.0); sha = newSWFShape(); // Character ID 2. Has 1 showframe. Is exported first. mc2 = newSWFMovieClip(); SWFMovieClip_add(mc2, (SWFBlock)sha); SWFMovieClip_nextFrame(mc2); // Export it. SWFMovie_addExport(mo, (SWFBlock)mc2, "C2"); SWFMovie_writeExports(mo); // Main timeline actions for frame 1 add_actions(mo, "var c = 0; var i = 0; trace('frame 1'); gotoAndStop(3);"); initac = newSWFAction("trace('onInitialize'); _root.i++;"); // ID 3 is defined here. It has no showframe. It is exported immediately. mc3 = newSWFMovieClip(); SWFMovie_addExport(mo, (SWFBlock)mc3, "ctor"); SWFMovie_writeExports(mo); dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600); SWFMovie_add(mo, (SWFBlock)dejagnuclip); // Init actions for ID 3. This only exists to create the constructor // for mc2 in its initactions. ac = newSWFAction( " _global.ctor = function () {" " super();" " trace('Object ID 2 is constructed');" " c += 1;" " };" ); SWFInitAction ia = newSWFInitAction_withId(ac, 3); SWFMovie_add(mo, (SWFBlock)ia); // Init actions for ID 2 (registered class) ac1 = newSWFAction("Object.registerClass('C2', ctor); " "trace('Registered class');"); ia = newSWFInitAction_withId(ac1, 2); SWFMovie_add(mo, (SWFBlock)ia); // Frame 2 SWFMovie_nextFrame(mo); add_actions(mo, "trace('Frame 2');"); // Place object ID 2. it = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setName(it, "mc2"); SWFDisplayItem_addAction(it, initac, SWFACTION_INIT); // Frame 3 SWFMovie_nextFrame(mo); // Remove object ID 2 SWFMovie_remove(mo, it); add_actions(mo, "trace('frame 3');"); // The class should not be constructed if the object is removed after // being placed. It should be constructed if it's not removed. MovieClips // with an onUnload handler are always constructed. check_equals(mo, "c", "0"); check_equals(mo, "i", "0"); check(mo, "_root.mc2 == undefined"); add_actions(mo, "gotoAndPlay(5);"); // Frame 4 SWFMovie_nextFrame(mo); add_actions(mo, "trace('Frame 4');"); // Place object ID 2 again it = SWFMovie_add(mo, (SWFBlock)mc2); SWFDisplayItem_setName(it, "mc2a"); SWFDisplayItem_addAction(it, initac, SWFACTION_INIT); // Frame 5 SWFMovie_nextFrame(mo); // This time the MovieClip was not removed before we get here, // so it should be present and the constructor should be // called. add_actions(mo, "trace('frame 5');"); check_equals(mo, "c", "1"); check_equals(mo, "i", "1"); check(mo, "typeof(_root.mc2a) == 'movieclip'"); add_actions(mo, "stop();"); SWFMovie_nextFrame(mo); puts("Saving " OUTPUT_FILENAME ); SWFMovie_save(mo, OUTPUT_FILENAME); return 0; }
SWFOutput SWFMovie_toOutput(SWFMovie movie, int level) { int swflength; #if USE_ZLIB int status; #endif SWFOutput header, tempbuffer=0, buffer, swfbuffer; SWFBlock lastBlock; unsigned long compresslength; if ( movie->nExports > 0 ) SWFMovie_writeExports(movie); if ( movie->metadata != NULL) { SWFMovie_addBlock(movie, (SWFBlock)movie->metadata); movie->metadata = NULL; // do not destroy with movie if added as block } /* Add a terminating SHOWFRAME tag if not already there */ lastBlock = SWFBlockList_getLastBlock(movie->blockList); if ( ! lastBlock || SWFBlock_getType(lastBlock) != SWF_SHOWFRAME ) { SWFMovie_nextFrame(movie); } while ( movie->nFrames < movie->totalFrames ) SWFMovie_nextFrame(movie); if(movie->symbolClass) SWFMovie_addBlock(movie, (SWFBlock)movie->symbolClass); if(movie->sceneData) SWFMovie_addBlock(movie, (SWFBlock)movie->sceneData); SWFMovie_addBlock(movie, newSWFEndBlock()); // add five for the setbackground block.. swflength = SWFBlockList_completeBlocks(movie->blockList, movie->version); /* XXX - hack */ SWFDisplayList_rewindSoundStream(movie->displayList); header = newSizedSWFOutput(23); SWFOutput_writeRect(header, movie->bounds); SWFOutput_writeUInt16(header, (int)floor(movie->rate*256)); SWFOutput_writeUInt16(header, movie->nFrames); /* SWF >= 8: first block _must_ be SWF_FILEATTRIBUTES */ if(movie->fattrs) writeSWFBlockToMethod((SWFBlock)movie->fattrs, SWFOutputMethod, header); if(movie->backgroundBlock) writeSWFBlockToMethod(movie->backgroundBlock, SWFOutputMethod, header); if(movie->limits) writeSWFBlockToMethod((SWFBlock)movie->limits, SWFOutputMethod, header); SWFOutput_byteAlign(header); swflength += 8 + SWFOutput_getLength(header); // compression level check #if USE_ZLIB if (level < -1) level = -1; if (level > 9) level = 9; #else if ( level != -1 ) { SWF_warn("No zlib support compiled in, " "cannot generate compressed output"); level = -1; } #endif // reserve output buffer if(level >= 0) { // a little bit more than the uncompressed data compresslength = swflength + (swflength/1000) + 15 + 1; swfbuffer = newSizedSWFOutput( compresslength + 8 ); } else swfbuffer = newSizedSWFOutput( swflength ); if (level >= 0) SWFOutput_writeUInt8 (swfbuffer, 'C'); else SWFOutput_writeUInt8 (swfbuffer, 'F'); SWFOutput_writeUInt8 (swfbuffer, 'W'); SWFOutput_writeUInt8 (swfbuffer, 'S'); SWFOutput_writeUInt8 (swfbuffer, movie->version); // Movie length SWFOutput_writeUInt32(swfbuffer, swflength); if(level >= 0) buffer = tempbuffer = newSizedSWFOutput( swflength - 8); else buffer = swfbuffer; SWFOutput_writeToMethod(header, SWFOutputMethod, buffer); destroySWFOutput(header); // fill swfbuffer with blocklist SWFBlockList_writeBlocksToMethod(movie->blockList, SWFOutputMethod, buffer); #if USE_ZLIB if (level >= 0) { status = compress2 ( (Bytef*) SWFOutput_getBuffer(swfbuffer)+8, &compresslength, SWFOutput_getBuffer(tempbuffer), SWFOutput_getLength(tempbuffer), level); if (status == Z_OK) { SWFOutput_truncate(swfbuffer, compresslength+8); destroySWFOutput(tempbuffer); } else SWF_error("compression failed"); } #endif // ndef USE_ZLIB return swfbuffer; }
EXPORT BOOL WINAPI m_writeExports(int p1, int p2, int p3, int p4) { lstrcpy(funcname, "m_writeExports"); SWFMovie_writeExports(mhsp_movie); return 0; }