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

Call a fieldtext in stage from a Class

New Here ,
Dec 25, 2016 Dec 25, 2016

Hello, guys, I can´t figure out this, hopefully somebody can guide me, since all the related topics I could find were pointing in another direction (create a fieldtext in stage from within a Class).

Lets say I already have a dynamic fieldtext in stage, and its instance name is "txt1".

Now, I want to put some text in it from a Class (not the Main Class, but any other one):

package {

    import flash.display.Sprite;

    import flash.display.Stage;

    import flash.text.TextField;

  public class printText extends TextField{

  public function printText () {

  TextField(root).txt1.text = "abc"; // This didn´t work

  this_parent[txt1].text = "abc"; // Neither do this

            }

       }

  }

Any help would be really appreciate it!

Happy hollydays to everyone, thanks in advance!

TOPICS
ActionScript
320
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
Community Expert ,
Dec 25, 2016 Dec 25, 2016

printText needs a reference to stage or an object in the display list.  that's always doable because what ever class invokes printText has a parent, grand parent etc that is the document class.

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
New Here ,
Dec 26, 2016 Dec 26, 2016

Thanks for your kind answer, kglad.

Sorry if I´m not fully understanding what you answered (kind of newbie in AS3).

So there is no straight way to put some text in a Textfield located on the stage from a Class? I want to use an already existing textfield, I just assumed I could write something like stage.textfieldName.text = "abc"; but I understand from your answer there is no such shortcut, right?

The solution to this is related to understand the concept of nesting in classes? When you say "reference to stage", how could I refer to my stage in order to "talk" directly to my fieldtext?

Thanks again for your time, I really appreciate it

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
Community Expert ,
Dec 26, 2016 Dec 26, 2016

no,, you do not nest classes.  absolutely not.

you have a document class, correct?

there is some class that references PrintText, correct?  (eg, using var pt:PrintText=new PrintText() )

what's the relationship between your doc class and PrintText?

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
New Here ,
Dec 26, 2016 Dec 26, 2016

Thanks for your answer, kglad. You guide me brilliantly in the right direction!

I don´t have a document class, but after thinking about your last message, I write this on frame 1 of the stage timeline:

var newPt = new printText ();

txt1.text = printText.stopPoints[0]; //"stopPoints" is an array I have in my class with some values in it.

This works like a charm. And if I put that inside a document class, it works perfect too, no need to write anything in the timeline.  So far, so good.

Now, suppose I want every line of code inside my Class printText. No timeline, no document class.

Is that doable? Or I have no option, but to call the Class from the document class? I´m sorry, I´m still a little confused here, but I think I´m closer to match the pieces now.

Thanks again!

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
Community Expert ,
Dec 26, 2016 Dec 26, 2016

the only class automatically included in your project is you document class or classes you import on your timeline.

if have a simple project, coding on the timeline is fine.  but as a project increases in complexity, the benefits of using a class structure increase.

putting all your significant code in one class (which will have to be your document class) is not much better than timeline coding.  the big benefits accrue as your projects increase in complexity and you increasingly compartmentalize your code in different classes.

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
New Here ,
Dec 26, 2016 Dec 26, 2016

Crystal clear, kglad, thank you very much for your time!

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
Community Expert ,
Dec 26, 2016 Dec 26, 2016
LATEST

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

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