Copy link to clipboard
Copied
Hello, I've got little (I hope) problem.
I don't know how to get text from text field that is on the stage to external class code.
I think it might look like this:
Main class:
public var username:Textfield = username_txt;
External class:
import Main;
private var _mainClass:Main;
// place where I need to get the text
vars.username = _mainClass.username.text;
but code above is not working because I'm getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Thank you so much in advance for all help
Copy link to clipboard
Copied
you don`t need these lines:
import Main;
private var _mainClass:Main;
if your external class has acces to the stage/displayList
you can always call your var with either
MovieClip(root).username (absolute syntax)
or in your case with
MovieClip(this.parent).username
be aware that you have to have either already a instance of External class on the stage for this to work,
or if you use addChild, wait until the constructor has access to stage:
public function ExternalClass():void{
if(stage) init();
else{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void{
//put your code here
}
}
Copy link to clipboard
Copied
hi, I've tryed that, but I'm getting these errors:
/Users/Peter/Desktop/project/project beta 0.6/as3/com/filebrowser/FileListManager.as, Line 40 | 1180: Call to a possibly undefined method MovieClip. |
/Users/Peter/Desktop/project/project beta 0.6/as3/com/filebrowser/FileListManager.as, Line 40 | 1119: Access of possibly undefined property parent through a reference with static type com.filebrowser:FileListManager. |
line 40 is this:
vars.username = MovieClip(this.parent).username;
ps. thanks for your helping to me
Copy link to clipboard
Copied
Put this import statement at the beginning of your FileListManager-class
import flash.display.MovieClip
another problem is that your FileListManager-class ist static, so you can`t use the this keyword
Be sure thatz you want to use a static class, because it has some restrictions
Copy link to clipboard
Copied
Hi, sorry about that I'm responding so late.
I've solved this problem like so.
External Class: FileListManager.as
public var username:String;
username = null;
vars.username = username;
Main Class: Main.as
import FileListManager;
private var _manager:FileListManager();
_manager = new FileListManager();
_manager.username = username_txt.text;
Thank you all so much for your helping to me
Find more inspiration, events, and resources on the new Adobe Community
Explore Now