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;
}
Exemple #2
0
	/*
     * device_NewPage is called whenever a new plot requires
     * a new page.
     * A new page might mean just clearing the
     * device (e.g., X11) or moving to a new page
     * (e.g., postscript)
     *
     */
static void SWF_NewPage( const pGEcontext plotParams, pDevDesc deviceInfo ){
	
	/* Shortcut pointers to variables of interest. */
	swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific;
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,
			"SWF_Newpage: Starting new frame\n");
		fflush(swfInfo->logFile);
	}
	
	if(!(swfInfo->nFrames == 0)){
		/*
		 * Add a new frame to the current movie.
		 * This function adds a new frame to the current movie. 
		 * All items added, removed
		 * manipulated effect this frame and probably following frames.
		 */
		SWFMovie_nextFrame( swfInfo->m );
		
		/*Wipe the slate clean:
		 * nextFrame draws all the ojects and then advances the frame
		 * so remove all the objects in the display list and start over.
		 * 
		 * This addresses a difference in the drawing model of Ming and 
		 * R.  Ming wants to set up objects, save them and move them around 
		 * later which makes sense in flash.  It assumes you want to keep 
		 * those objects in the next frame. R wants to draw a shape and 
		 * forget about it.  Hence the voodoo with the linked list and 
		 * storing the display items in the current frame. 
		*/
		while (swfInfo->displayListHead) {
			swfInfo->displayListTail = swfInfo->displayListHead->next;
			SWFDisplayItem_remove(swfInfo->displayListHead->d);
			free(swfInfo->displayListHead);
			swfInfo->displayListHead = swfInfo->displayListTail;
		}
	}
	swfInfo->nFrames++;
	/*if(swfInfo->haveControls == TRUE){
		SWF_addPlayerControls(&swfInfo->ControlsX,&swfInfo->ControlsY);
	}*/
	
}
Exemple #3
0
/* 
 * Removes a SWFDisplayItem from the movieclips stage.
 * A SWFDisplayItem stays on stage until it gets removed. This function 
 * removes the item. The item is displayed until the current frame.
 */
void
SWFMovieClip_remove(SWFMovieClip clip, SWFDisplayItem item)
{
	SWFDisplayItem_remove(item);
}
Exemple #4
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip mc1, mc2, dejagnuclip;
  SWFDisplayItem it1, it2;
  SWFShape  sh1,sh2;

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

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
  
  mo = newSWFMovie();
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate(mo, 6);

  // Frame 1: Place dejagnu clip

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, "mc1Constructed=0; mc2Constructed=0; mc3Constructed=0; mc4Constructed=0;");
  SWFMovie_nextFrame(mo); 
  
  //
  // Frame 2: 
  //   Place red static movieClip1 DisplayObject at depth 3 (-16381)
  //   Place black static movieClip1 DisplayObject at depth 4 (-16380)
  //
  sh1 = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  mc1 = newSWFMovieClip();
  SWFMovieClip_add(mc1, (SWFBlock)sh1); 
  SWFMovieClip_nextFrame(mc1);
  
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  //add movieClip1 to the _root
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_setName(it1, "movieClip1"); //name movieClip1
  SWFDisplayItem_addAction(it1, newSWFAction(
    "_root.note(this+' constructed');"
    "_root.mc1Constructed++;"
    ), SWFACTION_CONSTRUCT);


  sh2 = make_fill_square (330, 270, 120, 120, 0, 0, 0, 0, 0, 0);
  mc2 = newSWFMovieClip();
  SWFMovieClip_add(mc2, (SWFBlock)sh2);  
  SWFMovieClip_nextFrame(mc2); 

  it2 = SWFMovie_add(mo, (SWFBlock)mc2);  //add movieClip2 to the _root
  SWFDisplayItem_setDepth(it2, 4);
  SWFDisplayItem_setName(it2, "movieClip2"); //name movieClip2
  SWFDisplayItem_addAction(it2, newSWFAction(
    "_root.note(this+' constructed');"
    "_root.mc2Constructed++;"),
      SWFACTION_CONSTRUCT);
  
  SWFMovie_nextFrame(mo);  

  // Frame3: nothing new
  SWFMovie_nextFrame(mo);  
  
  // Frame4: remove "movieClip1" and "movieClip2"
  
  SWFDisplayItem_remove(it1);
  SWFDisplayItem_remove(it2);
  SWFMovie_nextFrame(mo); 
  
  //
  // Frame5: 
  //   Place red static movieClip3 DisplayObject at depth 3 (-16381) with ratio set to 2.0
  //   Place black static movieClip4 DisplayObject at depth4 (-16380) with ratio set to 0.0
  //

  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  //add movieClip3 to the _root
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_setName(it1, "movieClip3"); //name movieClip3
  SWFDisplayItem_setRatio(it1, 2.0); // It's important to set this, don't why yet.
  SWFDisplayItem_addAction(it1, newSWFAction(
    "_root.note(this+' constructed');"
    "_root.mc3Constructed++;"
    ), SWFACTION_CONSTRUCT);
  
  it2 = SWFMovie_add(mo, (SWFBlock)mc2);  //add movieClip4 to the _root
  SWFDisplayItem_setDepth(it2, 4);
  SWFDisplayItem_setName(it2, "movieClip4"); //name movieClip4
  SWFDisplayItem_setRatio(it2, 0.0); // It's important to set this, don't why yet.
  SWFDisplayItem_addAction(it2, newSWFAction(
    "_root.note(this+' constructed');"
    "_root.mc4Constructed++;"
    ), SWFACTION_CONSTRUCT);
  
  SWFMovie_nextFrame(mo); 
  
  //
  // Frame4: check, gotoAndStop(3), check..
  //
  check_equals(mo, "typeof(movieClip1)", "'undefined'");
  check_equals(mo, "typeof(movieClip2)", "'undefined'");
  check_equals(mo, "typeof(movieClip3)", "'movieclip'");
  check_equals(mo, "typeof(movieClip4)", "'movieclip'");
  check_equals(mo, "_root.mc1Constructed", "1");
  check_equals(mo, "_root.mc2Constructed", "1");
  check_equals(mo, "_root.mc3Constructed", "1");
  check_equals(mo, "_root.mc4Constructed", "1");
  
  SWFMovie_add(mo, (SWFBlock)newSWFAction( "gotoAndStop(3);"));
  
  check_equals(mo, "typeof(movieClip1)", "'movieclip'");
  check_equals(mo, "typeof(movieClip2)", "'undefined'");
  // the difference of movieClip3 and movieClip4 was caused by the ratio value
  check_equals(mo, "typeof(movieClip3)", "'undefined'");
  check_equals(mo, "typeof(movieClip4)", "'movieclip'");
  check_equals(mo, "_root.mc1Constructed", "2");
  check_equals(mo, "_root.mc2Constructed", "1");
  check_equals(mo, "_root.mc3Constructed", "1");
  check_equals(mo, "_root.mc4Constructed", "1");
  
  SWFMovie_add(mo, (SWFBlock)newSWFAction( "totals(); stop();" ));
  SWFMovie_nextFrame(mo);

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

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

  /* For the button duplication test */
#if MING_VERSION_CODE >= 00040400
  SWFButton but;
  SWFButtonRecord br;
#endif

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

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

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

  
  mc1 = newSWFMovieClip();
  sh_red = make_fill_square (100, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc1, (SWFBlock)sh_red);  
  add_clip_actions(mc1, "stop();");
  SWFMovieClip_nextFrame(mc1);

  mc2 = newSWFMovieClip();
  sh_red = make_fill_square (100, 200, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc2, (SWFBlock)sh_red);  
  add_clip_actions(mc2, "stop();");
  SWFMovieClip_nextFrame(mc2);

  it1 = SWFMovie_add(mo, (SWFBlock)mc1); 
  SWFDisplayItem_setDepth(it1, 10); 
  SWFDisplayItem_setName(it1, "mc1"); 

  it2 = SWFMovie_add(mo, (SWFBlock)mc2); 
  SWFDisplayItem_setDepth(it2, 20); 
  SWFDisplayItem_setName(it2, "mc2"); 
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(" _root.note('onClipLoad triggered'); "
                         " _root.x1 = _root.x1 + 1; "),
    SWFACTION_ONLOAD);  
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(" _root.note('onClipEnterFrame triggered'); "
                         " _root.x2 = _root.x2 + 1; "),
    SWFACTION_ENTERFRAME);  
  SWFDisplayItem_addAction(it2,
    compileSWFActionCode(" _root.note('onClipUnload triggered'); "
                         " _root.x3 = _root.x3 + 1; "),
    SWFACTION_UNLOAD); 

  add_actions(mo, " mc1.onLoad = function () {}; "
                  " mc1.prop1 = 10; "
                  " duplicateMovieClip('mc1', 'dup1', 1); "
                  " mc2.onLoad = function () {}; "
                  " duplicateMovieClip('mc2', 'dup2', 2); " );
  SWFMovie_nextFrame(mo); /* 2nd frame */
  
  
  check_equals(mo, "mc1.prop1", "10");
  check_equals(mo, "typeof(mc1.onLoad)", "'function'");
  check_equals(mo, "mc1.getDepth()", "-16374");
  /* user defined property will not be duplicated */
  check_equals(mo, "dup1.prop1", "undefined");  
  /* user defined event handler will not be duplicated */
  check_equals(mo, "typeof(dup1.onLoad)", "'undefined'"); 
  check_equals(mo, "dup1.getDepth()", "1");
  /* check user defined onLoad */
  check_equals(mo, "typeof(mc2.onLoad)", "'function'");
  /* onClipEvent does not define a function */
  check_equals(mo, "typeof(mc2.onEnterFrame)", "'undefined'");
  /* user defined event handler will not be duplicated */
  check_equals(mo, "typeof(dup2.onLoad)", "'undefined'"); 
  check_equals(mo, "_root.x1", "2");
  check_equals(mo, "_root.x2", "2");
  SWFMovie_nextFrame(mo); /* 3rd frame */
  
  SWFDisplayItem_remove(it1);
  SWFDisplayItem_remove(it2);
  add_actions(mo, " dup2.removeMovieClip(); ");

  SWFMovie_nextFrame(mo); /* 4th frame */
  
#if MING_VERSION_CODE >= 00040400

  /* Create a button, add it to mc1 */
  but = newSWFButton();
  br = SWFButton_addCharacter(but, (SWFCharacter)sh_red, SWFBUTTON_UP);
  SWFButtonRecord_setDepth(br, 10);
  it1 = SWFMovie_add(mo, (SWFBlock)but);
  SWFDisplayItem_setName(it1, "button");

  /* Sanity check */
  check_equals(mo, "typeof(button)", "'object'");

  add_actions(mo,
          "trace(button);"
          "dupl = MovieClip.prototype.duplicateMovieClip;"
          "button.dupl = dupl;"
          "o = { x: 4 };"
          "d = button.dupl('buttdup', 201, o);"
          );
  
  xcheck_equals(mo, "typeof(d)", "'object'");
  xcheck_equals(mo, "'' + _root.buttdup", "'_level0.buttdup'");
  check_equals(mo, "_root.buttdup", "d");
  
  /* initobj not used */
  check_equals(mo, "_root.buttdup.x", "undefined");
#endif

  add_actions(mo,
          "t = new Object();"
          "t.dupl = dupl;"
          "o2 = { x: 44 };"
          "d2 = t.dupl('objdup', 202, o2);"
          "trace(_root.objdup);"
          );

  /* Does not work on plain objects */
  check_equals(mo, "typeof(d2)", "'undefined'");
  check_equals(mo, "typeof(_root.objdup)", "'undefined'");

  SWFMovie_nextFrame(mo); /* 5th frame */

  check_equals(mo, "_root.x1", "2");
  check_equals(mo, "_root.x2", "3");
  check_equals(mo, "_root.x3", "2");  
  add_actions(mo, " _root.totals(); stop(); ");
  SWFMovie_nextFrame(mo); /* 5th frame */
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

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

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

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

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

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

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

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

  return 0;
}
Exemple #7
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;
}
Exemple #8
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFDisplayItem it1, it2, it3;
  SWFDisplayItem it41;
  SWFDisplayItem it51;
  SWFMovieClip mc1, mc2, mc3, dejagnuclip;
  SWFMovieClip mc4, mc41;
  SWFMovieClip mc5, mc51;
  SWFShape  sh1, sh2, sh3;

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

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
  
  mo = newSWFMovie();
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate(mo, 12);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, " haslooped1=false; haslooped2=false; haslooped3=false;"
                  " mc1Initialized=0; mc1Unloaded=0;"
                  " mc2Initialized=0; mc2Unloaded=0;"
                  " mc3Initialized=0; mc3Unloaded=0;"
                  " asOrder='0+';");
  SWFMovie_nextFrame(mo); // frame1


  sh1 = make_fill_square (100, 100, 60, 60, 255, 0, 0, 255, 0, 0);
  mc1 = newSWFMovieClip();
  SWFMovieClip_add(mc1, (SWFBlock)sh1); 
  SWFMovieClip_nextFrame(mc1);
  
  sh2 = make_fill_square (200, 200, 60, 60, 0, 0, 0, 0, 0, 0);
  mc2 = newSWFMovieClip();
  SWFMovieClip_add(mc2, (SWFBlock)sh2);  
  SWFMovieClip_nextFrame(mc2); 

  sh3 = make_fill_square (300, 300, 60, 60, 0, 0, 0, 0, 0, 0);
  mc3 = newSWFMovieClip();
  SWFMovieClip_add(mc3, (SWFBlock)sh3);  
  SWFMovieClip_nextFrame(mc3); 
 
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  
  SWFDisplayItem_setName(it1, "mc1"); 
  SWFDisplayItem_setDepth(it1, 100); 
  SWFDisplayItem_addAction(it1, newSWFAction(
        "_root.note(this+' initialized');"
        "_root.mc1Initialized++;"
        "_root.asOrder += '1+';"
        ), SWFACTION_INIT); 
  SWFDisplayItem_addAction(it1, newSWFAction(
        "_root.note(this+' unloaded');"
        "_root.mc1Unloaded++;"
        "_root.asOrder += '3+';"
        ), SWFACTION_UNLOAD);
  SWFMovie_nextFrame(mo); // frame2
  
    
  SWFDisplayItem_remove(it1);
  it2 = SWFMovie_add(mo, (SWFBlock)mc2); 
  SWFDisplayItem_setName(it2, "mc2"); 
  SWFDisplayItem_setRatio(it2, 0.1); 
  SWFDisplayItem_setDepth(it2, 100); 
  SWFDisplayItem_addAction(it2, newSWFAction(
        "_root.note(this+' initialized');"
        "_root.mc2Initialized++;"
        "_root.asOrder += '2+';"
        ), SWFACTION_INIT);
  SWFDisplayItem_addAction(it2, newSWFAction(
        "_root.note(this+' unloaded');"
        "_root.mc2Unloaded++;"
        "_root.asOrder += '5+';"
        ), SWFACTION_UNLOAD);
  SWFMovie_nextFrame(mo);  // frame3


  SWFDisplayItem_remove(it2);
  it3 = SWFMovie_add(mo, (SWFBlock)mc3); 
  SWFDisplayItem_setName(it3, "mc3"); 
  SWFDisplayItem_setRatio(it3, 0.2); 
  SWFDisplayItem_setDepth(it3, 100); 
  SWFDisplayItem_addAction(it3, newSWFAction(
        "_root.note(this+' initialized');"
        "_root.mc3Initialized++;"
        "_root.asOrder += '4+';"
        ), SWFACTION_INIT);
  SWFDisplayItem_addAction(it3, newSWFAction(
        "_root.note(this+' unloaded');"
        "_root.mc3Unloaded++;"
        ), SWFACTION_UNLOAD);
  SWFMovie_nextFrame(mo);  // frame4


  SWFMovie_nextFrame(mo);  // frame 5

  
  add_actions(mo, "if(! haslooped1) {"
                  "   gotoAndPlay(5);"
                  "   haslooped1 = true;"
                  "}" );
  SWFMovie_nextFrame(mo);  // frame 6
  
  
  check_equals(mo, "mc1Initialized", "2");
  check_equals(mo, "mc2Initialized", "2");
  check_equals(mo, "mc3Initialized", "1");
  check_equals(mo, "mc1Unloaded", "2");
  check_equals(mo, "mc2Unloaded", "2");
  check_equals(mo, "mc3Unloaded", "0");
  
  xcheck_equals(mo, "asOrder", "'0+1+2+3+4+5+1+2+3+5+'");
  SWFMovie_nextFrame(mo);  // frame 7
  
  //
  // ==case 2==
  //
  mc4 = newSWFMovieClip();
    mc41 = newSWFMovieClip(); 
    SWFMovieClip_nextFrame(mc41);
    
    it41 = SWFMovieClip_add(mc4, (SWFBlock)mc41); 
    add_clip_actions(mc4, 
        "_root.check_equals(this._target, '/instance3');"
        "inst = this.getInstanceAtDepth(-16383);"
        "if(! haslooped2) {"
        "   haslooped2 = true;"
        "   _root.check_equals(inst._target, '/instance3/instance4');"
        "} else {"
        "   _root.check_equals(inst._target, '/instance3/instance5');"
        "   stop();"
        "}"
   );
  SWFMovieClip_nextFrame(mc4);
    SWFDisplayItem_remove(it41);
  SWFMovieClip_nextFrame(mc4);  
  
  SWFMovie_add(mo, mc4);
  SWFMovie_nextFrame(mo);  // frame 9
  
  SWFMovie_nextFrame(mo);  // frame 10
  
  //
  // ==case 3==
  //
  mc5 = newSWFMovieClip();
    mc51 = newSWFMovieClip(); 
    SWFMovieClip_nextFrame(mc51);
    
    it51 = SWFMovieClip_add(mc5, (SWFBlock)mc51); 
    add_clip_actions(mc5, 
        "_root.check_equals(this._target, '/instance6');"
        "inst = this.getInstanceAtDepth(-16383);"
        "if(! haslooped3) {"
        "   haslooped3 = true;"
        "   _root.check_equals(inst._target, '/instance6/instance7');"
        "} else {"
        "   _root.check_equals(inst._target, '/instance6/instance7');"
        "   stop();"
        "}"
   );
  SWFMovieClip_nextFrame(mc5);
  SWFMovieClip_nextFrame(mc5); 
  
  SWFMovie_add(mo, mc5);
  SWFMovie_nextFrame(mo);  // frame 11
  
  SWFMovie_nextFrame(mo);  // frame 12
  
  SWFMovie_nextFrame(mo);  // frame 13
  
  mc5 = newSWFMovieClip();
  add_clip_actions(mc5, "_root.check_equals(this._target, '/instance9');");
  SWFMovieClip_nextFrame(mc5);
  
  SWFMovie_add(mo, mc5);
  SWFMovie_nextFrame(mo);  // frame 14
  
  add_actions(mo, "totals(16); stop();");
  SWFMovie_nextFrame(mo);  // frame 15
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Exemple #9
0
int
main(int argc, char** argv)
{
  
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFMorph morph;
  SWFShape startShape, endShape;
  SWFDisplayItem it;
  float ratio;


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

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

  // _root.frame2, define and place a morph
  morph =  newSWFMorphShape();
  startShape = SWFMorph_getShape1(morph);
  make_shape(startShape, 0, 0, 100, 100, 255, 0 ,0);
  endShape = SWFMorph_getShape2(morph);
  make_shape(endShape, 700, 500, 100, 100, 0, 255 ,0);

  it = SWFMovie_add(mo, (SWFBlock)morph); 
  SWFMovie_nextFrame(mo); 
  
  // update the morph with different ratios
  for(ratio=0.2; ratio<1.01; ratio+=0.2)
  {
     SWFDisplayItem_remove(it);
     it = SWFMovie_add(mo, (SWFBlock)morph);
     SWFDisplayItem_setRatio(it, ratio);
     SWFMovie_nextFrame(mo);     
  }

  /* Test for #39989 by adding an empty morph shape. */
  morph = newSWFMorphShape();
  startShape = SWFMorph_getShape1(morph);
  endShape = SWFMorph_getShape2(morph);
  it = SWFMovie_add(mo, (SWFBlock)morph);
  SWFMovie_nextFrame(mo);
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Exemple #10
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;
}
Exemple #11
0
EXPORT BOOL WINAPI i_remove(int p1, int p2, int p3, int p4)
{
	lstrcpy(funcname, "i_remove");
	SWFDisplayItem_remove(mhsp_item);
	return 0;
}
Exemple #12
0
/// This test checks the event order of key events.
//
/// Known listeners are:
/// 1. MovieClips with a defined key event
/// 2. Button with a defined key event
/// 3. Anything added to Key listeners in ActionScript.
//
/// The test adds objects in this order:
//
/// Frame 1:
/// 1. mc1
/// 3. button1 (responds to 'a')
/// 3. o1 (actionscript key listener object)
/// 4. mc2
///
/// Frame 2:
/// 5. button2 (responds to 'a')
/// 6. button3 (responds to 'b')
/// 3. o2 (actionscript key listener object)
//
/// The test shows that, irrespective of construction order:
/// 1. MovieClips are notified first
/// 2. ActionScript listeners are notified second.
/// 3. Buttons are notified last.
//
/// Additionally:
//
/// 1. Only one button action can respond to any key.
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip mc, dejagnuclip;
  SWFButtonRecord br;
  SWFButton bu;
  SWFDisplayItem it1, it, it2;
  SWFShape sh1, sh2;

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

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

  SWFMovie_setRate (mo, 12.0);

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

  SWFMovie_nextFrame(mo);

  add_actions(mo,
          "_root.order = '';"
          "_root.note('Press \"a\" then \"b\"');"
          "_root.note('Do not press any other keys!');"
          );

  mc = newSWFMovieClip();
  it = SWFMovie_add(mo, (SWFBlock)mc);
  SWFDisplayItem_setName(it, "mc1");
  SWFDisplayItem_addAction(it,
          newSWFAction("trace('mc1'); _root.order += 'mc1,';"),
          SWFACTION_KEYDOWN);

  bu = newSWFButton();
  
  sh1 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 0, 0);
  sh2 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 255, 0);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
  SWFButtonRecord_setDepth(br, 3);
  
  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
  SWFButtonRecord_setDepth(br, 4);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
  SWFButtonRecord_setDepth(br, 5);

  SWFButton_addAction(bu,
          newSWFAction("trace('button1'); _root.order += 'button1,';"),
		  SWFBUTTON_KEYPRESS('a'));

  it1 = SWFMovie_add(mo, (SWFBlock)bu);
  SWFDisplayItem_setName(it, "button1");

  SWFMovie_add(mo, newSWFAction(
              "o1 = {};"
              "o1.onKeyDown = function() {"
              "    trace('o1'); "
              "    _root.order += 'o1,';"
              "};"
              "Key.addListener(o1);"
              ));

  mc = newSWFMovieClip();
  it = SWFMovie_add(mo, (SWFBlock)mc);
  SWFDisplayItem_setName(it, "mc2");
  SWFDisplayItem_addAction(it,
          newSWFAction("trace('mc2'); _root.order += 'mc2,';"),
          SWFACTION_KEYDOWN);

  SWFMovie_nextFrame(mo); // Frame 2

  bu = newSWFButton();
  
  sh1 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 0, 0);
  sh2 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 255, 0);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
  SWFButtonRecord_setDepth(br, 3);
  
  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
  SWFButtonRecord_setDepth(br, 4);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
  SWFButtonRecord_setDepth(br, 5);

  SWFButton_addAction(bu,
          newSWFAction("trace('button2'); _root.order += 'button2,';"),
		  SWFBUTTON_KEYPRESS('a'));

  it2 = SWFMovie_add(mo, (SWFBlock)bu);
  SWFDisplayItem_setName(it, "button2");
  
  bu = newSWFButton();
  
  sh1 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 0, 0);
  sh2 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 255, 0);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
  SWFButtonRecord_setDepth(br, 3);
  
  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
  SWFButtonRecord_setDepth(br, 4);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
  SWFButtonRecord_setDepth(br, 5);

  SWFButton_addAction(bu,
          newSWFAction(
              "trace('button3'); "
              "_root.order += 'button3,';"
              "play();"
              ),
		  SWFBUTTON_KEYPRESS('b'));

  it = SWFMovie_add(mo, (SWFBlock)bu);
  SWFDisplayItem_setName(it, "button3");
  
  SWFMovie_add(mo, newSWFAction(
              "o2 = {};"
              "o2.onKeyDown = function() {"
              "    trace('o2'); "
              "    _root.order += 'o2,';"
              "};"
              "Key.addListener(o2);"
              "stop();"
              ));

  SWFMovie_nextFrame(mo);

  xcheck_equals(mo, "_root.order",
          "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");
  
  SWFMovie_nextFrame(mo);

  SWFDisplayItem_remove(it2);
  
  add_actions(mo,
          "_root.order = '';"
          "_root.note('Press \"a\" then \"b\" again');"
          "_root.note('Do not press any other keys!');"
          "stop();"
          );
  SWFMovie_nextFrame(mo);

  // Check that removing the second button associated with 'a' does not
  // remove the key trigger for button2. There's no reason to think it should,
  // but it could happen if it's implemented badly!
  check_equals(mo, "_root.order",
          "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");

  SWFMovie_add(mo, newSWFAction("stop();"));

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

  return 0;
}
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip  mc1, mc2, dejagnuclip;
  SWFDisplayItem it1, it2;
  
  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, "testvar1 = 0; testvar2 = 0;");
  SWFMovie_nextFrame(mo); // frame1
  

  mc1 = newSWFMovieClip();
  SWFMovieClip_nextFrame(mc1);
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  
  SWFDisplayItem_setName(it1, "static_mc1");
  SWFDisplayItem_addAction(it1,
    newSWFAction(
        " this.createEmptyMovieClip('dyn1', 100); "
        " _root.check_equals(dyn1.getDepth(), 100);"
        " _root.dyn1Ref = dyn1;"
        // shouldn't be executed.
        " dyn1.onUnload = function () { _root.check(false); } ;"
        "trace(this);"
    ),
    SWFACTION_UNLOAD);  
  
  mc2 = newSWFMovieClip();
  SWFMovieClip_nextFrame(mc2);
  it2 = SWFMovie_add(mo, (SWFBlock)mc2);  
  SWFDisplayItem_setName(it2, "static_mc2");
  SWFDisplayItem_addAction(it2,
    newSWFAction(
       " this.createEmptyMovieClip('dyn2', 200); "
       " _root.check_equals(dyn2.getDepth(), 200);"
       " dyn2.onUnload = function () {_root.dyn2testvar = 'executed'; } ;"
    ),
    SWFACTION_ONLOAD);  
  SWFDisplayItem_addAction(it2,
    newSWFAction(
      " _root.check_equals(_level0.dyn1Ref.getDepth(), 100);"
      " _level0.dyn1Ref.swapDepths(101); "
      // Check that we can still swap the new child created in onClipUnload(mc1)
      // Note mc1 is already unloaded(this is in mc2.unload).
      " _root.check_equals(_level0.dyn1Ref.getDepth(), 101);"
    ),
    SWFACTION_UNLOAD); 
  SWFMovie_nextFrame(mo); // frame2

  SWFDisplayItem_remove(it1);
  SWFDisplayItem_remove(it2);
  SWFMovie_nextFrame(mo); // frame3
  
  check_equals(mo, "typeof(_root.dyn1Ref)", "'movieclip'");
  check_equals(mo, "_root.dyn1Ref.valueof()", "null");
  // check that dyn2.onUnload was triggered
  check_equals(mo, "_root.dyn2testvar", "'executed'");
  SWFMovie_nextFrame(mo); // frame4

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

  return 0;
}
Exemple #14
0
int main(int argc, char* argv[])
{

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

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

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

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

    SWFMovie_nextFrame(mo);

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

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

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

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

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

    // Frame 2
    SWFMovieClip_nextFrame(mc3);

    // Remove mc2
    SWFDisplayItem_remove(it);

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

    SWFMovieClip_nextFrame(mc3);

    // End mc3


    // This is frame 1 of the main timeline

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

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

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

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

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

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

    // SWF_END 
    SWFMovie_save(mo, OUTPUT_FILENAME);

    return 0;
}
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip 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;
}
Exemple #16
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;
}
Exemple #17
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip mc1, mc2, mc3, dejagnuclip;
  SWFShape  sh1, sh2, sh3;
  SWFDisplayItem it1, it2, it3;

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

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

  // Frame 1: Place dejagnu clip

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

  // Frame 2: Place two static DisplayObjects

  sh1 = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  mc1 = newSWFMovieClip();
  SWFMovieClip_add(mc1, (SWFBlock)sh1); 
  SWFMovieClip_nextFrame(mc1);
  
  sh2 = make_fill_square (330, 270, 120, 120, 0, 0, 0, 0, 0, 0);
  mc2 = newSWFMovieClip();
  SWFMovieClip_add(mc2, (SWFBlock)sh2);  
  SWFMovieClip_nextFrame(mc2); 

  sh3 = make_fill_square (330, 270, 120, 180, 0, 255, 0, 0, 255, 0);
  mc3 = newSWFMovieClip();
  SWFMovieClip_add(mc3, (SWFBlock)sh3);
  SWFMovieClip_nextFrame(mc3); 

  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  //add movieClip1 to the _root
  SWFDisplayItem_setName(it1, "movieClip1"); //name movieClip1
  SWFDisplayItem_addAction(it1, newSWFAction(
		"_root.note(this+' constructed');"
		"_root.mc1Constructed++;"
		), SWFACTION_CONSTRUCT);
  SWFDisplayItem_setDepth(it1, 3); // depth of movieClip1 is 3 (-16381)

  it2 = SWFMovie_add(mo, (SWFBlock)mc2);  //add movieClip2 to the _root
  SWFDisplayItem_setName(it2, "movieClip2"); //name movieClip2
  SWFDisplayItem_addAction(it2, newSWFAction(
		"_root.note(this+' constructed');"
		"_root.mc2Constructed++;"),
		  SWFACTION_CONSTRUCT);
  SWFDisplayItem_setDepth(it2, 30000); // depth of movieClip2 is 30000 (13616)

  it3 = SWFMovie_add(mo, (SWFBlock)mc3);  //add movieClip3 to the _root
  SWFDisplayItem_setName(it3, "movieClip3"); //name movieClip3
  SWFDisplayItem_addAction(it3, newSWFAction(
		"_root.note(this+' constructed');"
		"_root.mc3Constructed++;"),
		  SWFACTION_CONSTRUCT);
  SWFDisplayItem_setDepth(it3, 30001); // depth of movieClip3 is 30001 (13617)

  SWFMovie_add(mo, (SWFBlock)newSWFAction(
      "check_equals(movieClip3.getDepth(), 13617);"
  ));
  
  SWFMovie_nextFrame(mo);
  
  // Frame4: RemoveObject(mc3) - one of those out of static depth zone

  SWFDisplayItem_remove(it3);

  // Frame4: gotoAndStop(1), check..

  SWFMovie_add(mo, (SWFBlock)newSWFAction(

      "var mc1_depth = movieClip1.getDepth();"
      "var mc2_depth = movieClip2.getDepth();"
      "movieClip1.secretCode = 'mc1';"
      "movieClip2.secretCode = 'mc2';"

      "check_equals(movieClip1.getDepth(), -16381);" 
      "check_equals(movieClip2.getDepth(), 13616);"
      // movieClip3 was removed, despite it's depth is out of the static zone
      "check_equals(typeof(movieClip3), 'undefined');"

      "gotoAndStop(1);"

      // MC1 (in static depth zone) has been removed
      "check_equals(typeof(movieClip1), 'undefined');"
      // MC2 (in dynamic depth zone) has been kept
      "check_equals(typeof(movieClip2), 'movieclip');"

      // The kept instance wasn't detroyed
      "check_equals(movieClip2.secretCode, 'mc2');"

      // Both chars have been constructed once (consistency check)
      "check_equals(mc1Constructed, 1);"
      "check_equals(mc2Constructed, 1);"

      "totals(9);"

	));
  SWFMovie_nextFrame(mo);

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

  return 0;
}