Solved

Acces Global variables in ActionScript 3.0

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
Viewers will learn how to include realistic velocity sensitivity to their Sampler instruments. Set the Vol<Vel parameter in the Filter/Global tab to your desired setting: Gather samples of hits of various intensity, and drag/drop into Velocity zon…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

623 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