how to create dynamic button in actionscript

 

At first, it is a very simple tip.Maybe… anybody knows how can we create dynamic button in flash as we create textfield dynamically using this MovieClip.createTextField(), In this article, it shows how to creat dynamical button in actionscript. No design tools will be used, it is just actionscript code. Ok, let’s see the following code, hope it is what you are looking for and will be helpful to you.

 

  1. // paint
  2. var G:Array = [[0, 0], [80, 0], [80, 20], [0, 20], [0, 0]];
  3. this.createEmptyMovieClip(“btn”,0);
  4. btn.beginFill(“0x000000”,100);
  5. for (i=0; i<G.length; i++) {
  6. i == 0 ? btn.moveTo(G[i][0], G[i][1]) : btn.lineTo(G[i][0], G[i][1]);
  7. }
  8. btn.endFill();
  9. // set button position
  10. btn._x = (Stage.width/2)-btn._width/2;
  11. btn._y = (Stage.height/2)-btn._height/2;
  12. // button methon
  13. btn.onRelease = function() {
  14. getURL(“http://ntt.cc”, “_blank”);
  15. };