Solved

Flash

Posted on 2011-02-28
3
259 Views
Last Modified: 2012-08-14
Hi i have a problem i create a variable var countss:Number = 1; and when i open 2 more layer it do not work any more. How i can creare global variable so i can use it when i go 2 layer down.
0
Comment
Question by:umaxim
3 Comments
 
LVL 12

Expert Comment

by:scooby_56
ID: 34999193
if countss is in the root then you could use this in your lower layers

var r = root;
trace(r.countss) //note that  trace(root.countss) will not work.

Otherwise you could access by doing:
trace(parent.parent.countss);
0
 
LVL 4

Accepted Solution

by:
ute_arbeit earned 500 total points
ID: 34999698
That depends on your version of Actionscript:
1. In Actionscript 1 or 2 you can define global variables using the '_global' prefix like so:

_global.countss = 1;

Open in new window



The you can reference it from any script in any level using
_global.countss

Open in new window



2. In Acrionscript 3 the _global object was removed. You should organize your code and data in classes. But if you absolutely want you could create a class called e.g. GlobalData.as in the root of your class directory (normally the folder containing the fla) and add the variable as a public static variable.

package {
	public class GlobalData {
		public static var countss:Number = 1;
	}
}

Open in new window


As the variable is static you do not have to create an instance of your class and can just reference if from anywhere with
GlobalData.countss

Open in new window

0
 
LVL 1

Author Closing Comment

by:umaxim
ID: 34999929
thank you
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

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…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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.

914 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