# Adding dynamic text to a button

**URL:** <https://forum.kirupa.com/t/adding-dynamic-text-to-a-button/327828>\
**Category:** Uncategorized\
**Created:** [March 30, 2012, 3:46pm UTC](https://forum.kirupa.com/t/adding-dynamic-text-to-a-button/327828 "2012-03-30T15:46:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Porter](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Alex\_Porter](https://forum.kirupa.com/u/Alex_Porter)\
**Post date:** [March 30, 2012, 3:46pm UTC](https://forum.kirupa.com/t/adding-dynamic-text-to-a-button/327828/1 "2012-03-30T15:46:01Z")

</div>

hey guys. im pretty new to actionscript 3.

im trying to make a basic addition game where two random numbers are generated, and then the sum of the numbers will be dragged/snapped into place underneath.

i thought the easiest way to drag/snap the “total” number would be to somehow turn it into a button that still allowed dynamic text.

here is my code so far

```auto
var high:Number = 5;
var low:Number = 1; 
var firstNumber:Number = Math.floor(Math.random()*(1+high-low))+low;
var secondNumber:Number = Math.floor(Math.random()*(1+high-low))+low;
var total:Number = firstNumber + secondNumber;
var mc:MovieClip=new MovieClip()

firstNumber_box.text = String(firstNumber)
secondNumber_box.text = String(secondNumber)
total_box.text = String(total)

addChild(mc)
mc.addChild(total_box)
mc.addEventListener(MouseEvent.MOUSE_DOWN,drag)
mc.addEventListener(MouseEvent.MOUSE_UP,drop)

function drag(event:MouseEvent)
{

    event.currentTarget.startDrag();
}

function drop(event:MouseEvent)
{
    stopDrag();
}

```

any help would be really appreciated, if you guy’s could explain what the code does as well, that would be awesome!

[http://dl.dropbox.com/u/4982762/messing%20around.swf](http://dl.dropbox.com/u/4982762/messing%20around.swf)
