Solved

Acces Global variables in ActionScript 3.0

Posted on 2007-12-03
5
13,508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
Viewers will learn how to create burn videos onto a DVD using Nero Suite including creating a DVD menu and chapters.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

756 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