Solved

AS3 class communication

Posted on 2010-11-10
2
488 Views
Last Modified: 2012-08-13
I have a button created in one class. When that button is clicked, I believe I need to add a dispatchEvent so that I can listen for that in another class. Is that correct, or is there a simpler, more elegant way of reacting to that in the first class?
0
Comment
Question by:msukow
2 Comments
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 34103708
That's correct. The way of communicating between objects is through the event model. Dispatching custom events in one and using event listeners to gather the information.

"Elegant code" is pretty much in the eye of the beholder, there really isn't a common definition, some say it's the juxtaposition of simplicity and functionality, some others disagree and state that "elegant" code is all about readability, since you can do a lot in one line, but if nobody can decipher it but you, then it isn't "elegant".

All that just to say that maybe a different approach will look better to you, perhaps searching in the Display List if both classes are there would seem to be a better suit in some cases... but I'd always go with the event model, it adds a lot of readability to your code, especially if you're using custom classes and not just a string literal, it's simple and works fine, but in the end, it's your call!

Good Luck.
-V
0
 

Author Closing Comment

by:msukow
ID: 34103780
Thanks for the confirmation
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Changing Audit Policies through scripting 5 69
Auto-indent certain lines in Notepad++ 10 112
Need some help with powershell script 5 55
How can i open a .fxp file 3 40
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The viewer will learn how to count occurrences of each item in an array.
The goal of the tutorial is to teach the user how to how to record live broadcast.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question