Declaring global variables possible with scripting?

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!

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:

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

\ryou can write:

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

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!

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

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 :smiley: ), that’s how you’re supposed to use this :

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

pom 0]

thanx a ton guys!!

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

no… not truely global

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