# Declaring global variables possible with scripting?

**URL:** https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589
**Category:** Uncategorized
**Created:** [May 27, 2002, 2:37pm UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589 "2002-05-27T14:37:27Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 27, 2002, 2:37pm UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/1 "2002-05-27T14:37:27Z")

</div>

hello boyz and girls…i am wondering where and how i can insert global variables in my code (below)…or is that too ‘C’ a concept!?!..see what i am trying to do here is this…onClipEvent calls within it attachMovie from my library with the appropriate linkages…a few setProperty here and there…what i want is a few characters initialised above the rest of the code…why?..coz as u will see, when k=0, a movie is picked up, put at level m=1…\r\r…the second time round the loop begins, k=1 so a movie gets picked up again at random…now this is where i need ur help…the second (and subsequent 3 movies) need to be placed on top of the basemovie…i am trying swapdepths here…good choice?..anything else i can do?..yet to figure out reducing the opacity of subsequent movies…see i am looking for a motion trail kinda effect…so at one point of time 5 mc will be visible…total no. of mc=250 and at random they get picked up over and over again…\r\r…would appreciate any advise…been trying loadmovie but then that doesn’t work within onclipEvent!..moreover, onclipEvent doesn’t allow any code outside its parantheses!..where can i initialise my k,j,m and alpha…\r\rNote: this is a frame action and the movies get loaded in an empty mc… \r\r…new to flash scripting…still romantic about C! =)\r\rset (k,“0”);\rset (m,“1”);\rset (j,“0”);\rset (alpha,“100”);\r\ronClipEvent (load) {\r//k=0;\r//m=1;\rif(k=0){\r&nbsp &nbsp &nbsp &nbsp i = Math.ceil(Math.random()\*5);\r&nbsp &nbsp &nbsp &nbsp \_root.textBox = "this is movie " +i;\r&nbsp &nbsp &nbsp &nbsp this.attachMovie(“Symbol”+i, “fred”+i,m);\r &nbsp &nbsp &nbsp &nbsp setProperty (“fred”+i, \_alpha, “alpha”);\r setProperty (“fred”+i, \_x, “25”);\r setProperty (“fred”+i, \_y, “10”);\r&nbsp &nbsp &nbsp &nbsp k++;\r} \relse {\r&nbsp &nbsp &nbsp &nbsp i = Math.ceil(Math.random()\*5);\r&nbsp &nbsp &nbsp &nbsp “fred”+j.swapdepths(“fred”+i);\r&nbsp &nbsp &nbsp &nbsp \_root.textBox = "this is movie " +i;\r&nbsp &nbsp &nbsp &nbsp this.attachMovie(“Symbol”+i, “fred”+m);\r &nbsp &nbsp &nbsp &nbsp setProperty (“fred”+i, \_alpha, “alpha-20”);\r setProperty (“fred”+i, \_x, “25”);\r setProperty (“fred”+i, \_y, “10”);&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \r&nbsp &nbsp &nbsp &nbsp j++;\r&nbsp &nbsp &nbsp &nbsp if (j=5) {j=0}\r}\rif (m\<5) {m++}\relse {m=1}\r}\r\r\rcheers!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 27, 2002, 3:50pm UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/2 "2002-05-27T15:50:59Z")

</div>

if i have variables that i want every movie to see, i usually put them in \_root, \_parent, or in an object created for that purpose. in this case, why not keep them in the empty clip in which this is all happening?\r\rattachMovie’s last argument is the level in which to place it. as long as that variable is incrementing, it should appear on top without the swapDepths.\r\ra tip to save typing: despite the documentation’s insistence to the contrary, attachMovie actually returns a reference to the newly attached movie. this means that instead of:

```auto
 \r\r this.attachMovie("Symbol"+i, "fred"+i,m);\r\r setProperty ("fred"+i, _alpha, "alpha");

```

\ryou can write:

```auto
 \r\r var mc = this.attachMovie("Symbol"+i, "fred"+i,m);\r\r mc._alpha = alpha;

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 27, 2002, 6:20pm UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/3 "2002-05-27T18:20:25Z")

</div>

just read an ultrashock post that enlightened me to \_global. setting a variable in the \_global namespace will make it available to everything in the flash movie.\r\rfun!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 27, 2002, 8:08pm UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/4 "2002-05-27T20:08:32Z")

</div>

thats awesome. Makes a lot of things much easier…never knew about that…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 27, 2002, 8:27pm UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/5 "2002-05-27T20:27:54Z")

</div>

I don’t see what’s so romantic about C…\r\rAnyway, for all the people who are wondering how to use that nice little trick (and who are to lazy to open their Actionscript Dictionnary 😃 ), that’s how you’re supposed to use this :

```auto
 _global.a = 5 ;\r\r_global.move = function () {...}

```

pom 0]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 30, 2002, 4:45pm UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/6 "2002-05-30T16:45:20Z")

</div>

thanx a ton guys!!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 31, 2002, 1:03am UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/7 "2002-05-31T01:03:07Z")

</div>

my understanding was that using \r\rset var\r\rwould make the var global. Is that not correct?\r

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 31, 2002, 1:04am UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/8 "2002-05-31T01:04:38Z")

</div>

no… not truely global

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 31, 2002, 7:30am UTC](https://forum.kirupa.com/t/declaring-global-variables-possible-with-scripting/2589/9 "2002-05-31T07:30:22Z")

</div>

I’ve always used \_root, but I never knew about \_global.\r\r - Kit
