Solved

Acces Global variables in ActionScript 3.0

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
In this article, I'll explain how to setup a Plex Media Server (https://plex.tv/) on a Redhat (Centos) 7 based NAS with screenshots to help those looking for assistance.  What is Plex? If you aren't familiar with Plex, it’s a DLNA media serv…
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…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

707 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

13 Experts available now in Live!

Get 1:1 Help Now