actionscript 3 - Creating a public function in object oriented programming (flash)? -


I'm new to object oriented programming and flash. As far as I know, global variables and functions are bad things. We have to use the objects, right?

So far everything is going well, apart from this, when I want to make sad. Create a log function that will write the debug message in a textfield object.

The problem is that I should be able to use this log function everywhere in children of this child and parents of children, children of these, etc. - anywhere in the code

How should I do this in a good object-oriented manner? Because, when it calls in Object A and is to use it in Object A child, then the object will not be accessible until now, which is Object B.

Another method is to use a singleton class. In short, it was shown to you like a Christian class But the way you access it, is the singletonclass.get instance (). DoSomething () The principle behind this is that the class only holds an example of itself, so every time you get the call (), the class checks that this example has been made, and returns it back to you about it Learn more and see its various implementations here:

However for your case, I would probably have to go through a steady global class in a simple way because the Christian said static method To reach a textfield from the log (), you can create a testfield (TF: textfield) to register another static method and call it with the textfield at the beginning of your application, register it in a fixed variable , And you can go from there to be there. Adding Christian example, this would be something like this:

  package {import flash.text.TextField; Public Class MyCustomLogger {Personal Static var _textfield: TextField; Public function MyCustomLogger () {//} Public Static Work Log (text: string): zero {_textfield.text = text; } Public stable work registerTextField (textfield: textfield): zero {_textfield = textfield; }}}  

Good luck!


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -