Reputation: 1390
Say I have code in my main mxml and in a function like this:
this.addChild(someContainer);
and now I want to refactor code and move this to it's own class and method in a separate file. How could I access root now, since this obviously now points to the new class I created.
Upvotes: 1
Views: 1383
Reputation: 13361
You could use something like Application.application, Application.root or event this.root (depending on your needs)
But I would'nt advise it (try to refactor your code so that you can pass a reference to your main or something like that ... ).
The question is : is your newly-created class going to be reponsible for adding childs to components ? Then I would suggest you instead make it possible to pass it a reference to any kind of Container ; and in you main mxml, you pass the reference to root.
It might also be that the new class is only responible for exposing the things to add ; in which case you could probably leave the "this.addChild(...)" code in the main.
Hoping this helps.
Upvotes: 2