[vet-mm] global and local variables

Paul Sijpkes sijp at knox.vic.edu.au
Wed Sep 5 09:16:58 EST 2007


I know this is an old topic but I thought my input might be useful.

I tend to declare all variables on the first frame in the _root
timeline, I don't use the _global option because it is bad programming
practice.  

Global variables can easily become confused with locals, especially in
bigger programs, it also makes your code less portable so you can't
reuse it as easily.

Anyway, this is a huge topic, and I'm sure people will debate this with
me, but in my opinion it's the best way to go.

 

I find the best practice is to create an object for each major part of
your code in the _root timeline.

 

var presentation:Object = new ObjectI(); 

var audience.Object = new Object();

 

and then declaring the variables relating to that part inside the
objects.

 

presentation.slides = 5;

presentation.boring = true;

audience.sleeping = true;

 

etc...

 

You can now reference these objects anywhere in your application using
_root.presentation.slides, _root.audience.sleeping etc...

Hope this helps.

 

Cheers,

 

 

Paul Sijpkes
VET Coordinator
THE KNOX SCHOOL
Independent Co-educational International
Wantirna South VIC 3152
Phone: +61 3 9801 9233 
Fax: +61 3 9887 1850
Website:
<http://mail1/exchweb/bin/redir.asp?URL=http://www.knox.vic.edu.au>
www.knox.vic.edu.au <http://www.knox.vic.edu.aucricos/> 
CRICOS Provider No: 00151G ABN: 16 095 158 222

________________________________

From: vet-mm-bounces at edulists.com.au
[mailto:vet-mm-bounces at edulists.com.au] On Behalf Of Stoney, Marian Sy
Sent: Wednesday, 22 August 2007 4:35 PM
To: VET Multimedia Teachers' Mailing List
Subject: RE: [vet-mm] global and local variables

 

Thanks, John. I haven't loaded Flash 8 yet but I'll have to now!  The
advice on declaring them on the main timeline is good,

Regards,

Marian

________________________________

From: vet-mm-bounces at edulists.com.au on behalf of Mr John Parlas
Sent: Tue 21/08/2007 3:26 PM
To: VET Multimedia Teachers' Mailing List
Subject: RE: [vet-mm] global and local variables

Hi Marian,

 

Not sure what you mean but I suspect it has something to do with how the
variables are declared. Hopefully the attached file can clear the water
a bit. Basically, when variables are declared properly, globals can be
used in other parts of the movie where as locals cannot. I tend to
always declare globals main timeline - not within a function and just
use them within the function.

 

Look in the frame script to see the code.

 

Hope this helps????? Flash 8 format.

 

Regards

John

________________________________

From: vet-mm-bounces at edulists.com.au
[mailto:vet-mm-bounces at edulists.com.au] On Behalf Of Stoney, Marian Sy
Sent: Tuesday, 21 August 2007 12:20 PM
To: vet-mm at edulists.com.au
Subject: [vet-mm] global and local variables

 

Hi there all you Actionscript types!

I'm wondering why, if I declare a global variable on the timeline, it's
available to a function on a movie clip, but if I declare a global
variable inside a function on a movie clip, it's not available to the
timeline, whilst still being available to other functions on other movie
clips. I thought global functions were supposed to be available
everywhere? I've attached my file, but it's a bit of a mess.

Grateful for any insights!

Thanks,

Marian

Important - This email and any attachments may be confidential. If
received in error, please contact us and delete all copies. Before
opening or using attachments check them for viruses and defects.
Regardless of any loss, damage or consequence, whether caused by the
negligence of the sender or not, resulting directly or indirectly from
the use of any attached files our liability is limited to resupplying
any affected attachments. Any representations or opinions expressed are
those of the individual sender, and not necessarily those of the
Department of Education and Early Childhood Development.

_______________________________________________ 
http://www.edulists.com.au <http://www.edulists.com.au/> - FAQ,
resources, subscribe, unsubscribe 
VET Multimedia Mailing List kindly supported by 
http://www.vcaa.vic.edu.au/vet/programs/multimedia/multimedia.html
<http://www.vcaa.vic.edu.au/vet/programs/multimedia/multimedia.html%20>
- Victorian Curriculum and Assessment Authority and 
http://www.pixeled.org.au <http://www.pixeled.org.au/> - PixelEd
Multimedia Teachers Association

_______________________________________________ 
http://www.edulists.com.au <http://www.edulists.com.au/> - FAQ,
resources, subscribe, unsubscribe 
VET Multimedia Mailing List kindly supported by 
http://www.vcaa.vic.edu.au/vet/programs/multimedia/multimedia.html -
Victorian Curriculum and Assessment Authority and 
http://www.pixeled.org.au <http://www.pixeled.org.au/> - PixelEd
Multimedia Teachers Association 

DISCLAIMER:

This email and any files transmitted with it are confidential and
intended solely for the use of the individual to whom they are
addressed.

If you have received this email in error, please notify the sender
immediately by return email and then delete this message. 

Any views expressed in this email are those of the individual sender and
may not necessarily reflect the views of Yarra Valley Grammar.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/vet-mm/attachments/20070905/d5249db0/attachment-0001.html


More information about the vet-mm mailing list