Noob question (probably). I have a class with a var textFieldObjets:Textfield
in my class environnement
What i'd like to do, is access this var from another class and change the text. I tried things like environnement.textFieldObjets.text = "blabla";
Got error 1119, Access of a possible undefined property textFieldObjets trough a reference with static type Class. I can't even access my environnement class...
How could I do that? thx!
Make the variable a class member with public static
identifier.
public static var textFieldObjects:Textfield;
For more information on what static
and public
keywords mean, you could refer to this question: Actionscript 3: Can someone explain to me the concept of static variables and methods?
Documentation from Adobe: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f30.html
1. You need to declare the variable as "public":
public var textFieldObjects:TextField;
2. You can't access a regular property directly through the class--you need an instance of your environnement
class. If you're working in the Flash tool, you'll need to place your component on the stage (this creates the instance), and then give it an instance id. Then you can use that id to access the component from your actionscript.
So if you call your instance: myEnv, then your actionscript might look like this:
myEnv.textFieldObjets.text = "blabla";
If you're working in flex, then it works the same way -- just place the component into your mxml document, and set it's id
attribute to a unique name. Now, you can access that component from script, by using the id you defined.