Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get text from textfield on the stage in Main class to external class

Explorer ,
Apr 22, 2013 Apr 22, 2013

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

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 22, 2013 Apr 22, 2013

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

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 22, 2013 Apr 22, 2013

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 401180: Call to a possibly undefined method MovieClip.

/Users/Peter/Desktop/project/project beta 0.6/as3/com/filebrowser/FileListManager.as, Line 401119: 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 22, 2013 Apr 22, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2013 May 26, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines