Solved

Flash

Posted on 2011-02-28
3
251 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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

772 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

12 Experts available now in Live!

Get 1:1 Help Now