sample #22
button with sound event
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. $swfFN = "buttonSound.swf"; // swf we'll generate
  5. $sndFN = "ringout.mp3"; // sound to insert
  6.  
  7. $svgFN1 = "inkscape_bt_off.svg"; // vector data for button state off
  8. $svgFN2 = "inkscape_bt_over.svg"; // button state over
  9. $svgFN3 = "inkscape_bt_down.svg"; // state down
  10. $svgFN4 = "inkscape_bt_hit.svg"; // hit
  11.  
  12. $svg1 = new MKsimple_svg_reader($svgFN1); // build tag data
  13. $svgTD1 = $svg1->update_tagData(); //
  14.  
  15. $svg2 = new MKsimple_svg_reader($svgFN2, "", 2); //
  16. $svgTD2 = $svg2->update_tagData();
  17.  
  18. $svg3 = new MKsimple_svg_reader($svgFN3, "", 3); //
  19. $svgTD3 = $svg3->update_tagData();
  20.  
  21. $svg4 = new MKsimple_svg_reader($svgFN4, "", 4); //
  22. $svgTD4 = $svg4->update_tagData();
  23.  
  24. $snd = new MKsound_container("", $sndFN, "", 5); //
  25. $sndTD = $snd->update_tagData();
  26.  
  27. $shapeAr = array($svg4, $svg3, $svg2, $svg1); // prepare for button
  28. $button = new MKbutton_container("", 6); // a fresh button
  29. $buttonTD = $button->build_from_array($shapeAr); // build states
  30. $button->set_sound_event(5, ROLL_OVER); // a sound event
  31. $buttonSoundTD = $button->update_buttonSound_tagData(); // get sound event tag data
  32.  
  33. $button->move(35, 15); // place @35,15
  34. $buttonTD = $button->build_from_array($shapeAr); // use shape array for placing an setting states
  35. $buttonPB = $button->update_place_tagData(); // place tag data
  36.  
  37. $swf = new MKswf($swfFN); // a fresh swf
  38. $swf->set_stage_dimensions(200, 100); // width/height 200/100
  39. $swf->set_backgroundColor("#33CC33"); // a kind of green as background color
  40. $swf->set_swfDir(SERVER_MKTMP); // set output directory
  41.  
  42. $swf->add_tagData($svgTD1); // start to populate
  43. $swf->add_tagData($svgTD2); //
  44. $swf->add_tagData($svgTD3); //
  45. $swf->add_tagData($svgTD4); //
  46.  
  47. $swf->add_tagData($sndTD); // sound tag data
  48.  
  49. $swf->add_tagData($buttonTD); // button tag data
  50. $swf->add_tagData($buttonSoundTD); // button sound event tag data
  51. $swf->add_tagData($buttonPB); // place button on stage
  52. $swf->swf_output(); // save
  53.  
  54. $swfHeader = $swf->fetch_assoc(); // prepare to publish
  55.  
  56. $str = render_swf_box($swfHeader, $imgDir, false);
  57. $str .= "<br/><strong>" .$swfFN ." created in :<br />" .SERVER_MKTMP ."</strong>";
  58. echo show_content($str, basename(__FILE__));
  59. ?>

combining sound insertion technique and button build you may obtain both visual and sound event button, additional set_sound_event is needed and update_buttonSound_data for swf population. Another way is to use sound linkages and actionscript.


mikrokosmos