Solved

Flash

Posted on 2011-02-28
3
288 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
[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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
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 select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

737 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