Solved

Acces Global variables in ActionScript 3.0

Posted on 2007-12-03
5
13,487 Views
Last Modified: 2010-05-18
I need to declare a global variable in Flash CS3 using ActionScript 3.0. I looked around the internet and the only solution that I found was to declare it in an external Class file, however, when I do this my flash animation won't work in MOST computers.

Does anyone know how to access global variables inside the flash animation? WITHOUT using an external class file?
0
Comment
Question by:ibone
5 Comments
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 20397072
with AS3.0, concept of _global variables have been removed completely.
although, an external class can be used to act as exactly AS2.0 _global

if you implement it properly, you should get desired results. here are the details:

1.
create a AS3.0 class with name "glo.as", and save it in the same folder where FLA resides.

2.
Just copy paste the following actionscript in "glo.as" class file.
////////////
package
{
      //Class will act as _global object of AS2
      // Static variable "bal" of this class is going to store "varibales, instance's/object's referece to be used by any other class or displayObject/movieClip
      // sample code to store a reference of a movieClip
      //
      // glo.bal.myMovie = this.new_mc;
      //
      //
      public class glo
      {
            public static  var bal:Object = new Object();
      }
}
//////

3.
Now just create any global variable anywhere by just using "glo.bal" instead of "_global"

for example:

glo.bal.myGlobalVariable = 22;

it will be accessible everywhere in the scope of your FLA and other classes.

-------------------
Aneesh Chopra
-------------------

0
 

Author Closing Comment

by:ibone
ID: 31412371
Thank you! Works like a charm! :-)
0
 

Expert Comment

by:m_for
ID: 22295023
1119: Access of possibly undefined property bal through a reference with static type Class.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 22296363
as mentioned in line no.3 "if you implement it properly, you should get desired results"

so you only need to crosscheck what you have missed in the suggested implementation..

make sure, "glo.as" must be in the FLA folder..
0
 

Expert Comment

by:davidtidwell86
ID: 24560177
Thanks so much, this is a very handy tip!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
Viewers will get an overview of how to make and use Drum Racks in Ableton Live. Load new Drum Rack into empty MIDI track: Fill rack with audio samples: Re-arrange sample slots as necessary: Adjust parameters of each slot to tailor each sound a…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now