# Changin global var on runtime from within button?

**URL:** https://forum.kirupa.com/t/changin-global-var-on-runtime-from-within-button/145828
**Category:** Uncategorized
**Created:** [April 26, 2005, 5:42am UTC](https://forum.kirupa.com/t/changin-global-var-on-runtime-from-within-button/145828 "2005-04-26T05:42:26Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![visitor13](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@visitor13](https://forum.kirupa.com/u/visitor13)
#### Post date: [April 26, 2005, 5:42am UTC](https://forum.kirupa.com/t/changin-global-var-on-runtime-from-within-button/145828/1 "2005-04-26T05:42:26Z")

</div>

I’ve been playing with writing a simple script that would entirely depend on a few variables declared right on top of it. Is there a way of changing them (in my case values of p, q, a & b) with a button if the button is part of the script?  
Here’s the script (just copy and paste entire thing into the first frame);

[AS]  
//number of buttons & images  
var n = 4;  
//indexing of buttons and images starts from:  
var k = 0;  
//starting left align point (\_x value):  
var p = 100;  
//starting left align point (\_y value) for images and buttons:  
var q = 100;  
//movie clip width:  
a = 400;  
//movie clip height:  
b = 200;  
//create a script assigning RGB color to a clip  
function combineRGB (red, green, blue) {  
//combine the color values into a single number  
var RGB = (red \<\< 16) | (green \<\< 8) | blue;  
return RGB;  
}  
MovieClip.prototype.setRGB = function (colorValue) {  
new Color (this).setRGB (colorValue);  
};  
//set colors:  
color0 = combineRGB (44, 115, 30);  
color1 = combineRGB (76, 98, 139);  
color2 = combineRGB (124, 54, 52);  
color3 = combineRGB (92, 92, 118);  
color4 = combineRGB (119, 91, 80);  
color5 = combineRGB (132, 74, 50);  
white = combineRGB (255, 255, 255);  
grey = combinedRGB (127, 127, 127);  
black = combineRGB (0, 0, 0);  
//declare a new Array: “colors” for retrieving values later  
colors = [color0, color1, color2, color3, color4, color5, white, grey, black];  
//create a movie clip:  
this.createEmptyMovieClip (“container\_mc”, 200);  
this.container\_mc.moveTo (p, q);  
this.container\_mc.beginFill (0xFF0000);  
this.container\_mc.lineTo (p + a, q);  
this.container\_mc.lineTo (p + a, q + 200);  
this.container\_mc.lineTo (p, q + 200);  
this.container\_mc.lineTo (p, q);  
this.container\_mc.endFill;  
//create buttons for controlling which images will slide into position  
for (i = k; i \< n; i++) {  
this.createEmptyMovieClip (“btn” + i + “\_mc”, i + 100);  
//button height:  
var bh = 8;  
//spacing between buttons:  
var bs = 8;  
//button width:  
var bw = (a - (n - 1) \* bs) / n;  
//button distance from the container clip:  
var bd = bh \* 2;  
this[“btn” + i + “\_mc”].moveTo (p, q - bd);  
this[“btn” + i + “\_mc”].beginFill (0xFF0000);  
this[“btn” + i + “\_mc”].lineTo (p + bw, q - bd);  
this[“btn” + i + “\_mc”].lineTo (p + bw, q - (bd - bh));  
this[“btn” + i + “\_mc”].lineTo (p, q - (bd - bh));  
this[“btn” + i + “\_mc”].lineTo (p, q - bd);  
this[“btn” + i + “\_mc”].endFill;  
//position buttons:  
for (r = k + 1; r \< n; r++) {  
this[“btn” + r + “\_mc”].\_x = (this[“btn” + (r - 1) + “\_mc”].\_x) + (this[“btn” + (r - 1) + “\_mc”].\_width + bs);  
}  
}  
for (i = k; i \< n; i++) {  
this[“btn” + i + “\_mc”].onRelease = function () {  
var btNameString = getProperty (this, \_name);  
t = btNameString.charAt (3);  
container\_mc.setRGB (colors[t]);  
};  
}  
[/AS]

I would want my container (and buttons since they’re attached) to change position or size when the buttons are clicked so essentially I’d like to be able to change p and q values.
