Solved

AS3 class communication

Posted on 2010-11-10
2
487 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 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