Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AS3 class communication

Posted on 2010-11-10
2
Medium Priority
?
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 2000 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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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