Skip to main content
Participant
June 4, 2008
Answered

Communication between Classes

  • June 4, 2008
  • 1 reply
  • 391 views
I'm trying to wrap my head around this and need some help. The scenario is this:

I have a main movie with it's Document class, the document class loads a few other classes
- Class 1 holds all of the file information, for example a few xml files and arrays
- Class 2 just a movie on the stage with a dataGrid
- Class 3 another movie on the stage with a button and text box

What looks so simple is hard for me to grasp, how do I get Class 2,3 to communicate with Class 1? So for example when button in class 3 is clicked it retrieves some text from Class 1 and displays it in the text box. Or lets say from the document class a method is called from Class 2 to retrieve info from Class 1 to display in the dataGrid.

Should I just include the Class 1 in every class that I need to use it? I would think that would weigh the file down but maybe flash only loads Class 1 into memory once and then if it is included again it just re-uses it.

Maybe a custom events class? Have no idea if that is the right track or even where to begin with that.

Or should I just write one giant Document class and forget the whole OOP idea.

Please help!
This topic has been closed for replies.
Correct answer jshields55
Well Mr Helpy mcHelpson you go down as AWESOME! in my book. I built a simple test app and it worked.

Thank you!

(if anyone wants to see the test app just ask and I will post)

1 reply

Inspiring
June 4, 2008
a class doesn't really talk to a class - rather an object which has been created by a class talks to another object. (unless a class calls another class, but I don't think thats what you mean).

to begin OOP in AS3 (or AS2)- pick up Moock's book - or a "friend of ed" book. they'll help out greatly.

{ I always base my class structure of visuals first. In fact, in starting- just ignore trying to write abstract classes, and just write classes that extend Sprite. }

However, ignore all that. to get two objects to talk with each other all you have to do is register them with each other and they can call each other....

var Obj_One = new SuperFakeObjectOne();
var Obj_Two= new SuperFakeObjectTwo();

Obj_One.setObject(Obj_Two);

//then on the SuperFakeObjectOne class ...
public var objectToTalkTo:SuperFakeObjectTwo;

public function registerObject(obj:SuperFakeObjectTwo) {
objectToTalkTo = obj;
}

//////////////

thats kind of a lot if you're just starting, but maybe it helps a bit? ;)
jshields55AuthorCorrect answer
Participant
June 4, 2008
Well Mr Helpy mcHelpson you go down as AWESOME! in my book. I built a simple test app and it worked.

Thank you!

(if anyone wants to see the test app just ask and I will post)