sample #22
button area
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. $swfFN = "btarea.swf"; // swf file name to ouput
  5.  
  6. $shape1 = new MKshape_container(); // a shape ...
  7. $shape1->add_fillStyle_solid(); // ... with default black color
  8. $shape1->add_rect(); // ... and a 100x100 default rect
  9. $shapeTD1 = $shape1->update_tagData(); // get tag data
  10.  
  11. $button1 = new MKbutton_container("", 2); // a button
  12. $buttonTD1 = $button1->build_button_state($shape1, "hit"); // with only "hit" state
  13. $buttonPB1 = $button1->update_place_tagData(); // place tag data
  14.  
  15. $swf = new MKswf($swfFN); // the swf to generate
  16. $swf->set_swfDir(SERVER_MKTMP); // set output directory
  17. $swf->add_tagData($shapeTD1); // start to populate
  18. $swf->add_tagData($buttonTD1); // ...
  19. $swf->add_tagData($buttonPB1); // ...
  20. $swf->swf_output();
  21.  
  22. $swfHeader = $swf->fetch_assoc(); // prepare to publish to the browser
  23.  
  24. $str = "<div style=\"width:600; height:500; background-color:#EEEEEE; text-align:center\"><br />";
  25. $str .= render_swf_box($swfHeader, $imgDir, false);
  26. $str .= "<br/><strong>" .$swfFN ." created in :<br />" .SERVER_MKTMP ."</strong>";
  27. $str .= "<br/>hit area is in the top left until 100,100</div>";
  28. echo show_content($str, basename(__FILE__));
  29. ?>

building "hit area" button is simple. All you have to do is define a shape drawn with desired form and the use call build_button_state method for MKbutton_container.
buttons in mk can be stored as linkage symbols in the same way of movieclips, sounds and fonts. E.g. you can store a 100x100px (default shape rectangle) and use it at run-time playing with its _xscale and _yscale to create smaller or larger transparent hit areas.


mikrokosmos