# Making instances and assigning variables

**URL:** https://forum.kirupa.com/t/making-instances-and-assigning-variables/233940
**Category:** flash
**Created:** [July 28, 2007, 1:58pm UTC](https://forum.kirupa.com/t/making-instances-and-assigning-variables/233940 "2007-07-28T13:58:11Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Dan0](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@Dan0](https://forum.kirupa.com/u/Dan0)
#### Post date: [July 28, 2007, 1:58pm UTC](https://forum.kirupa.com/t/making-instances-and-assigning-variables/233940/1 "2007-07-28T13:58:11Z")

</div>

Hi.  
Sorry to ask so many questions but;  
I made a sprite, simple enough. Now I want to give the sprite 2 variables and I can’t figure how to do it!  
My sprite is essentially a button, with a shape and textfield instances inside it. I have got an eventListener to check if the mouse is over. If it is, it calls a function which makes another eventListener Event.ENTER\_FRAME on the sprite instance to animate the shape instance inside it. But for the animation to work I need these two variables to be given to the sprite instance. But when I try to do somthing like this;

```auto
var p = buttonCreate("cool",100,10,5);
          addChild(p);
function buttonCreate(txtT,wT,hT,extT) {
 var a = new Sprite();
 a.curExt = 0;
 a.maxExt = extT;
 var b = new Shape();
 a.addChild(b);
 var t = new TextField();
 a.addChild(t);
 a.addEventListener(MouseEvent.MOUSE_OVER,buttonOver);
 return a;
}

```

It doesnt want to give it the curExt or maxExt variables. I understand that you have to make a variable with the var keywork in AS3 before it works but how do you do it externally from the instance itself?  
Thanks for reading/helping,  
Dan

Also how should I store an identifier to the shape instance on the sprite? Because for the animation to work I am going to need to reference to it…
