Solved

Acces Global variables in ActionScript 3.0

Posted on 2007-12-03
5
13,496 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video resolutions to be set for Videos in FB 9 72
ASIO4ALL 9 47
Upload video to Youtube 2 18
Music – name and composer 2 19
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The advancements in today's technology are unparalleled. Much of the technology that we have could not have been imagined twenty years ago. One of the latest additions to the list of technological advances is virtual reality. Virtual reality has an …
Viewers will learn how to turn a Live Set into a compressed Live Pack file, and how to install Live Packs. Make: File > Collect All And Save: File > Manage Files: Click Manage Project: Click Create Pack: Select save location: Install: Doub…
Viewers will learn the basics of using Ableton Live's advanced sampler instrument, Sampler. Load new Sampler into an empty MIDI track: Select a sample and drop it into sample window in Sampler: Adjust pitch if necessary with Root Key setting: …

813 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

8 Experts available now in Live!

Get 1:1 Help Now