We help IT Professionals succeed at work.

AS3 Class - Access Object In Root

pD_EO
pD_EO asked
on
Hey Guys,

I am creating a class in AS3 that loads some info from a remote file.  What I want to be able to do is put this info into a text box.

I have given the text box an instance name, but I am not sure on how I would target the text box from within a class method.

Thanks
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2008

Commented:
USE "root" instead of "_root"

it should work

Author

Commented:
Hi,

I gave that a try, but I get an error...

"1120: Access of undefined property root.
CERTIFIED EXPERT
Top Expert 2008

Commented:
The MovieClip/textField is located on the timeline created by the flash player. You can call it using this syntax by casting the Displayobject "this.root" to a MovieClip:

trace("this.root: "+MovieClip(this.root).getChildByName("mytxt") );

Author

Commented:
Hmm, still having a problem.
package com.blah.apples {
 
	public class apples {
	
		public function apples {
			trace("this.root: " + MovieClip(this.root).getChildByName("mytxt"));
		}
	
	}
 
}

Open in new window

CERTIFIED EXPERT
Top Expert 2008
Commented:
main timeline root is not accessible freely anymore in AS3,
it can be accessed by any class only if class gets any reference of the main timeline.

so simplest way is store a global refernce to any object is create a class which can act as similar to "_global" of AS2

visit following link to get more details about storing and accesing Global variables in ActionScript 3.0
http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_22997849.html


-------------------
Aneesh Chopra
-------------------

Author

Commented:
I worked out that I could pass the main timeline to my class, but thought there might be a better way.

Thanks for your help.