<?php include("sample_utils.php"); // provides some utils and using mk $swfFN = "button.swf"; // the file we'll generate $btImageFN1 = "gimp_bt_off.png"; // image for button state off $btImageFN2 = "gimp_bt_over.png"; // button state over $btImageFN3 = "gimp_bt_down.png"; // state down $swf = new MKswf($swfFN); // create a fresh swf $swf->set_swfDir(SERVER_MKTMP); // store in tmp $swf->set_stage_dimensions(170, 50); // stage dimensions $swf->set_backgroundColor("#0066FF"); // background color $img = new Bitmap_item(); // image object, id = 1 by default $imgTD = $img->create_from_file($btImageFN1); // create from image file $swf->add_tagData($imgTD); // tag data $buttonWidth = $img->get_imageWidth(); // used for hit area $buttonHeight = $img->get_imageHeight(); // $img = new Bitmap_item(2); // $imgTD = $img->create_from_file($btImageFN2); // $swf->add_tagData($imgTD); // $img = new Bitmap_item(3); // $imgTD = $img->create_from_file($btImageFN3); // $swf->add_tagData($imgTD); // $shape1 = new MKshape_container("", 4); // a shape that bound image #1 $shape1->add_bitmap_fill(1); // $shape1->add_rect(0, 0, $buttonWidth, $buttonHeight); // $shapeTD1 = $shape1->update_tagData(); // $swf->add_tagData($shapeTD1); // $shape2 = new MKshape_container("", 5); // bound image #2 $shape2->add_bitmap_fill(2); // $shape2->add_rect(0, 0, $buttonWidth, $buttonHeight); // $shapeTD2 = $shape2->update_tagData(); // $swf->add_tagData($shapeTD2); // $shape3 = new MKshape_container("", 6); // bound image #3 $shape3->add_bitmap_fill(3); // $shape3->add_rect(0, 0, $buttonWidth, $buttonHeight); // $shapeTD3 = $shape3->update_tagData(); // $swf->add_tagData($shapeTD3); // $shape4 = new MKshape_container("", 7); // hit area, only vector data $shape4->add_fillStyle_solid(); // black by default, color is pointless here $shape4->add_rect(0, 0, $buttonWidth, $buttonHeight); // use image width/height for hit area $shapeTD4 = $shape4->update_tagData(); // $swf->add_tagData($shapeTD4); // $button = new MKbutton_container("", 8); // a fresh button $button->move(10, 10); // place @10,10 $buttonTD = $button->build_from_array($shapeAr); // use shape array for placing an setting states $buttonPB = $button->update_place_tagData(); // place tag data $swf->add_tagData($buttonTD); // $swf->add_tagData($buttonPB); // $swf->swf_output(); // save $swfHeader = $swf->fetch_assoc(); // prepare to publish $str = render_swf_box($swfHeader, $imgDir, false); $str .= "<br/><strong>" .$swfFN ." created in :<br />" .SERVER_MKTMP ."</strong>"; ?>
buttons in swf are something complex object, they define three event "states": off, over, down and a phisical state: hit area, that is the active area of button reaction.
Despite to its complexity, IMHO buttons are almost unuseful, because their states don't fit well real world application (e.g. flip-flop state are not supported by definition). That's the reason why they are supported only after 18 months of development. For building button in mk you have to prepare the contribs and call build_from_array method.
There is not cases that a good actionscript + sprites can't be handled in better and smarter way, so professionals tend to ignore button design.
Anyway there is some case of convenient use of button, in the next sample we'll build a "trasparent hit area", that can be drawn in whatever we want shape, allowing to implement e.g. image maps or spot in virtual tour.
Another issue is related to actionscript: buttons can contain bytecode so if we want to completely deconstruct an swf we have to be able reading that.
It is suggested to avoid "button actionscript", it is obsolete and deprecated.
![]()