Пример #1
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip  mc, dejagnuclip;

  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); /* 1st frame */

  mc = newSWFMovieClip();
  add_clip_actions(mc, "_root.x = 1;"
                       "_root.check_equals(_root.x, 1);");
  SWFMovieClip_nextFrame(mc);
 
 
  add_actions(mo, " gotoAndPlay(4); ");
  SWFMovie_nextFrame(mo); /* 2nd frame */
  
  SWFMovie_nextFrame(mo); /* 3rd frame */
  
   
  /* add mc to _root and name it as "mc" */
  SWFDisplayItem it;
  it = SWFMovie_add(mo, (SWFBlock)mc);  
  SWFDisplayItem_setDepth(it, 3); 
  SWFDisplayItem_setName(it, "mc"); 
  add_actions(mo, " _root.x = 2; "
                  " _root.check_equals(_root.x, 2); ");
  SWFMovie_nextFrame(mo); /* 4th frame */

	SWFDisplayItem_remove(it);
  check_equals(mo, "_root.x", "1");
  check_equals(mo, "typeof(mc)", "'undefined'");
  add_actions(mo, " _root.totals(); stop(); ");
  SWFMovie_nextFrame(mo); /* 5th frame */

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #2
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip   dejagnuclip;

  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 1.0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo);  // frame1
  
  // get current time in frame2
  add_actions(mo, "x1 = getTimer();");
  SWFMovie_nextFrame(mo); // frame2

  // just delay some time here
  add_actions(mo, " for(i=0; i<1000; i++) {} ");
  // get current time in frame3 
  add_actions(mo, "x2 = getTimer();");
  SWFMovie_nextFrame(mo); // frame3

  // check that the timer is working
  check(mo, "x1 > 0");
  check(mo, "x2 > x1" );
  // this is dependent on frame rate(current setting is 1 second per frame)
  // check(mo, "x2 > 1000");
  check(mo, "x2 < 6000");
  // check that "getTimer" return a intergral number
  check(mo, "x2 == Math.ceil(x2)");
  check(mo, "x2 == Math.floor(x2)");
  SWFMovie_nextFrame(mo); // frame4        

  add_actions(mo, "_root.totals(); stop();");
  SWFMovie_nextFrame(mo); // frame5       
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #3
0
int main(int argc, char** argv)
{
  SWFMovie  movie;
  SWFMovieClip dejagnuclip;
  SWFAction ac[FRAME_COUNT];
  int i;
  const char *srcdir=".";

  if ( argc>1 ) srcdir=argv[1];
  else
  {
    fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
    return 1;
  }

  Ming_init();
  movie = newSWFMovie();
  SWFMovie_setDimension(movie, 800, 600);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(movie, (SWFBlock)dejagnuclip);

  // Add frame ActionScipts to frames
  ac[0] = action_in_frame1();
  ac[1] = action_in_frame2();
  ac[2] = action_in_frame3();
  ac[3] = action_in_frame4();
  
  for(i=0; i<FRAME_COUNT; i++)
  {
    SWFMovie_add(movie, (SWFBlock)ac[i]);
    SWFMovie_nextFrame(movie); 
  }
  
  // save files
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(movie, OUTPUT_FILENAME);

  return 0;
}
Пример #4
0
void setupMovie(SWFMovie mo, const char* srcdir)
{
  SWFDisplayItem it;
  char fdbfont[256];
  SWFFont font;
  SWFMovieClip dejagnuclip;
  FILE* font_file;
  
  sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
  font_file = fopen(fdbfont, "r");
  if (font_file == NULL)
  {
    perror(fdbfont);
    exit(1);
  }

  font = loadSWFFontFromFile(font_file);

  /* Add output textfield and DejaGnu stuff */
  dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 800, 800);
  it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFDisplayItem_setDepth(it, 200); 

}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	const char *srcdir=".";
	SWFMovieClip  dejagnuclip;


	/*********************************************
	 *
	 * Initialization
	 *
	 *********************************************/

	if ( argc>1 ) srcdir=argv[1];
	else
	{
		fprintf(stderr, "Usage: %s\n", argv[0]);
		return 1;
	}

	puts("Setting things up");

	Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* let's talk pixels */
 
	mo = newSWFMovie();
	SWFMovie_setRate(mo, 12);
	SWFMovie_setDimension(mo, 640, 400);

	/*********************************************
	 *
	 * Body
	 *
	 *********************************************/

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
	SWFMovie_add(mo, (SWFBlock)dejagnuclip);
	addRedSquareExport(mo);
	/* it seems we need a SHOWFRAME for this to be effective */
	/* (maybe it's related to loop-back handling ?) */
	SWFMovie_nextFrame(mo);  /* end of frame1 */

	add_actions(mo, "counter = 1; onLoadCalled = new Array();");

	add_actions(mo,
		"var name1 = 'square'+counter;"
		"attachMovie('redsquare', name1, 70+counter);"
		"var clip1 = this[name1];"
		"counter++;"
		);

	SWFMovie_nextFrame(mo); /* end of frame2 */

	add_actions(mo,
		"function CustomClass() { this._x = 80; }"
		"CustomClass.prototype.onLoad = function() { note(this+'.onLoad called'); _root.onLoadCalled.push(this); };"
		"registerClassRet = Object.registerClass('redsquare', CustomClass);"
		);

	check_equals(mo, "typeof(registerClassRet)", "'boolean'");
	check_equals(mo, "registerClassRet", "true");

	add_actions(mo,
		"var name2 = 'square'+counter;"
		"attachMovie('redsquare', name2, 70+counter);"
		"var clip2 = this[name2];"
		"counter++;"
		);


	SWFMovie_nextFrame(mo); /* end of frame3 */

	add_actions(mo,
		"function CustomClass2() { this._x = 160; check_equals(typeof(super.lineTo), 'function'); }"
		"CustomClass2.prototype = new MovieClip;"
		"registerClassRet = Object.registerClass('redsquare', CustomClass2);"
		);

	check_equals(mo, "_root.onLoadCalled.length", "1");
	check_equals(mo, "_root.onLoadCalled[0]", "_level0.square2");
	check_equals(mo, "typeof(registerClassRet)", "'boolean'");
	check_equals(mo, "registerClassRet", "true");

	add_actions(mo,
		"var name3 = 'square'+counter;"
		"attachMovie('redsquare', name3, 70+counter);"
		"var clip3 = this[name3];"
		"counter++;"
		);

	SWFMovie_nextFrame(mo); /* end of frame4 */

	add_actions(mo,
		"registerClassRet = Object.registerClass('redsquare');"
		);

	check_equals(mo, "typeof(registerClassRet)", "'boolean'");
	check_equals(mo, "registerClassRet", "false");

	add_actions(mo,
		"var name4 = 'square'+counter;"
		"attachMovie('redsquare', name4, 70+counter);"
		"var clip4 = this[name4];"
		"clip4._x = 240;"
		"counter++;"
		);

	SWFMovie_nextFrame(mo); /* end of frame5 */

	check_equals(mo, "typeof(clip1)", "'movieclip'");
	check(mo, "clip1 instanceOf MovieClip");
	check_equals(mo, "clip1._x", "0");
	check(mo, "! clip1 instanceOf CustomClass");
	
	// Check that non-enumerable properties (unnamed instances,
	// constructor, __constructor__) are not enumerated.
	add_actions(mo, "var s = ''; for (i in clip1) { s += i + ','; };");
	check_equals(mo, "s", "'onRollOver,'");

	check_equals(mo, "typeof(clip2)", "'movieclip'");
	check(mo, "clip2 instanceOf CustomClass");
	check(mo, "clip2.hasOwnProperty('__constructor__')");
	check(mo, "clip2.hasOwnProperty('constructor')");
	check(mo, "clip2.hasOwnProperty('__proto__')");
	check_equals(mo, "clip2.__proto__", "CustomClass.prototype");
	check_equals(mo, "clip2.__constructor__", "CustomClass");
	check_equals(mo, "clip2.constructor", "CustomClass");
	check_equals(mo, "clip2._x", "80");
	check_equals(mo, "typeof(clip2.lineTo)", "'undefined'");
	check(mo, "! clip2 instanceOf MovieClip");
	
	// Check that non-enumerable properties (unnamed instances,
	// constructor, __constructor__) are not enumerated.
	add_actions(mo, "var s = ''; for (i in clip2) { s += i + ','; };");
	check_equals(mo, "s", "'onLoad,onRollOver,'");

	check(mo, "clip3.hasOwnProperty('__constructor__')");
	check(mo, "clip3.hasOwnProperty('constructor')");
	check(mo, "clip3.hasOwnProperty('__proto__')");
	check_equals(mo, "clip3.__proto__", "CustomClass2.prototype");
	check_equals(mo, "clip3.__constructor__", "CustomClass2");
	check_equals(mo, "clip3.constructor", "CustomClass2");
	check_equals(mo, "typeof(clip3)", "'movieclip'");
	check_equals(mo, "clip3._x", "160");
	check(mo, "clip3 instanceOf CustomClass2");
	check(mo, "clip3 instanceOf MovieClip");
	
	// Check that non-enumerable properties (unnamed instances,
	// constructor, __constructor__) are not enumerated.
	add_actions(mo, "var s = ''; for (i in clip3) { s += i + ','; };");
	check_equals(mo, "s", "'onRollOver,'");

	check(mo, "clip4.hasOwnProperty('__constructor__')");
	check(mo, "clip4.hasOwnProperty('constructor')");
	check(mo, "clip4.hasOwnProperty('__proto__')");
	check_equals(mo, "clip4.__proto__", "CustomClass2.prototype");
	check_equals(mo, "clip4.__constructor__", "CustomClass2");
	check_equals(mo, "clip4.constructor", "CustomClass2");
	check_equals(mo, "typeof(clip4)", "'movieclip'");
	check_equals(mo, "clip4._x", "240");
	check(mo, "clip4 instanceOf MovieClip");

	add_actions(mo,
		"totals(47);"
		"stop();"
		);

	SWFMovie_nextFrame(mo); /* end of frame5 */

	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Пример #8
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  const char *srcdir=".";
  char fdbfont[256];
  SWFMovieClip  dejagnuclip;
  
  /*********************************************
   *
   * Initialization
   *
   *********************************************/

  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);

  puts("Setting things up");

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
  //Ming_setScale(20.0); /* so we talk twips */
 
  mo = newSWFMovie();
  SWFMovie_setRate(mo, 1.0);
  SWFMovie_setDimension(mo, 800, 600);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); // 1st frame 

  // Check that the dejagnu clip is really a TextField.
  check_equals(mo, "_root.getInstanceAtDepth(-16383)",
          "_level0.instance1");
  check(mo, "_level0.instance1._xtrace_win "
          "instanceof TextField");

  // Note: the dejagnuclip already placed some texts, so the following
  // should be true.
  check(mo, "TextField.prototype.hasOwnProperty('background')");
  check(mo, "TextField.prototype.hasOwnProperty('backgroundColor')");
  check(mo, "TextField.prototype.hasOwnProperty('text')");
  check(mo, "TextField.prototype.hasOwnProperty('textColor')");

  /*********************************************
   *
   * Add some textfields
   *
   *********************************************/
  {
    SWFDisplayItem it;
    FILE *font_file = fopen(fdbfont, "r");
    if ( font_file == NULL )
    {
      perror(fdbfont);
      exit(1);
    }
    SWFBrowserFont bfont = newSWFBrowserFont("_sans");
    SWFFont efont = loadSWFFontFromFile(font_file);

    it = add_text_field(mo, (SWFBlock)bfont, "Hello", 1, 2, 3, SWFTEXTFIELD_ALIGN_LEFT, 10, 100, 101, 102, 50);
    SWFDisplayItem_setName(it, "dtext1");
    SWFDisplayItem_moveTo(it, 0, 200);
    it = add_text_field(mo, (SWFBlock)efont, "Hello", 4, 5, 6, SWFTEXTFIELD_ALIGN_CENTER, 11, 110, 111, 112, 51);
    SWFDisplayItem_setName(it, "etext1");
    SWFDisplayItem_moveTo(it, 0, 300);

    SWFBrowserFont bfont2 = newSWFBrowserFont("times");
    it = add_text_field(mo, (SWFBlock)bfont2, "Hello", 7, 8, 9, SWFTEXTFIELD_ALIGN_RIGHT, 12, 120, 121, 122, 52);
    SWFDisplayItem_setName(it, "dtext2");
    SWFDisplayItem_moveTo(it, 0, 400);
  }
  SWFMovie_nextFrame(mo); 

  check_equals(mo, "dtext1.embedFonts", "false");
  check_equals(mo, "etext1.embedFonts", "true");
  check_equals(mo, "etext1.hasOwnProperty('embedFonts')", "false");

  add_actions(mo, "ret = Selection.setFocus(dtext1);"
                  "check_equals(ret, false);"
                  "check_equals(Selection.getFocus(), '_level0.dtext1');");
  add_actions(mo, "ret = Selection.setFocus(etext1);"
                  "check_equals(ret, false);"
                  "check_equals(Selection.getFocus(), '_level0.etext1');");

  add_actions(mo, "createTextField('dynamictext1', 99, 10, 10, 10, 10);");

  add_actions(mo, "ret = Selection.setFocus(dynamictext1);"
               "check_equals(ret, false);"
               "check_equals(Selection.getFocus(), '_level0.dynamictext1');");

  check_equals(mo, "dtext1.__proto__", "TextField.prototype");
  check_equals(mo, "etext1.__proto__", "TextField.prototype");
  check_equals(mo, "etext1.__proto__", "dynamictext1.__proto__");

  // checks after placing some swf defined TextField
  check(mo, "TextField.prototype.hasOwnProperty('background')");
  check(mo, "TextField.prototype.hasOwnProperty('backgroundColor')");
  check(mo, "TextField.prototype.hasOwnProperty('text')");
  check(mo, "TextField.prototype.hasOwnProperty('textColor')");
  check(mo, "!TextField.prototype.hasOwnProperty('_parent')");
  check(mo, "!TextField.prototype.hasOwnProperty('_xmouse')");
  check(mo, "!TextField.prototype.hasOwnProperty('_ymouse')");
  check(mo, "!TextField.prototype.hasOwnProperty('_xscale')");
  check(mo, "!TextField.prototype.hasOwnProperty('_yscale')");
  
  check_equals(mo, "typeof(dtext1)", "'object'");
  check_equals(mo, "typeof(dtext1.text)", "'string'");
  check_equals(mo, "typeof(dtext1.background)", "'boolean'");
  check_equals(mo, "typeof(dtext1.backgroundColor)", "'number'");
  check_equals(mo, "typeof(dtext1.textColor)", "'number'");
  check_equals(mo, "typeof(dtext1._alpha)", "'number'");
  check_equals(mo, "typeof(dtext1.type)", "'string'");
  check_equals(mo, "dtext1.type", "'input'");
  
  check_equals(mo, "typeof(dtext1.__proto__.text)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__.background)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__.backgroundColor)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__.textColor)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__._alpha)", "'undefined'");

  check_equals(mo, "dtext1.hasOwnProperty('text')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('background')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('backgroundColor')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('textColor')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('_alpha')", "false");
  check(mo, "!dtext1.hasOwnProperty('_parent')");
  check(mo, "!dtext1.hasOwnProperty('_xmouse')");
  check(mo, "!dtext1.hasOwnProperty('_ymouse')");
  check(mo, "!dtext1.hasOwnProperty('_xscale')");
  check(mo, "!dtext1.hasOwnProperty('_yscale')");
  check(mo, "!etext1.hasOwnProperty('_parent')");
  check(mo, "!etext1.hasOwnProperty('_xmouse')");
  check(mo, "!etext1.hasOwnProperty('_ymouse')");
  check(mo, "!etext1.hasOwnProperty('_xscale')");
  check(mo, "!etext1.hasOwnProperty('_yscale')");
  
  check(mo, "dtext1.__proto__.hasOwnProperty('text')");
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('background')", "true");
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('backgroundColor')", "true");
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('textColor')", "true");
  // Why _alpha is special???
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('_alpha')", "false");
  
  check_equals(mo, "dtext1.text", "'Hello'");
  check_equals(mo, "etext1.text", "'Hello'");
  check_equals(mo, "dtext2.text", "'Hello'");
  check_equals(mo, "dtext1.background", "false");
  check_equals(mo, "etext1.background", "false");
  check_equals(mo, "dtext2.background", "false");
  check_equals(mo, "dtext1.backgroundColor", "0xffffff");
  check_equals(mo, "etext1.backgroundColor", "0xffffff");
  check_equals(mo, "dtext2.backgroundColor", "0xffffff");
  check_equals(mo, "dtext1.textColor", "6579558");
  check_equals(mo, "etext1.textColor", "7237488");
  check_equals(mo, "dtext2.textColor", "7895418");
  check_equals(mo, "dtext1._alpha", "100");
  check_equals(mo, "etext1._alpha", "100");
  check_equals(mo, "dtext2._alpha", "100");
  check_equals(mo, "etext1._parent", "_root");
  check_equals(mo, "dtext2._parent", "_root");
  check_equals(mo, "etext1._xscale", "100");
  check_equals(mo, "dtext2._xscale", "100");
  check_equals(mo, "etext1._yscale", "100");
  check_equals(mo, "dtext2._yscale", "100");
  check_equals(mo, "typeof(etext1._xmouse)", "'number'");
  check_equals(mo, "typeof(dtext2._xmouse)", "'number'");
  check_equals(mo, "typeof(etext1._ymouse)", "'number'"); 
  check_equals(mo, "typeof(dtext2._ymouse)", "'number'"); 

  // TextFormat objects are created on the fly
  add_actions(mo,
	"etext1.tf = etext1.getTextFormat();"
	"dtext2.tf = dtext2.getTextFormat();"
	);
  check_equals(mo, "typeof(etext1.tf)", "'object'"); 
  check_equals(mo, "typeof(dtext2.tf)", "'object'"); 
  check_equals(mo, "etext1.tf.size", "12"); 
  check_equals(mo, "dtext2.tf.size", "12"); 
  check_equals(mo, "etext1.tf.font", "'Bitstream Vera Sans'");
  check_equals(mo, "dtext2.tf.font", "'times'"); 
  check_equals(mo, "typeof(etext1.tf.bold)", "'boolean'");
  check_equals(mo, "typeof(dtext2.tf.bold)", "'boolean'");
  check_equals(mo, "etext1.tf.bold", "false");
  check_equals(mo, "dtext2.tf.bold", "false"); 
  check_equals(mo, "typeof(etext1.tf.italic)", "'boolean'");
  check_equals(mo, "typeof(dtext2.tf.italic)", "'boolean'");
  check_equals(mo, "etext1.tf.italic", "false");
  check_equals(mo, "dtext2.tf.italic", "false"); 
  check_equals(mo, "typeof(etext1.tf.indent)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.indent)", "'number'");
  check_equals(mo, "etext1.tf.indent", "4");
  check_equals(mo, "dtext2.tf.indent", "7"); 
  check_equals(mo, "typeof(etext1.tf.leftMargin)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.leftMargin)", "'number'");
  check_equals(mo, "etext1.tf.leftMargin", "5");
  check_equals(mo, "dtext2.tf.leftMargin", "8"); 
  check_equals(mo, "typeof(etext1.tf.rightMargin)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.rightMargin)", "'number'");
  check_equals(mo, "etext1.tf.rightMargin", "6");
  check_equals(mo, "dtext2.tf.rightMargin", "9"); 
  check_equals(mo, "typeof(etext1.tf.align)", "'string'");
  check_equals(mo, "typeof(dtext2.tf.align)", "'string'");
  check_equals(mo, "etext1.tf.align", "'center'");
  check_equals(mo, "dtext2.tf.align", "'right'"); 
  check_equals(mo, "typeof(etext1.tf.leading)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.leading)", "'number'");
  check_equals(mo, "etext1.tf.leading", "11");
  check_equals(mo, "dtext2.tf.leading", "12"); 
  check_equals(mo, "typeof(etext1.tf.color)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.color)", "'number'");
  check_equals(mo, "etext1.tf.color", "7237488");
  check_equals(mo, "dtext2.tf.color", "7895418");
  check_equals(mo, "typeof(etext1.tf.blockIndent)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.blockIndent)", "'number'");
  check_equals(mo, "etext1.tf.blockIndent", "0");
  check_equals(mo, "dtext2.tf.blockIndent", "0");
  check_equals(mo, "typeof(etext1.tf.underline)", "'boolean'");
  check_equals(mo, "typeof(dtext2.tf.underline)", "'boolean'");
  check_equals(mo, "etext1.tf.underline", "false");
  check_equals(mo, "dtext2.tf.underline", "false");

  add_actions(mo, "dtext1.background = true;"
                  "etext1.background = true;"
                  "dtext2.background = true;"
                  "dtext1.backgroundColor = 0xff0000;"
                  "etext1.backgroundColor = 0x00ff00;"
                  "dtext2.backgroundColor = 0x0000ff;"
                  "dtext1.textColor = 0x00ffff;"
                  "etext1.textColor = 0xff00ff;"
                  "dtext2.textColor = 0xffff00;"
                  "dtext1.text += ' world';"
                  "etext1.text += ' world';"
                  "dtext2.text += ' world';" );

  check_equals(mo, "etext1.getTextFormat().color", "0xff00ff");
  check_equals(mo, "dtext2.getTextFormat().color", "0xffff00"); 

  check_equals(mo, "dtext1.text", "'Hello world'");
  check_equals(mo, "etext1.text", "'Hello world'");
  check_equals(mo, "dtext2.text", "'Hello world'");
  check_equals(mo, "dtext1.background", "true");
  check_equals(mo, "etext1.background", "true");
  check_equals(mo, "dtext2.background", "true");
  check_equals(mo, "dtext1.backgroundColor", "0xff0000");
  check_equals(mo, "etext1.backgroundColor", "0x00ff00");
  check_equals(mo, "dtext2.backgroundColor", "0x0000ff");
  check_equals(mo, "dtext1.textColor", "0x00ffff");
  check_equals(mo, "etext1.textColor", "0xff00ff");
  check_equals(mo, "dtext2.textColor", "0xffff00");
  SWFMovie_nextFrame(mo); 
  
  add_actions(mo, "dtext1._alpha = 0;"
                  "etext1._alpha = 0;"
                  "dtext2._alpha = 0;" );
  check_equals(mo, "dtext1._alpha", "0");
  check_equals(mo, "etext1._alpha", "0");
  check_equals(mo, "dtext2._alpha", "0");
  SWFMovie_nextFrame(mo); 

  add_actions(mo, "dtext1._alpha = 100; dtext1.embedFonts=true; dtext1.text = 'embedFonts';"
                  "etext1._alpha = 100; etext1.embedFonts=false; etext1.text = '!embedFonts';"
                  "dtext2._alpha = 100;" );

  check_equals(mo, "dtext1.embedFonts", "true");
  check_equals(mo, "etext1.embedFonts", "false");

  add_actions(mo, "totals(); stop();");
  SWFMovie_nextFrame(mo); 

  /*****************************************************
   *
   * Output movie
   *
   *****************************************************/
  puts("Saving " OUTPUT_FILENAME );

  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #9
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	const char *srcdir=".";
	SWFMovieClip  dejagnuclip;
    SWFDisplayItem it;


	/*********************************************
	 *
	 * Initialization
	 *
	 *********************************************/

	if ( argc>1 ) srcdir=argv[1];
	else
	{
		fprintf(stderr, "Usage: %s\n", argv[0]);
		return 1;
	}

	puts("Setting things up");

	Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* let's talk pixels */
 
	mo = newSWFMovie();
	SWFMovie_setRate(mo, 1.33);
	SWFMovie_setDimension(mo, 640, 400);

	/*********************************************
	 *
	 * Body
	 *
	 *********************************************/

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
	it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
	addSoundExport(mo);

	SWFMovie_nextFrame(mo);  /* end of frame1 */

    // Tracker variables for calls to onSoundComplete
    add_actions(mo, "c_soundComplete = 0;");
    add_actions(mo, "d_soundComplete = 0;");
    add_actions(mo, "e_soundComplete = 0;");

    add_actions(mo, "a = new Sound();");
    check_equals(mo, "a.duration", "undefined");
    add_actions(mo, "a.attachSound('mono22_mp2');");
    check_equals(mo, "a.duration", "13740");

    add_actions(mo, "b = new Sound(); b.attachSound('mono22_mp2b');");
    add_actions(mo, "c = new Sound(); c.attachSound('stereo8_mp3');");

    // Two different Sounds with the same exported sound.
    add_actions(mo, "d = new Sound(); d.attachSound('stereo8_mp3b');");
    add_actions(mo, "e = new Sound(); e.attachSound('stereo8_mp3b');");

    add_actions(mo, "check_equals(a.getBytesTotal(), undefined);");
    add_actions(mo, "check_equals(a.getBytesLoaded(), undefined);");
    add_actions(mo, "check_equals(a.id3, undefined);");
    check_equals(mo, "a.position", "0");
    add_actions(mo, "a.start();");
    // This isn't very consistent either. Please re-enable when it is.
    //check_equals(mo, "a.position", "0");

    check_equals(mo, "b.duration", "13740");
    check_equals(mo, "b.position", "0");
    add_actions(mo, "b.start();");

    // Here, gst gives 46, ffmpeg 0.
    //check_equals(mo, "b.position", "0");

    check_equals(mo, "c.duration", "5224");
    check_equals(mo, "c.position", "0");
    // Play twice (loop).
    add_actions(mo, "c.start(0, 2);");
    check_equals(mo, "c.position", "0");

    check_equals(mo, "d.duration", "5224");
    check_equals(mo, "d.position", "0");
    // Start twice.
    add_actions(mo, "d.start();");
    add_actions(mo, "d.start(4);");
    check_equals(mo, "d.position", "0");

    add_actions(mo, "e.start();");

    SWFMovie_nextFrame(mo);

    add_actions(mo, "stop();"
            "note('will wait for onSoundComplete to finish the test (about "
            "13 seconds).');");

    // This is the longest sound, so the test should end when this is called.
    add_actions(mo, "a.onSoundComplete = function() {"
            "check_equals(arguments.length, 0);"
            "check_equals(a.position, 13740, 'a.position at a.onSoundComplete time');"
            "check_equals(c_soundComplete, 1, 'c_soundComplete at a.onSoundComplete time');"
            "check_equals(d_soundComplete, 1, 'd_soundComplete at a.onSoundComplete time');"
            "check_equals(e_soundComplete, 2, 'e_soundComplete at a.onSoundComplete time');"
            "totals(26); "
            "finished = true;"
            "};");

    // Check position of b, c, d, and e after the first loop of c.
    add_actions(mo, "c.onSoundComplete = function() {"
            // I'm not sure how reliable this is:
            "check_equals(b.position, 10472, 'b.position at c.onSoundComplete time');"
            "check_equals(c.position, 5224, 'c.position at c.onSoundComplete time');"
            "check_equals(d.position, 5224, 'd.position at c.onSoundComplete time');"
            "check_equals(e.position, 5224, 'e.position at c.onSoundComplete time');"
            "c_soundComplete++;"
            "note('c.onSoundComplete() called '+c_soundComplete+' time(s).');"
            "};");

    add_actions(mo, "d.onSoundComplete = function() {"
            "check_equals(d.position, 5224, 'd.position at d.onSoundComplete time');"
            "d_soundComplete++;"
            "note('d.onSoundComplete() called '+d_soundComplete+' time(s).');"
            "};");

    // This starts e again. It should run twice before the longest
    // sound stops.
    add_actions(mo, "e.onSoundComplete = function() {"
            "check_equals(e.position, 5224, 'e.position at e.onSoundComplete time');"
            "e_soundComplete++;"
            "note('e.onSoundComplete() called '+e_soundComplete+' time(s).');"
            "if ( e_soundComplete < 2 ) e.start();"
            "};");


	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Пример #10
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  const char *srcdir=".";
  char fdbfont[256];
  SWFMovieClip  dejagnuclip;
  
  /*********************************************
   *
   * Initialization
   *
   *********************************************/

  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);

  puts("Setting things up");

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
  //Ming_setScale(20.0); /* so we talk twips */
 
  mo = newSWFMovie();
  SWFMovie_setRate(mo, 1.0);
  SWFMovie_setDimension(mo, 800, 600);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); // 1st frame 


  /*********************************************
   *
   * Add some textfields
   *
   *********************************************/
  {
    SWFDisplayItem it;
    FILE *font_file = fopen(fdbfont, "r");
    if ( font_file == NULL )
    {
      perror(fdbfont);
      exit(1);
    }
    SWFFont efont = loadSWFFontFromFile(font_file);

    it = add_text_field(mo, efont, "First text");
    SWFDisplayItem_setName(it, "dtext1");
    SWFDisplayItem_moveTo(it, 0, 200);
    it = add_text_field(mo, efont, "Zweites Textfeld");
    SWFDisplayItem_setName(it, "etext1");
    SWFDisplayItem_moveTo(it, 0, 300);

    it = add_text_field(mo, efont, "Some more static text here... abcdefgh");
    SWFDisplayItem_setName(it, "dtext2");
    SWFDisplayItem_moveTo(it, 0, 400);
  }
  SWFMovie_nextFrame(mo); 

  add_actions(mo, "createTextField('dynamictext1', 99, 10, 10, 10, 10);"
		  "this.dynamictext1.text = 'Dynamic Text';");
  
  add_actions(mo, "ts = this.getTextSnapshot();");
  check(mo, "ts instanceof TextSnapshot");
  check_equals(mo, "ts.getCount()", "64");

  check_equals(mo, "ts.getText(0, 1)", "'F'");
  check_equals(mo, "ts.getText(3, 3)", "'s'");
  check_equals(mo, "ts.getText(-5, 5)", "'First'");
  check_equals(mo, "ts.getText(10, 6)", "'Z'");
  check_equals(mo, "ts.getText(0, 100)", "'First textZweites TextfeldSome more "
		  "static text here... abcdefgh'");
  add_actions(mo, "ss = ts.getText(100, 110);");
  check_equals(mo, "typeof(ss)", "'string'");
  check_equals(mo, "ss", "'h'");
  check_equals(mo, "ss.length", "1");
  
  check_equals(mo, "ts.getText(0, 100, true)", 
          "'First text\nZweites Textfeld\nSome more "
		  "static text here... abcdefgh'");
  
  check_equals(mo, "ts.getText(0, 14, true)", "'First text\nZwei'");

  check_equals(mo, "ts.findText(0, '', false)", "-1");
  check_equals(mo, "ts.findText(0, 'f', false)", "0");
  check_equals(mo, "ts.findText(0, 'f', true)", "22");
  check_equals(mo, "ts.findText(1, 'Rst', false)", "2");
  check_equals(mo, "ts.findText(3, 'RSt', false)", "-1");
  check_equals(mo, "ts.findText(100, 'h', false)", "-1");
  check_equals(mo, "ts.findText(64, 'h', false)", "-1");
  check_equals(mo, "ts.findText(-5, 'Zwei', true)", "-1");
  check_equals(mo, "ts.findText(-5, 'gh', true)", "-1");

  add_actions(mo, "ts.setSelected(5, 30, true);");
  check_equals(mo, "ts.getSelectedText()", "' textZweites TextfeldSome'");
  check_equals(mo, "ts.getSelectedText(true)", "' text\nZweites "
          "Textfeld\nSome'");
  check_equals(mo, "ts.getSelectedText(false)", "' textZweites TextfeldSome'");
  check_equals(mo, "ts.getSelected(0, 4)", "false");
  check_equals(mo, "ts.getSelected(1, 9)", "true");
  check_equals(mo, "ts.getSelected(-4, 10)", "true");
  check_equals(mo, "ts.getSelected(-4, 6)", "true");
  check_equals(mo, "ts.getSelected(28, 23)", "true");
  check_equals(mo, "ts.getSelected(20, 20)", "true");
  check_equals(mo, "ts.getSelected(20, 27)", "true");
  check_equals(mo, "ts.getSelected(-3, -1)", "false");
  check_equals(mo, "ts.getSelected(30, 31)", "false");
  check_equals(mo, "ts.getSelected(0, 5)", "false");
  check_equals(mo, "ts.getSelected(40, 45)", "false");
  check_equals(mo, "ts.getSelected(31, 34)", "false");

  check_equals(mo, "ts.getSelected(0)", "undefined");
  check_equals(mo, "ts.getSelected(1)", "undefined");
  check_equals(mo, "ts.getSelected(-4)", "undefined");
  check_equals(mo, "ts.getSelected(-4)", "undefined");
  check_equals(mo, "ts.getSelected(28)", "undefined");
  check_equals(mo, "ts.getSelected(20)", "undefined");

  // Selected text is stored in the textfield and reset when a new
  // snapshot is taken.
  add_actions(mo, "ts2 = new TextSnapshot(this);");
  check_equals(mo, "ts.getSelectedText(false)", "''");
  check_equals(mo, "ts2.getCount()", "64");
  check_equals(mo, "ts2.getSelectedText()", "''");
  add_actions(mo, "ts2 = this.getTextSnapshot();");
  check_equals(mo, "ts2.getCount()", "64");
  check_equals(mo, "ts2.getSelectedText()", "''");

  add_actions(mo, "ts2.setSelected(3, 10, true);");
  check_equals(mo, "ts2.getSelectedText(false).length", "7");
  check_equals(mo, "ts.getSelectedText(false).length", "7");

  add_actions(mo, "ts.setSelectedColor(0xffff00);");
  add_actions(mo, "ts2.setSelectedColor(0x0000ff);");

  check_equals(mo, "ts.getSelectedText(false)", "'st text'");
  add_actions(mo, "ri = ts.getTextRunInfo(4, 10);");
  check_equals(mo, "typeof(ri)", "'object'");
  check(mo, "ri instanceof Array");
  check_equals(mo, "ri.length", "7");

  add_actions(mo, "el = ri[1];");
  check_equals(mo, "typeof(el)", "'object'");
  check(mo, "!el.hasOwnProperty('indexInRun')");
  check_equals(mo, "el.indexInRun", "5");
  check_equals(mo, "el.selected", "true");
  check_equals(mo, "el.font", "'Bitstream Vera Sans'");
  check_equals(mo, "el.color", "0");
  check_equals(mo, "el.height", "12");
  check_equals(mo, "el.matrix_a", "1");
  check_equals(mo, "el.matrix_b", "0");
  check_equals(mo, "el.matrix_c", "0");
  check_equals(mo, "el.matrix_d", "1");
  check_equals(mo, "el.matrix_tx", "25.95");
  check_equals(mo, "el.matrix_ty", "200");
  xcheck_equals(mo, "el.corner0x", "25.95");
  xcheck_equals(mo, "el.corner0y", "202.8");
  xcheck_equals(mo, "el.corner1x", "29.75");
  xcheck_equals(mo, "el.corner1y", "202.8");
  xcheck_equals(mo, "el.corner2x", "29.75");
  xcheck_equals(mo, "el.corner2y", "188.85");
  xcheck_equals(mo, "el.corner3x", "25.95");
  xcheck_equals(mo, "el.corner3y", "188.85");

  // Check properties individually
  check_equals(mo, "ri[2].height", "12");
  check_equals(mo, "ri[3].height", "12");
  check_equals(mo, "ri[4].height", "12");
  check_equals(mo, "ri[5].height", "12");
  check_equals(mo, "ri[6].height", "12");

  check_equals(mo, "ri[2].selected", "true");
  check_equals(mo, "ri[3].selected", "true");
  check_equals(mo, "ri[4].selected", "true");
  check_equals(mo, "ri[5].selected", "true");
  check_equals(mo, "ri[6].selected", "false");

  check_equals(mo, "ri[2].matrix_tx", "29.75");
  check_equals(mo, "ri[2].matrix_ty", "200");
  check_equals(mo, "ri[3].matrix_tx", "34.4");
  check_equals(mo, "ri[3].matrix_ty", "200");
  check_equals(mo, "ri[4].matrix_tx", "41.75");
  check_equals(mo, "ri[4].matrix_ty", "200");

  xcheck_equals(mo, "ri[2].corner0x", "29.75");
  xcheck_equals(mo, "ri[2].corner0y", "202.8");
  xcheck_equals(mo, "ri[3].corner0x", "34.4");
  xcheck_equals(mo, "ri[3].corner0y", "202.8");
  xcheck_equals(mo, "ri[4].corner0x", "41.75");
  xcheck_equals(mo, "ri[4].corner0y", "202.8");
  
  xcheck_equals(mo, "ri[2].corner2y", "188.85");
  xcheck_equals(mo, "ri[3].corner2y", "188.85");
  xcheck_equals(mo, "ri[4].corner2y", "188.85");

  add_actions(mo, "ts.setSelected(0, 10, true);");
  add_actions(mo, "ts.setSelected(15, 20, false);");
  check_equals(mo, "ts2.getSelectedText().length", "10");

  add_actions(mo, "ri2 = ts.getTextRunInfo(0, 100);");

  check_equals(mo, "ri2[0].selected", "true");
  check_equals(mo, "ri2[1].selected", "true");
  check_equals(mo, "ri2[2].selected", "true");
  check_equals(mo, "ri2[3].selected", "true");
  check_equals(mo, "ri2[4].selected", "true");
  check_equals(mo, "ri2[5].selected", "true");
  check_equals(mo, "ri2[6].selected", "true");
  check_equals(mo, "ri2[15].selected", "false");
  check_equals(mo, "ri2[16].selected", "false");
  check_equals(mo, "ri2[17].selected", "false");
  check_equals(mo, "ri2[18].selected", "false");

  xcheck_equals(mo, "ri2[50].corner2y", "388.85");
  xcheck_equals(mo, "ri2[50].corner2x", "156.6");
  xcheck_equals(mo, "ri2[51].corner2y", "388.85");
  xcheck_equals(mo, "ri2[51].corner2x", "163.95");

  check_equals(mo, "ri2[50].matrix_tx", "151.65");
  check_equals(mo, "ri2[51].matrix_tx", "156.55");

  add_actions(mo, "ts = this.getTextSnapshot();");
  check_equals(mo, "typeof(ts)", "'object'");
  add_actions(mo, "backup = TextSnapshot;");
  add_actions(mo, "TextSnapshot = undefined;");
  add_actions(mo, "t = new TextSnapshot();");
  check_equals(mo, "typeof(t)", "'undefined'");

  check_equals(mo, "typeof(TextSnapshot)", "'undefined'");
  add_actions(mo, "ts = this.getTextSnapshot();");
  xcheck_equals(mo, "typeof(ts)", "'undefined'");
  add_actions(mo, "TextSnapshot = backup;");
  add_actions(mo, "ts = this.getTextSnapshot();");
  check_equals(mo, "typeof(ts)", "'object'");
  
  add_actions(mo, "backup = TextSnapshot.prototype;");
  add_actions(mo, "TextSnapshot.prototype = undefined;");
  add_actions(mo, "ts = this.getTextSnapshot();");
  check_equals(mo, "typeof(ts)", "'object'");
  add_actions(mo, "TextSnapshot.prototype = backup;");
  add_actions(mo, "ts = this.getTextSnapshot();");
  check_equals(mo, "typeof(ts)", "'object'");
  
  add_actions(mo, "totals(); stop();");
  
  SWFMovie_nextFrame(mo); 

  /*****************************************************
   *
   * Output movie
   *
   *****************************************************/
  puts("Saving " OUTPUT_FILENAME );

  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #11
0
int main(int argc, char* argv[])
{

    SWFMovie mo;
    SWFMovieClip mc1, mc2, mc3, mc4, dejagnuclip;
    SWFDisplayItem it;
    SWFAction ac;
    SWFInitAction initac;

    const char *srcdir=".";
    if (argc > 1) srcdir = argv[1];
    else {
        fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
        return 1;
    }

    Ming_init();
    mo = newSWFMovieWithVersion(OUTPUT_VERSION);
    SWFMovie_setDimension(mo, 800, 600);
    SWFMovie_setRate (mo, 12.0);

    add_actions(mo,
            "if (!_global.hasOwnProperty('arr')) { _global.arr = []; };"
            "_global.ch = function(a, b) {"
            "   trace(a);"
            "   if (typeof(b)=='undefined' || (typeof(b)=='boolean' && b)) {"
            "       _global.arr.push(a);"
            "   };"
            "};"
            "this.onEnterFrame = function() { "
            "   _global.ch('onEnterFrame', false);"
            "};"
            );

    SWFMovie_nextFrame(mo);

    //  MovieClip 1 
    mc1 = newSWFMovieClip(); // 1 frames 

    // SWF_EXPORTASSETS 
    SWFMovie_addExport(mo, (SWFBlock)mc1, "Segments_Name");
    SWFMovie_writeExports(mo);

    //  MovieClip mc3 has two frames. In each frame a different MovieClip
    //  is placed with the name Segments.
    mc3 = newSWFMovieClip(); // 2 frames 

    //  MovieClip 2 
    mc2 = newSWFMovieClip(); // 1 frames 

    // Add mc2
    it = SWFMovieClip_add(mc3, (SWFBlock)mc2);
    SWFDisplayItem_setDepth(it, 1);
    SWFDisplayItem_setName(it, "Segments");

    // Frame 2
    SWFMovieClip_nextFrame(mc3);

    // Remove mc2
    SWFDisplayItem_remove(it);

    // Add mc1
    it = SWFMovieClip_add(mc3, (SWFBlock)mc1);
    SWFDisplayItem_setDepth(it, 1);
    SWFDisplayItem_setName(it, "Segments");

    SWFMovieClip_nextFrame(mc3);

    // End mc3


    // This is frame 1 of the main timeline

    // Put our sprite mc3 on stage.
    it = SWFMovie_add(mo, (SWFBlock)mc3);
    SWFDisplayItem_setDepth(it, 1);
    SWFDisplayItem_setName(it, "mc");

    //  mc4 is just for executing init actions.
    mc4 = newSWFMovieClip(); 
    SWFMovie_addExport(mo, (SWFBlock)mc4, "__Packages.Bug");
    SWFMovie_writeExports(mo);
    
    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
                0, 0, 800, 600);
    SWFMovie_add(mo, (SWFBlock)dejagnuclip);

    ac = newSWFAction(
        "_global.loops = 0;"
        "_global.c = 0;"
        "if( !_global.Bug ) {"
        "   _global.Bug = function () {"
        "       this.onUnload = function() { "
        "           _global.ch('dynamic unload: ' + this.c);"
        "       }; "
        "       this.onLoad = function() { "
        "           _global.ch('dynamic load: ' + this.c);"
        "       }; "
        "       this.c = _global.c;"
        "       _global.ch('ctor: ' + _global.c);"
        "       _global.c++;"
        "   };"
        "};"
    );

    initac = newSWFInitAction_withId(ac, 4);
    SWFMovie_add(mo, (SWFBlock)initac);
    
    ac = newSWFAction("Object.registerClass('Segments_Name',Bug);");
    initac = newSWFInitAction_withId(ac, 1);
    SWFMovie_add(mo, (SWFBlock)initac);
    add_actions(mo, "_global.ch('Frame ' + "
                            "_level0._currentframe + ' actions: ' "
                            "+ _level0.mc.Segments.c);");

    // Frame 2 of the main timeline
    SWFMovie_nextFrame(mo);
    add_actions(mo, "_global.ch('Frame ' + "
                            "_level0._currentframe + ' actions: ' "
                            "+ _level0.mc.Segments.c);");
    
    add_actions(mo,
        "    if (_global.loops < 5) {"
        "        _global.loops++;"
        "        gotoAndPlay(2);"
        "   }"
        "   else {"
        "      delete this.onEnterFrame;"
        "      gotoAndPlay(4);"
        "   };"
        );
    
    SWFMovie_nextFrame(mo);
    
    check_equals(mo, "_global.arr.length", "20");
    check_equals(mo, "_global.arr[0]", "'Frame 2 actions: undefined'");
    check_equals(mo, "_global.arr[1]", "'ctor: 0'");
    xcheck_equals(mo, "_global.arr[2]", "'Frame 3 actions: 0'");
    xcheck_equals(mo, "_global.arr[3]", "'dynamic load: 0'");
    check_equals(mo, "_global.arr[4]", "'Frame 2 actions: 0'");
    check_equals(mo, "_global.arr[5]", "'Frame 3 actions: 0'");
    check_equals(mo, "_global.arr[6]", "'Frame 2 actions: 0'");
    check_equals(mo, "_global.arr[7]", "'ctor: 1'");
    check_equals(mo, "_global.arr[8]", "'dynamic unload: 0'");
    xcheck_equals(mo, "_global.arr[9]", "'Frame 3 actions: 0'");
    check_equals(mo, "_global.arr[11]", "'Frame 2 actions: 0'");
    check_equals(mo, "_global.arr[12]", "'Frame 3 actions: 1'");
    check_equals(mo, "_global.arr[13]", "'Frame 2 actions: 1'");
    check_equals(mo, "_global.arr[14]", "'ctor: 2'");
    check_equals(mo, "_global.arr[15]", "'dynamic unload: 1'");
    xcheck_equals(mo, "_global.arr[16]", "'Frame 3 actions: 1'");
    xcheck_equals(mo, "_global.arr[17]", "'dynamic load: 2'");
    check_equals(mo, "_global.arr[18]", "'Frame 2 actions: 1'");
    check_equals(mo, "_global.arr[19]", "'Frame 3 actions: 2'");
    xcheck_equals(mo, "_global.arr.toString()",
		    "'Frame 2 actions: undefined,ctor: 0,Frame 3 actions: 0,dynamic load: 0,Frame 2 actions: 0,Frame 3 actions: 0,Frame 2 actions: 0,ctor: 1,dynamic unload: 0,Frame 3 actions: 0,dynamic load: 1,Frame 2 actions: 0,Frame 3 actions: 1,Frame 2 actions: 1,ctor: 2,dynamic unload: 1,Frame 3 actions: 1,dynamic load: 2,Frame 2 actions: 1,Frame 3 actions: 2'");

    SWFMovie_nextFrame(mo);
    add_actions(mo, "totals(21); stop();");
    
    SWFMovie_nextFrame(mo);

    // SWF_END 
    SWFMovie_save(mo, OUTPUT_FILENAME);

    return 0;
}
Пример #12
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	const char *srcdir=".";
	SWFMovieClip dejagnuclip;


	/*********************************************
	 *
	 * Initialization
	 *
	 *********************************************/

	if ( argc>1 ) srcdir=argv[1];
	else
	{
		fprintf(stderr, "Usage: %s\n", argv[0]);
		return 1;
	}

	puts("Setting things up");

	Ming_init();
        Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* let's talk pixels */
 
	mo = newSWFMovie();
	SWFMovie_setRate(mo, 12);
	//SWFMovie_setDimension(mo, 6400, 4000);
	SWFMovie_setDimension(mo, 640, 400);

	/*********************************************
	 *
	 * Body
	 *
	 *********************************************/

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
	SWFMovie_add(mo, (SWFBlock)dejagnuclip);

	addRedSquareExport(mo);
	/* it seems we need a SHOWFRAME for this to be effective */
	/* (maybe it's related to loop-back handling ?) */
	SWFMovie_nextFrame(mo); 

    // This should run for four frames. The counter should only be reset
    // on the first frame, i.e. when start is undefined. This should
    // work for all swf versions, unlike "if (undefined < 4);"

	add_actions(mo, "initObj = new Object();");
	add_actions(mo, "if (!started) { counter = 0; started = true; }");
	add_actions(mo, "redsquare = function() { "
            "           trace('hello redsquare'); "
            "           if (counter > 0) {"
            "               check_equals(this._x, counter * 70);"
            "               check_equals(Math.round(this._xscale), 99);"
            "               check_equals(Math.round(this._yscale), "
            "                       Math.round((10 * counter +5) / 60 * 100));"
            "		        check_equals(this._height, 10 * counter + 5); "
            "		        check_equals(this.aProperty, 6); "
            "           } else {"
            "               check_equals(this._x, 0);"
            "               check_equals(this._xscale, 100);"
            "               check_equals(this._height, 60.1);"
            "		        check_equals(this.aProperty, undefined); "
            "           };"
            "       };"
            "redsquare.prototype = new MovieClip();"
            "Object.registerClass('redsquare', redsquare);"
            );

	add_actions(mo,
		"if ( counter < 4 ) {"
		"	if ( counter > 0 ) { "
		"		initObj.aProperty = 6;"
		"		initObj._xscale = 99;"
		"		initObj._x = 70*counter;"
		"		initObj._height = 10*counter + 5; "
		"		attachMovie('redsquare', "
		"			'square'+counter, 70+counter, initObj);"
		"	} else {"
		/* We don't use an initObject for the first attachMovie call
		 * to verify that the DisplayObject will be kept in DisplayList
		 * at loopback time anyway
		 */
		"		attachMovie('redsquare', "
		"			'square'+counter, 70+counter);"
		"	}"
		" 	check_equals(this['square'+counter]._x, 70*counter);"
        "   if (counter > 0) {"
		" 	    check_equals(this['square'+counter]._height, 10 * counter + 5);"
		"   };"
        "	note('Depth is '+70*counter);"
		"	counter++;"
		"	note('Next counter is '+counter);"
		"} else {"
		"	totals(26); stop();"
		"}"
		);

	SWFMovie_nextFrame(mo); /* showFrame */


	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Пример #13
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	const char *srcdir=".";
	SWFMovieClip dejagnuclip;


	/*********************************************
	 *
	 * Initialization
	 *
	 *********************************************/

	if ( argc>1 ) srcdir=argv[1];
	else
	{
		fprintf(stderr, "Usage: %s\n", argv[0]);
		return 1;
	}

	puts("Setting things up");

	Ming_init();
    Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* let's talk pixels */
 
	mo = newSWFMovie();
	SWFMovie_setRate(mo, 12);
	//SWFMovie_setDimension(mo, 6400, 4000);
	SWFMovie_setDimension(mo, 640, 400);

	/*********************************************
	 *
	 * Body
	 *
	 *********************************************/

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
	SWFMovie_add(mo, (SWFBlock)dejagnuclip);

	addRedSquareExport(mo);
	/* it seems we need a SHOWFRAME for this to be effective */
	/* (maybe it's related to loop-back handling ?) */
	SWFMovie_nextFrame(mo); 

	/* A load of tests for depth */
	
	add_actions(mo, "attachMovie('redsquare', 'depthtest', -16, initObj);"
	                "d = depthtest.getDepth();");
	check_equals(mo, "d", "-16");


	add_actions(mo, "attachMovie('redsquare', 'depthtest', -16384, initObj);"
	                "d = depthtest.getDepth();");
	check_equals(mo, "d", "-16384");

    /* Less than -16384 fails */
	add_actions(mo, "attachMovie('redsquare', 'depthtest2', -20000, initObj);"
	                "d = depthtest2.getDepth();");
	check_equals(mo, "d", "undefined");

    /* It really does */
	add_actions(mo, "attachMovie('redsquare', 'depthtest2', -16385, initObj);"
	                "d = depthtest2.getDepth();");
	check_equals(mo, "d", "undefined");

    /* Up to 2130690044 works */
	add_actions(mo, "attachMovie('redsquare', 'depthtest2', 1147483648, initObj);"
	                "d = depthtest2.getDepth();");
	check_equals(mo, "d", "1147483648");

    /* Up to 2130690044 works */
	add_actions(mo, "attachMovie('redsquare', 'depthtest3', 2130690044, initObj);"
	                "d = depthtest3.getDepth();");
	check_equals(mo, "d", "2130690044");

    /* 2130690045 doesn't work */
	add_actions(mo, "attachMovie('redsquare', 'depthtest4', 2130690045, initObj);"
	                "d = depthtest4.getDepth();");
	check_equals(mo, "d", "undefined");

    /* duplicateMovieClip */
    /* Same limits...     */

    add_actions(mo, "createEmptyMovieClip('original', 10);");

	add_actions(mo, "duplicateMovieClip('original', 'dup1', -1);"
	                "d = dup1.getDepth();");
	check_equals(mo, "d", "-1");

	add_actions(mo, "original.duplicateMovieClip('odup1', -1);"
	                "d = odup1.getDepth();");
	check_equals(mo, "d", "-1");

	add_actions(mo, "duplicateMovieClip('original', 'dup2', -16384);"
	                "d = dup2.getDepth();");
	check_equals(mo, "d", "-16384");

	add_actions(mo, "original.duplicateMovieClip('odup2', -16384);"
	                "d = odup2.getDepth();");
	check_equals(mo, "d", "-16384");

	add_actions(mo, "duplicateMovieClip('original', 'dup3', -16385);"
	                "d = dup3.getDepth();");
	check_equals(mo, "d", "undefined");

	add_actions(mo, "original.duplicateMovieClip('odup3', -16385);"
	                "d = odup3.getDepth();");
	check_equals(mo, "d", "undefined");

	add_actions(mo, "duplicateMovieClip('original', 'dup4', 2130690044);"
	                "d = dup4.getDepth();");
	check_equals(mo, "d", "2130690044");

	add_actions(mo, "original.duplicateMovieClip('odup4', 2130690044);"
	                "d = odup4.getDepth();");
	check_equals(mo, "d", "2130690044");

	add_actions(mo, "duplicateMovieClip('original', 'dup5', 2130690045);"
	                "d = dup5.getDepth();");
	check_equals(mo, "d", "undefined");

	add_actions(mo, "original.duplicateMovieClip('odup5', 2130690045);"
	                "d = odup5.getDepth();");
	check_equals(mo, "d", "undefined");
    
	add_actions(mo, "totals(); stop();");

	SWFMovie_nextFrame(mo); /* showFrame */

	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Пример #14
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	SWFMovieClip dejagnuclip;
	SWFDisplayItem it1;


	const char *srcdir=".";
	if ( argc>1 ) 
		srcdir=argv[1];
	else
	{
   		//fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
   		//return 1;
	}

	Ming_init();
	mo = newSWFMovieWithVersion(OUTPUT_VERSION);
	SWFMovie_setDimension(mo, 800, 600);
	SWFMovie_setRate (mo, 2);

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
	SWFMovie_add(mo, (SWFBlock)dejagnuclip);
	SWFMovie_nextFrame(mo); 

	// Frame 2: Add a static movieclip at depth 3 with origin at 10,200
	it1 = add_static_mc(mo, "static3", 3, 10, 200, 20, 20);
	add_actions(mo,
		"static3.myThing = 'guess';"
		"check_equals(static3._x, 10);"
		"check_equals(static3.myThing, 'guess');"
		"check_equals(static3.getDepth(), -16381);" 
		);
	SWFMovie_nextFrame(mo); 

	// Frame 3: nothing new
	SWFMovie_nextFrame(mo); 

	// Frame 4: move DisplayObject at depth 3 to position 50,200
	SWFDisplayItem_moveTo(it1, 50, 200); 
	add_actions(mo,
		"check_equals(static3._x, 50);"
		"check_equals(static3.getDepth(), -16381);" 
		);
	SWFMovie_nextFrame(mo); 

	// Frame 5: nothing new
	SWFMovie_nextFrame(mo); 

	// Frame 6: nothing new
	SWFMovie_nextFrame(mo); 

	// Frame 7: go to frame 2
	add_actions(mo,

		"check_equals(static3.myThing, 'guess');"
		"check_equals(static3._x, 50);"

		// Store a reference to the static3 instance
		// before jumping back
		"dynRef = static3;"

		// this reset char at depth -16381 to be at position 10,200
		"gotoAndStop(2);"

		// Static3 refers to same instance
		"check_equals(static3.myThing, 'guess');" 
		"check_equals(static3.getDepth(), -16381);" 

		// But it has now be reset to position 10,100 as specified
		// by PlaceObject2 tag in frame 2.
		// Note that the PlaceObject2 in frame 2 has the "move" flag
		// set to off as it's really intended to be used to *create*
		// an instance. Instead, since that depth is already occupied,
		// it behave as if it was a transforming PlaceObject2
		"check_equals(static3._x, 10);" 

		// The reference still refers to the same instance
		//  (see http://www.gnashdev.org/wiki/index.php/SoftReferences)
		"check_equals(dynRef.myThing, 'guess');" 
		"check_equals(dynRef.getDepth(), -16381);" 
		"check_equals(typeof(dynRef), 'movieclip');"
		"check_equals(dynRef._x, 10);"
		"check_equals(dynRef, static3);"

		// A single instance is created in total
		"check_equals(depth3Constructed, 1);"  

		"totals();"
		);
	SWFMovie_nextFrame(mo); 

	//Output movie
	puts("Saving " OUTPUT_FILENAME );
	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Пример #15
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;
}
Пример #16
0
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;
}
Пример #17
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;
}
Пример #18
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;
}
Пример #19
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFShape static1, static2;
  SWFDisplayItem it1;


  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      //return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 2);

  static1 = get_shape(60, 60, 255, 0, 0);
  static2 = get_shape(60, 60, 0, 255, 0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); 

  // Frame 2: place DisplayObject at depth 3 (-16381)
  it1 = SWFMovie_add(mo, (SWFBlock)static1);
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_moveTo(it1, 100, 300);
  SWFDisplayItem_setName(it1, "static1");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);
  add_actions(mo, "static1.name='static1';"); 

  check_equals(mo, "typeof(static1)", "'movieclip'"); 
  check_equals(mo, "static1", "_root");
  check_equals(mo, "static1.name", "'static1'");
  check_equals(mo, "_root.name", "'static1'");

  // Gnash allows custom members to shape DisplayObjects...
  // this is important to verify, see next check for it after REPLACE
  check_equals(mo, "static1.name", "'static1'");

  check_equals(mo, "static1._target", "'/'");
  SWFMovie_nextFrame(mo); 

  // Frame 3: replace instance at depth -16381 with DisplayObject 2
  if ( SWFMovie_replace(mo, it1, (SWFBlock)static2) )
  {
	  abort(); // grace and beauty...
  }
  SWFDisplayItem_moveTo(it1, 130, 330);
  SWFDisplayItem_setName(it1, "static2");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);


  // Can still reference the old DisplayObject and it's variables, after replace
  xcheck_equals(mo, "typeof(static1)", "'movieclip'"); 
  xcheck_equals(mo, "static1", "_root");
  xcheck_equals(mo, "static1.name", "'static1'");
  check_equals(mo, "_root.name", "'static1'");

  // While the new name results undefined...
  xcheck_equals(mo, "typeof(static2)", "'undefined'"); // the name wasn't changed

  // Everything suggests that a new instance is NOT created on replace !!!
  // Gnash here fails because it creates a NEW instance

  // We can't check the color or the _x in a self-contained testcase unfortunately,
  // we'll need a MovieTester-based runner for this.
  // It is expected the color of the current instane is GREEN, and the boundaries
  // are from 130 to 190 for X and 330 to 390 for Y.
  // TODO: implement a MovieTester based runner !!

  SWFMovie_nextFrame(mo); 
 
  // Frame 4: jump to frame 2, stop and check

  add_actions(mo,

    "gotoAndStop(2); " 

    // Shapes don't get their onConstruct event invoked !
    "check_equals(typeof(_root.depth3Constructed), 'undefined');"

    // Original DisplayObject name is still referenceable
    "check_equals(typeof(static1), 'movieclip');"

    // And it still has it's user-provided property
    "check_equals(static1.name, 'static1');"

    // We can't check the color or the _x in a self-contained testcase unfortunately,
    // we'll need a MovieTester-based runner for this.
    // It is expected the color of the current instance is RED, and the boundaries
    // are from 100 to 120 for both X and Y.
    // TODO: implement a MovieTester based runner !!

    "totals();"
    );
  SWFMovie_nextFrame(mo); 

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #20
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;
}
Пример #21
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  int frames;
  SWFVideoStream stream;
  SWFDisplayItem item;
  SWFMovieClip dejagnuclip;
  FILE *flv, *font_file;
  SWFFont font;
  char filename[256];
  char fdbfont[1024];

  if ( argc>1 ) mediadir=argv[1];
  else
  {
    fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
    return 1;
  }
	
  
  sprintf(filename, "%s/square.flv", mediadir);
  flv = fopen(filename, "rb");
  if (flv == NULL) {
	  perror(filename);
	  return -1;
  }

  sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", mediadir);
  font_file = fopen(fdbfont, "r");
  if ( font_file == NULL )
  {
    perror(fdbfont);
    exit(1);
  }

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);

  font = loadSWFFontFromFile(font_file);
	
  mo = newSWFMovie();
  SWFMovie_setDimension(mo, 320, 96);

  if (mo == NULL) return -1;

  SWFMovie_setRate(mo, 5);

  dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 200, 200);
  item = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFDisplayItem_setDepth(item, 200); 
  SWFDisplayItem_move(item, 140, 0); 

  stream = newSWFVideoStream_fromFile(flv);
  item = SWFMovie_add(mo, (SWFBlock)stream);
  SWFDisplayItem_setName(item, "vid");

  // A bug in Ming prevents this from working the
  // way I liked it to. It was useful to try this
  // out as it exposed a bad bug in gnash eating up
  // all memory and a few other issues.
  //
  // In order to keep the test *runner* untouched
  // this will be commented out for now. When Ming
  // is fixed I'll like to have two instances of
  // the definition playing one near the other,
  // both playing all frames.
  //
  //item = SWFMovie_add(mo, (SWFBlock)stream);
  //SWFDisplayItem_move(item, 150, 0);

  // Mouse clicks toggle play/stop
  add_actions(mo,
	"_root.onMouseDown = function() {"
	"  if (stopped) { play(); stopped=false; }"
	"  else { stop(); stopped=true; }"
	"};");

  // Pressing a number jumps to the specified frame
  add_actions(mo,
	"_root.onKeyDown = function() {"
	" var fnum = Key.getAscii() - 47;"
	//" trace('going to frame '+fnum);"
	" _root.gotoAndPlay(fnum);"
	"}; Key.addListener(_root);");

  // TODO: dynamic frame rate adjust
  frames = SWFVideoStream_getNumFrames(stream);
  for(; frames > 0; frames--)
  {
    SWFMovie_nextFrame(mo);
  }

  /// Video.clear() should not work on embedded Videos.
  add_actions(mo, "stop(); vid.clear(); trace(vid);");
  add_actions(mo, "note('You should still see the video frame."
          " Click to replay');"
		  "o = {};"
		  "o.onMouseDown = function() { _root.play(); };"
		  "Mouse.addListener(o);"
	     );

  SWFMovie_nextFrame(mo);

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #22
0
int main(int argc, char** argv)
{
  SWFMovie  movie;
  SWFMovieClip dejagnuclip;
  SWFAction ac[FRAME_COUNT];

  SWFDisplayItem it;
  SWFMovieClip mc1;

  int i;
  const char *srcdir=".";

  if ( argc>1 ) srcdir=argv[1];
  else
  {
    fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
    return 1;
  }

  Ming_init();
  movie = newSWFMovie();
  SWFMovie_setDimension(movie, 800, 600);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(movie, (SWFBlock)dejagnuclip);

  // Add frame ActionScipts to frames
  ac[0] = action_in_frame1();
  ac[1] = action_in_frame2();
  ac[2] = action_in_frame3();
  ac[3] = action_in_frame4();
  
  for(i=0; i<FRAME_COUNT; i++)
  {
    SWFMovie_add(movie, (SWFBlock)ac[i]);
    SWFMovie_nextFrame(movie); 
  }

  SWFMovie_add(movie, (SWFBlock)newSWFAction("_level0.ar = [];"));

  // This checks that a change of target in onEnterFrame code does
  // not change the target for other code.
  mc1 = newSWFMovieClip();
  SWFMovieClip_add(mc1, (SWFBlock)newSWFAction("this.g = 'moo'; _level0.ar.push(g);"));
  SWFMovieClip_nextFrame(mc1);
  SWFMovieClip_add(mc1, (SWFBlock)newSWFAction("_level0.ar.push(g);"));
  SWFMovieClip_nextFrame(mc1);

  it = SWFMovie_add(movie, (SWFBlock)mc1);
  SWFDisplayItem_addAction(it,
    compileSWFActionCode(" _root.note('onEnterFrame');"
                         " _level0.ar.push('setTarget');"
                         " asm { push '_level0' settargetexpr }; "),
                         SWFACTION_ENTERFRAME);  
  
  SWFMovie_nextFrame(movie); 

  check_equals(movie, "ar.toString()", "'moo,setTarget,moo'");

  SWFMovie_add(movie, (SWFBlock)newSWFAction("_root.totals(); stop();"));
  SWFMovie_nextFrame(movie); 

  // save files
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(movie, OUTPUT_FILENAME);

  return 0;
}
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip  mc1, mc2, mc3, mc4, mc5, dejagnuclip;
  SWFDisplayItem it1, it2, it3, it4, it5;
  SWFShape  sh_red;

  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, " x2 += 'as_start+'; "
                  " _root.OnLoad = function () { _root.note('_root onLoad called'); x2 += 'load_called+'; }; "
                  " x2 += 'as_end+'; "
                  " _root.onEnterFrame = function () { x3 += 'enterFrame_called+'; }; ");
  SWFMovie_nextFrame(mo); /* 1st frame */

  
  mc1 = newSWFMovieClip();
  sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc1, (SWFBlock)sh_red);  
  add_clip_actions(mc1, " _root.note('actions in 1st frame of mc1'); "
			// Defining onLoad in first frame of a sprite doesn't work, but works for root
			" this.onLoad = function() { _root.note('mc1 onLoad called'); _root.x1 += 'YY'; };"
                        " _root.x1 += '2+'; ");
  SWFMovieClip_nextFrame(mc1); /* mc1, 1st frame */
  add_clip_actions(mc1, " _root.note('actions in 2nd frame of mc1'); "
                        " _root.x1 += '12+'; "
                        " stop(); ");
  SWFMovieClip_nextFrame(mc1); /* mc1, 2nd frame */
 
  mc2 = newSWFMovieClip();
  sh_red = make_fill_square (80, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc2, (SWFBlock)sh_red); 
  add_clip_actions(mc2, " _root.note('actions in 1st frame of mc2'); "
			// Defining onLoad in first frame of a sprite doesn't work, but works for root
			" this.onLoad = function() { _root.note('mc2 onLoad called'); _root.x1 += 'XX'; };"
                        " _root.x1 += '4+'; "); 
  SWFMovieClip_nextFrame(mc2); /* mc2, 1st frame */
  add_clip_actions(mc2, " _root.note('actions in 2nd frame of mc2'); "
                        " _root.x1 += '10+'; "
                        " stop(); "); 
  SWFMovieClip_nextFrame(mc2); /* mc2, 2nd frame */
  
  mc3 = newSWFMovieClip();
  sh_red = make_fill_square (160, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc3, (SWFBlock)sh_red);  
  add_clip_actions(mc3, " _root.note('actions in 1st frame of mc3'); "
			// Defining onLoad in first frame of a sprite doesn't work, but works for root
			" this.onLoad = function() { _root.note('mc3 onLoad called'); _root.x1 += 'ZZ'; };"
                        " _root.x1 += '6+';"); 
  SWFMovieClip_nextFrame(mc3); /* mc3, 1st frame */
  add_clip_actions(mc3, " _root.note('actions in 2nd frame of mc3'); "
                        " _root.x1 += '8+'; "
                        " stop(); "); 
  SWFMovieClip_nextFrame(mc3); /* mc3, 2nd frame */
  
  
  /* add mc1 to _root and name it as "mc1" */
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  
  SWFDisplayItem_setDepth(it1, 10); 
  SWFDisplayItem_setName(it1, "mc1"); 
  /* Define Construct ClipEvent */
  SWFDisplayItem_addAction(it1,
    compileSWFActionCode(" _root.note('mc1 Construct called');"
                         " _root.x0 += '01+'; "),
    SWFACTION_CONSTRUCT);
  /* Define Load ClipEvent */
  SWFDisplayItem_addAction(it1,
    compileSWFActionCode(" _root.note('mc1 Load called');"
                         " _root.x1 += '1+'; "),
    SWFACTION_ONLOAD);
  /* Define Unload ClipEvent */
  SWFDisplayItem_addAction(it1,
    compileSWFActionCode(" _root.note('mc1 Unload called'); "
                         " _root.x1 += '13+'; "),
    SWFACTION_UNLOAD);
  /* Define EnterFrame ClipEvent */
  SWFDisplayItem_addAction(it1,
    compileSWFActionCode(" _root.note('mc1 EnterFrame called'); "
                         " _root.x1 += '11+'; "),
    SWFACTION_ENTERFRAME);
    
  /* add mc2 to _root and name it as "mc2" */
  it2 = SWFMovie_add(mo, (SWFBlock)mc2);  
  SWFDisplayItem_setDepth(it2, 12); 
  SWFDisplayItem_setName(it2, "mc2"); 
  /* Define Construct ClipEvent */
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(" _root.note('mc2 Construct called');"
                         " _root.x0 += '02+'; "),
    SWFACTION_CONSTRUCT);
  /* Define Load ClipEvent */
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(" _root.note('mc2 Load called'); "
                         " _root.x1 += '3+'; "),
    SWFACTION_ONLOAD);
  /* Define Unload ClipEvent */
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(" _root.note('mc2 Unload called'); "
                         " _root.x1 += '14+'; "),
    SWFACTION_UNLOAD);
  /* Define EnterFrame ClipEvent */
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(" _root.note('mc2 EnterFrame called'); "
                         " _root.x1 += '9+'; "),
    SWFACTION_ENTERFRAME);
    
  /* add mc3 to _root and name it as "mc3" */
  it3 = SWFMovie_add(mo, (SWFBlock)mc3);  
  SWFDisplayItem_setDepth(it3, 11); 
  SWFDisplayItem_setName(it3, "mc3"); 
  /* Define Construct ClipEvent */
  SWFDisplayItem_addAction(it3,
    compileSWFActionCode(" _root.note('mc3 Construct called');"
                         " _root.x0 += '03+'; "),
    SWFACTION_CONSTRUCT);
  /* Define Load ClipEvent */
  SWFDisplayItem_addAction(it3,
    compileSWFActionCode(" _root.note('mc3 Load called'); "
                         " _root.x1 += '5+'; "),
    SWFACTION_ONLOAD);
  /* Define Unload ClipEvent */
  SWFDisplayItem_addAction(it3,
    compileSWFActionCode(" _root.note('mc3 Unload called'); "
                         " _root.x1 += '15+';" ),
    SWFACTION_UNLOAD);
  /* Define EnterFrame ClipEvent */
  SWFDisplayItem_addAction(it3,
    compileSWFActionCode(" _root.note('mc3 EnterFrame called'); "
                         " _root.x1 += '7+'; "),
    SWFACTION_ENTERFRAME);
  
  add_actions(mo, " _root.x3 += '_root_frm2_as+'; ");
  SWFMovie_nextFrame(mo); /* 2nd frame */

  add_actions(mo, " _root.x3 += '_root_frm3_as+'; ");
  check_equals(mo, "_root.x3", "'enterFrame_called+_root_frm2_as+enterFrame_called+_root_frm3_as+'");
  SWFMovie_nextFrame(mo); /* 3rd frame */
  
  /* It's no use to change the order below.
  After compile, Ming will re-organize them as 
  remove mc1; remove mc2; remove mc3;*/
  SWFDisplayItem_remove(it3);  
  SWFDisplayItem_remove(it1);
  SWFDisplayItem_remove(it2);
  SWFMovie_nextFrame(mo); /* 4th frame */

  check_equals(mo, "_root.x0", "'01+02+03+'");
  check_equals(mo, "_root.x1", "'1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+'");
  check_equals(mo, "_root.x2", "'as_start+as_end+load_called+'");
  add_actions(mo, " _root.totals(); stop(); ");
  SWFMovie_nextFrame(mo); /* 5th frame */
  
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #24
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip dejagnuclip, static3;
  int i;
  SWFDisplayItem it1;


  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      //return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 2);

  static3 = get_static_mc(20, 20);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); 

  // Frame 2: place a static DisplayObject at depth 3 (-16381)
  it1 = SWFMovie_add(mo, (SWFBlock)static3);
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_setName(it1, "static1");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);
  SWFMovie_nextFrame(mo); 

  // Frame 3: remove DisplayObject at depth -16381 
  SWFDisplayItem_remove(it1);
  add_actions(mo, "check_equals(typeof(static1), 'undefined');"); // the replacement failed
  SWFMovie_nextFrame(mo); 
 
  // Frame 4: place same static DisplayObject at depth 3 (-16381)
  it1 = SWFMovie_add(mo, (SWFBlock)static3);
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_setName(it1, "static2");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);

  // Frame 5: jump to frame 2, stop and check
  add_actions(mo,
    "check_equals(typeof(static1), 'undefined');"
    "check_equals(typeof(static2), 'movieclip');"

    "gotoAndStop(2); " 

    // two instances were placed in total, the second instance is not
    // supposed to be removed on jump back, being on a depth supposed
    // to contain a timeline instance at that time
    // Gnash fails here by removing the instance placed in a later frame
    "check_equals(_root.depth3Constructed, 2);"

    // Gnash fails here by removing the instance placed in a later frame
    "check_equals(typeof(static1), 'undefined');"

    // Gnash fails here by removing the instance placed in a later frame
    // (thus placing a new instance)
    "check_equals(typeof(static2), 'movieclip');"

    "totals();"
    );
  SWFMovie_nextFrame(mo); 

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #25
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;
}
Пример #26
0
int
main(int argc, char **argv)
{
    SWFMovie mo;
    SWFDisplayItem it;
    const char *srcdir=".";
    char fdbfont[256];
    SWFMovieClip dejagnuclip;
    SWFFont font;

    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) {
        perror(fdbfont);
        exit(1);
    }

    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); 

    SWFMovie_nextFrame(mo);

    add_actions(mo,
            "mc1 = _root.createEmptyMovieClip('mc1', 34);"
            "mc2 = mc1.createEmptyMovieClip('mc2', 35);"
            "with(mc2) {"
            "   moveTo(100, 100);"
            "   beginFill(0x20fff0);"
            "   lineTo(100, 200);"
            "   lineTo(200, 200);"
            "   lineTo(200, 100);"
            "};"
            "_root.onMouseUp = function() { play(); };"
            );
    
    // One has all the functions, one has __resolve.
    add_actions(mo,
            "resolveevents = [];"
            "events = [];"
            "mc1.__resolve = function(a) { resolveevents.push(a); };"
            "mc2.onEnterFrame = function() { events.push('onEnterFrame'); };"
            "mc2.onMouseDown = function() { events.push('onMouseDown'); };"
            "mc2.onMouseUp = function() { events.push('onMouseUp'); };"
            // Gnash sends a bogus event here, but we're not testing that!
            //"mc2.onLoad = function() { events.push('onLoad'); };"
            "mc2.onPress = function() { events.push('onPress'); };"
            "mc2.onRelease = function() { events.push('onRelease'); };"
            "mc2.onRollOver = function() { events.push('onRollOver'); };"
            "mc2.onRollOut = function() { events.push('onRollOut'); };"
            "mc2.onInitialize = function() { events.push('onInitialize'); };"
            "mc2.onConstruct = function() { events.push('onConstruct'); };"
            "mc2.onReleaseOutside = function() { events.push('onReleaseOutside'); };"
            "mc2.onDragOver = function() { events.push('onDragOver'); };"
            "mc2.func = function() { events.push('func'); };"
    );

    add_actions(mo,
            "mc2.func();"
            "mc1.func();"
            "mc2.onEnterFrame();"
            "mc1.onEnterFrame();"
            "mc2.onRollOver();"
            "mc1.onRollOver();"
            );
    
    add_actions(mo, "_root.note('Do not touch anything!');");

    // The ones called manually should appear in both.
    check_equals(mo, "events.toString()", "'func,onEnterFrame,onRollOver'");
    check_equals(mo, "resolveevents.toString()",
            "'func,onEnterFrame,onRollOver'");

    SWFMovie_nextFrame(mo);
    
    check_equals(mo, "events.toString()",
            "'func,onEnterFrame,onRollOver,onEnterFrame'");
    check_equals(mo, "resolveevents.toString()",
            "'func,onEnterFrame,onRollOver'");
    
    // Otherwise the number is unpredictable.
    add_actions(mo, "mc2.onEnterFrame = function() {};");

    add_actions(mo, "stop();");
    add_actions(mo, "_root.note('Move over square, click and release!');");

    SWFMovie_nextFrame(mo);

    // Expect rollover, onMouseDown, onMouseUp, onRelease
    check_equals(mo, "events.toString()",
            "'func,onEnterFrame,onRollOver,onEnterFrame,"
            "onRollOver,onMouseDown,onPress,onMouseUp,onRelease'");
    check_equals(mo, "resolveevents.toString()",
            "'func,onEnterFrame,onRollOver'");

    add_actions(mo, "_root.note('Move out of square, click and release!');");
    add_actions(mo, "stop();");
    
    SWFMovie_nextFrame(mo);
    check_equals(mo, "events.toString()",
            "'func,onEnterFrame,onRollOver,onEnterFrame,onRollOver,"
            "onMouseDown,onPress,onMouseUp,onRelease,onRollOut,onMouseDown,"
            "onMouseUp'");
    check_equals(mo, "resolveevents.toString()",
            "'func,onEnterFrame,onRollOver'");
    
    add_actions(mo,
            "mevents = [];"
            "ressiz = resolveevents.length;"
            "mc2.onMouseMove = function() { mevents.push('onMouseMove'); };");
    // Last test!
    add_actions(mo, "_root.note('Move the mouse about, then click');");

    add_actions(mo, "stop();");
    
    SWFMovie_nextFrame(mo);
    // Check that mouse events aren't carried to resolve.
    check_equals(mo, "mevents[0]", "'onMouseMove'");
    check_equals(mo, "resolveevents.length", "ressiz");

    add_actions(mo, "_root.note('End of test!');");

    // Finish and save
    SWFMovie_nextFrame(mo);
    add_actions(mo, "stop();");

    puts("Saving " OUTPUT_FILENAME );
    SWFMovie_save(mo, OUTPUT_FILENAME);
     
    return 0;
}
Пример #27
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;
}
Пример #28
0
int
main(int argc, char **argv)
{
	SWFMovie mo;
	SWFInput in;
	SWFBitmap bitmap;
	SWFShape shpSmt;
	SWFShape shpHrd;
	SWFMovieClip mc;
	SWFDisplayItem it;
	int swfversion;
	SWFFont font;
	SWFMovieClip dejagnuclip;
	char outputFilename[256];
    FILE* imgfile;

	if ( argc < 2 ) {
		fprintf(stderr, "Usage: %s <swf_version>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	swfversion = atoi(argv[1]);
	sprintf(outputFilename, "BitmapSmoothingTest-v%d.swf", swfversion);

	/*********************************************
	 *
	 * Initialization
	 *
	 *********************************************/


	puts("Setting things up");

	Ming_init();
        Ming_useSWFVersion (swfversion);
 
	mo = newSWFMovieWithVersion(swfversion);

	/****************************************************
	* Create filled shapes mc
	****************************************************/
    imgfile = fopen(MEDIADIR"/vstroke.png", "rb");
    if (!imgfile) {
        fprintf(stderr, "Failed to open bitmap file");
        return EXIT_FAILURE;
    }

    // Note that recent ming version have the more convenient
    // newSWFInput_filename() function, but we want to support
    // older versions.
    in = newSWFInput_file(imgfile);
	bitmap = newSWFBitmap_fromInput(in);
	if (!bitmap) {
		return EXIT_FAILURE;
	}

	shpSmt = newSWFShapeFromBitmap(bitmap,
		SWFFILL_CLIPPED_BITMAP);

	shpHrd = newSWFShapeFromBitmap(bitmap,
		SWFFILL_NONSMOOTHED_CLIPPED_BITMAP);

	mc = newSWFMovieClip();
	SWFMovieClip_add(mc, (SWFBlock)shpSmt);
	it = SWFMovieClip_add(mc, (SWFBlock)shpHrd);
	SWFDisplayItem_moveTo(it, 0, 5);
	SWFMovieClip_nextFrame(mc); 

	/****************************************************
	* Create filled shapes mc, and scale it
	****************************************************/

	it = SWFMovie_add(mo, (SWFBlock)mc);
	SWFDisplayItem_scaleTo(it, 30, 10);

	SWFMovie_setDimension(mo, SWFBitmap_getWidth(bitmap)*30, 500);

	/****************************************************
	* Add dejagnu clip
	****************************************************/

	font = get_default_font(MEDIADIR);
	dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 200, 200);
	it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
	SWFDisplayItem_setDepth(it, 200); 
	SWFDisplayItem_move(it, 0, 100); 

	/****************************************************
	* TODO: Add actions
	****************************************************/


	/****************************************************
	* Save things up
	****************************************************/

	printf("Saving %s\n", outputFilename);

	SWFMovie_nextFrame(mo); /* showFrame */

	SWFMovie_save(mo, outputFilename);

    fclose(imgfile);

	return EXIT_SUCCESS;
}
Пример #29
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFDisplayItem  it, 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();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  // low frame rate is needed for visual checking
  SWFMovie_setRate (mo, 1.0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, 
    "test1=0; test2=0; test3=0; test4=0; test5='0'; test6=0; "
    "keyPressed=false; keyReleased=false;"
    "haslooped1=false; haslooped2=false;");
  SWFMovie_nextFrame(mo);  // _root frame1

  // test1: 
  //    (1)onKeyDown, onKeyPress and onKeyUp are not global functions
  //    (2)test that global Key object can be overridden
  //    (3)after overriden, previously registered handlers could still respond to new key events
  add_actions(mo, 
    "_root.var1 = 0; _root.var2 = 0;"
    "l = new Object();"
    "l.onKeyDown = function () { _root.note('l.onKeyDown'); _root.var1+=1; _root.Play(); }; "
    "l.onKeyUp = function () { _root.note('l.onKeyUp'); _root.var2+=1;}; "
    " Key.addListener(l);"
    "check_equals(typeof(Key), 'object');"
    "check_equals(typeof(onKeyUp), 'undefined');"
    "check_equals(typeof(onKeyDown), 'undefined');"
    "check_equals(typeof(onKeyPress), 'undefined');"
    "stop();"
    "_root.note('1. Press a single key to continue the test');"
  );
  SWFMovie_nextFrame(mo);  // _root frame2

  SWFMovie_nextFrame(mo);  // _root frame3
  
  add_actions(mo, 
    "stop();"
    "check_equals(var1, 1); "
    "check_equals(var2, 1); "
    "Key = 3;"
    "check_equals(typeof(Key), 'number');"
    "_root.note('2. Press a single key to continue the test');"
    );
  SWFMovie_nextFrame(mo);  // _root frame4
  
  SWFMovie_nextFrame(mo);  // _root frame5
  
  add_actions(mo,
    "stop();"
    "check_equals(var1, 2); "
    "check_equals(var2, 2);"
    "delete Key; "
    "check_equals(typeof(Key), 'object');"
    "Key.removeListener(l);"
    "_root.note('3. Press a single key to continue the test');"
    "obj1=new Object(); "
    " obj1.onKeyDown=function() {"
    "   _root.note('obj1.onKeyDown');"
    "   _root.play();"
    "}; "
    " Key.addListener(obj1); "
  );
  SWFMovie_nextFrame(mo);  // _root frame6
   
  add_actions(mo, 
    "check_equals(var1, 2);"
    "check_equals(var2, 2);"
    "Key.removeListener(obj1);"
    "delete l; delete obj1; "
  );
  SWFMovie_nextFrame(mo);  // _root frame7
  
  // test2:
  //    test removing of static clip key listeners
  SWFMovie_nextFrame(mo);  // _root frame8
  
  it = add_static_mc(mo, "listenerClip1", 20);
  SWFDisplayItem_addAction(it,
    newSWFAction(" _root.note('listenerClip2.onClipKeyDown'); "
                 " _root.test2++; "
                 "if(!_root.haslooped1){"
                 "   _root.haslooped1=true;"
                 "   _root.gotoAndPlay(_root._currentframe-1);"
                 "} else {"
                 "   _root.gotoAndPlay(_root._currentframe+1);"
                 "}"
                ), 
    SWFACTION_KEYDOWN);  
  add_actions(mo,
    "stop();"
    "_root.note('4. Press a single key to continue the test');"
  );
  SWFMovie_nextFrame(mo);  // _root frame9
  
  check_equals(mo, "_root.test2", "2");
  SWFDisplayItem_remove(it);
  SWFMovie_nextFrame(mo);  // _root frame10
  
  
  // test3:
  //    test removing of dynamic sprite key listeners 
  SWFMovie_nextFrame(mo);  // _root frame11
  
  add_actions(mo, 
    "stop();"
    "_root.note('5. Press a single key to continue the test');"
    "_root.createEmptyMovieClip('dynamic_mc', -10);"
    "dynamic_mc.onKeyDown = function() "
    "{"
    "   _root.note('dynamic_mc.onKeyDown triggered');"
    "   _root.check_equals(this, _root.dynamic_mc);"
    "   _root.test3++;"
    "   if(!_root.haslooped2){"
    "       _root.haslooped2=true;"
    "       _root.gotoAndPlay(_root._currentframe-1);"
    "       _root.check_equals(_root._currentframe, 11);"
    "   } else {"
    "       _root.gotoAndPlay(_root._currentframe+1);"
    "       _root.check_equals(_root._currentframe, 13);"
    "   }"
    "};"
    "Key.addListener(dynamic_mc);"
  );
  SWFMovie_nextFrame(mo);  // _root frame12
  
  check_equals(mo, "_root.test3", "2");
  add_actions(mo, "dynamic_mc.swapDepths(10);  dynamic_mc.removeMovieClip();");
  SWFMovie_nextFrame(mo);  // _root frame13
  
  // test4:
  //    GC test
  add_actions(mo, 
    "_root.note('6. Press a single key to continue the test');"
    " obj2 = new Object(); "
    " obj2.x = 100; "
    " obj2.onKeyDown = function () { "
    "   _root.note('obj2.onKeyDown triggered');"
    "   _root.test4++; "
    "   _root.objRef = this; "
    "   _root.play();"
    " };" 
    " Key.addListener(obj2); "
    // After deleting obj2, we still have a key listener kept alive!
    " delete obj2; "
    " stop();"
  );
  check_equals(mo, "_root.test4", "0");
  SWFMovie_nextFrame(mo);  // _root frame14
  
  check_equals(mo, "objRef.x", "100");
  check_equals(mo, "_root.test4", "1");
  add_actions(mo,
    "stop();"
    "_root.note('7. Press a single key to continue the test');"
    "Key.removeListener(objRef); "
    // check that objRef is still alive
    "check_equals(typeof(objRef), 'object');"
    // delete the objRef, no object and no key listener now.
    "delete objRef;"
    "obj3=new Object(); "
    "obj3.onKeyDown=function() {"
    "   _root.note('obj3.onKeyDown');"
    "   _root.gotoAndPlay(_currentframe+1);"
    "}; "
    "Key.addListener(obj3); "
  );
  SWFMovie_nextFrame(mo);  // _root frame15
  
  check_equals(mo, "_root.test4", "1");
  add_actions(mo, 
    "Key.removeListener(obj3);"
    "delete obj3; "
  );
  SWFMovie_nextFrame(mo);  // _root frame16

  // test5:
  //   test key listeners invoking order.
  //   expected behaviour:
  //   (1)for DisplayObject key listeners, first added last called
  //   (2)for general object listeners, first added first called
  //   (3)for DisplayObject listeners, user defined onKeyDown/Up won't be called
  //      if not registered to the global Key object.
  it1 = add_static_mc(mo, "ls1", 30);
  SWFDisplayItem_addAction(it1,
    compileSWFActionCode(
       "_root.note('ls1.onClipKeyDown');"
       "_root.test5 += '+ls1';"
    ),
    SWFACTION_KEYDOWN);
  SWFMovie_nextFrame(mo);  // _root frame17
  
  it2 = add_static_mc(mo, "ls2", 31);
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(
       "_root.note('ls2.onClipKeyDown');"
       "_root.test5 += '+ls2';"
    ),
    SWFACTION_KEYDOWN);
  SWFMovie_nextFrame(mo);  // _root frame18
   
  it3 = add_static_mc(mo, "ls3", 29);
  SWFDisplayItem_addAction(it3,
    compileSWFActionCode(
       "_root.note('ls3.onClipKeyDown');"
       "_root.test5 += '+ls3';"
    ),
    SWFACTION_KEYDOWN);
  SWFMovie_nextFrame(mo);  // _root frame19

  add_actions(mo, 
    "obj1=new Object();"
    "obj1.onKeyDown = function () { "
    "  _root.note('obj1.onKeyDown');"
    "  _root.test5 += '+obj1'; "
    "  _root.gotoAndPlay(_root._currentframe+1);"
    "}; "
    "Key.addListener(obj1);"
    "ls1.onKeyDown = function () {"
    "  _root.note('ls1.onKeyDown');"
    "  _root.test5 += '+ls1';"
    "}; "
    "Key.addListener(ls1);"
    "obj2=new Object();"
    "obj2.onKeyDown = function () {"
    "  _root.note('obj2.onKeyDown');"
    "  _root.test5 += '+obj2';"
    "}; "
    "Key.addListener(obj2);"
    "ls2.onKeyDown = function () {"
    "  _root.note('ls2.onKeyDown');"
    "  _root.test5 += '+ls2';"
    "}; "
    "Key.addListener(ls2);"
    "obj3=new Object();"
    "obj3.onKeyDown = function () {"
    "  _root.note('obj3.onKeyDown');"
    "  _root.test5 += '+obj3';"
    "}; "
    "Key.addListener(obj3);"
    "ls3.onKeyDown = function () {"
    "  _root.note('ls3.onKeyDown');"
    "  _root.test5 += '+ls3';"
    "}; "
    "stop(); "
    "_root.note('8. Press a single key to continue the test');"
  );
  SWFMovie_nextFrame(mo);  // _root frame20

  SWFMovie_nextFrame(mo);  // _root frame21
  
  add_actions(mo,
    "stop(); "
    "_root.note('9. Press a single key to continue the test');"
  );
  SWFDisplayItem_remove(it1);
  SWFDisplayItem_remove(it2);
  SWFDisplayItem_remove(it3);
  SWFMovie_nextFrame(mo);  // _root frame22
 
  check_equals(mo, "test5", "'0+ls3+ls2+ls1+obj1+ls1+obj2+ls2+obj3+obj1+obj2+obj3'");

  add_actions(mo,
     "o = new Object();"
     "_root.t = '';"
     "o.onKeyDown = function() { t = _root.ff.text; play(); };"
     "Key.addListener(o);"
     "_root.createTextField('ff', 987, 300, 20, 200, 40);"
     "_root.ff.type = 'input';"
     "_root.ff.text = 'Input here';"
     "_root.ff.border = true;"
    "_root.note('10. Click on the TextField and type \"i\"');"
    "stop();"
  );
  
  SWFMovie_nextFrame(mo);  // _root frame23

  // The listener is called before text is updated!
  check_equals(mo, "_root.t", "'Input here'");
  check_equals(mo, "_root.ff.text", "'Input herei'");


  add_actions(mo, "totals(); stop();");
  SWFMovie_nextFrame(mo);  // _root frame24
  //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;
}