sample #16
simple movieclips
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. $swfFN = "test_mk_movieclip01.swf"; // swf file that we will create
  5.  
  6.  
  7. $mad = array(); // setup an array
  8. $mad["rotation"] = 89; // ... that will contain
  9. $mad["x"] = 0; // placing settings, x
  10. $mad["y"] = 0; // ... y
  11. $mad["width"] = 200; // ... width and ...
  12. $mad["height"] = 200; // height
  13.  
  14. $colors = array(); // create ...
  15. $colors[0] = get_color_array("#FFFF00"); // two colors, yellow ...
  16. $colors[1] = get_color_array("#FF0000"); // ... and red
  17.  
  18. $sc = new MKshape_container(); // create ...
  19. $sc1 = new MKshape_container(); // two shapes
  20. $sc1->set_itemID(2); // assign item id to the last shape
  21. // the first have item id = 1 by default
  22.  
  23. $sc1->add_gradient_fill(LINEAR_GRADIENT_FILL,
  24. $colors, array(0, 0xff),
  25. $mad); // add gradient fill
  26. $sc1->add_rect(0, 0, 200, 200); // draw a rectangle, it will be the background
  27.  
  28. $mad["x"] = -50; // setup a new placing settings
  29. $mad["y"] = -50; // ...
  30. $mad["width"] = 100; // ...
  31. $mad["height"] = 100; // ...
  32. $mad["rotation"] = 0; // ...
  33.  
  34. $sc->add_gradient_fill(RADIAL_GRADIENT_FILL,
  35. $colors, array(0, 0xff),
  36. $mad); // a new gradient fill, for the foreground shape
  37. $coords = get_coords_star(0, 0, 50); // get star coordinates
  38. $sc->add_mixed_poly($coords); // draw star
  39.  
  40.  
  41. $mc = new MKmovieclip(); // create new movieclip
  42. $mc->set_spriteID(3); // with its item id
  43. $mc->add_tagData($sc->update_place_tagData(), 1); // place the star in the first frame of mc
  44.  
  45. for($i = 4.5, $k = 2; $i < 72; $i += 4.5, $k++){ // rotate by 4.5 degree
  46. $sc->rotate($i,true); // assign rotation
  47. $mc->add_tagData($sc->update_place_tagData(), $k); // get binary tag data
  48. }
  49.  
  50. $s1 = $sc1->update_tagData(); // get binary tag data from shapes
  51. $s2 = $sc->update_tagData(); // ..
  52. $mcTagData = $mc->update_tagData(); // get binary tag data from mc
  53.  
  54. $swf = new MKswf($swfFN); // create new swf
  55. $swf->set_stageWidth(200); // setup canvas
  56. $swf->set_stageHeight(200); // ...
  57. $swf->set_fps(24); // frames per second
  58. $swf->set_swfDir(SERVER_MKTMP); // set working directory
  59.  
  60. $swf->add_tagData($s1); // start to populate swf
  61. $swf->add_tagData($s2); // ...
  62. $swf->add_tagData($mcTagData); // ...
  63.  
  64. $po = new MKplaceObject2("", 3, 3); // new placing settings
  65. $po->set_position(100, 100); // ...
  66.  
  67. $swf->add_tagData($sc1->update_place_tagData()); // ...
  68. $swf->add_tagData($po->update_tagData()); // ...
  69. $swf->swf_output(); // write to disk
  70.  
  71. $swfHeader = $swf->fetch_assoc(); // prepare to publish
  72.  
  73. $str = render_swf_box($swfHeader, $imgDir, false);
  74. $str .= "<br/><strong>" .$swfFN ." created in :<br />" .SERVER_MKTMP ."</strong>";
  75. echo show_content($str, basename(__FILE__));
  76. ?>

movieclips (or sprites, as sometime defined in the swf ff specification) are object with their own timeline, they don't define any new contrib, they simply use what is defined in the main timeline (there are some exception e.g. actionscript containers). They support control tags, mandatory for placing objects and satisfy the rules of well-formed timeline. A movieclip may use items defined BEFORE it appear in the main timeline, in case of nested movieclips, that is a movieclip inside another, the inner (child) mc must be defined before the outer (parent) and all are stored in the main timeline.
This method allows to simplify swf structure analysis avoiding recursions (that are well known as prone to errors). So, if we want to create a movieclip, we first have to define the item that will be used by that mc.
Another crucial advantage derived from using movieclips is at actionscript level, the real potential of flash movie is bound to the scripting features offered by this language.

 

mikrokosmos