This is a discussion on "How to correctly control one MC with another - custom listeners, classes or strings?" within the Flash & Multimedia Forum section. This forum, and the thread "How to correctly control one MC with another - custom listeners, classes or strings? are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
How to correctly control one MC with another - custom listeners, classes or strings?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
How to correctly control one MC with another - custom listeners, classes or strings?
I run into this all the time, so I assume it's a common and quite basic functionality people use - I'm still not sure how to approach it correctly.
Say I have a large number of MovieClips acting as controller buttons, placed in an array: btns[]. I have a second array of controlled MovieClips that should be activated when the corresponding button is pressed: mcs[]. I don't want to make a custom listener for each clip - instead, I have one listener function that correctly plays whatever MC is assigned to it. Now, I want to simply loop through the array of buttons and assign each button a MouseEvent.CLICK listener that would activate the correct clip. Originally I just wanted to pass the index of the array I am on to the listener, so the MC with the corresponding index would be affected. But of course, you can't pass parameters to a listener... So, what's the best way to get this done? I can think of three: 1) Create a custom event that would pass the index. Haven't tried and have no idea how to do this. 2) Create a custom class that has two MCs as members, the controller and the controlled, and a function that plays the controlled clip. Then simply add the eventListener in the constructor of the class. 3) Name each controller and controlled MC in a predetermined way. Then use strings to activate the correct the correct controlled MC. I've been using method 2, but I get the feeling that I am simply missing something and there must be a much easier way to accomplish this. Any suggestions? |
|
|
|
|||
|
Re: How to correctly control one MC with another - custom listeners, classes or strin
I've done this before. Using AS 3.0, you would add a event listener for the MC. For example:
Hope this helps. |
|
|||
|
Re: How to correctly control one MC with another - custom listeners, classes or strin
Thanks! I got a few other tips in another forum; I'll post them here for future reference. Seems like there is no one "right" way of doing this:
Ok, the other forum seems to be down for some reason, so here's what I remember: 1) Create a variable in each MC and set it to that ms's index in the array. So, if you have an array of button MCs and an array of animated MCs, for each one do something like:
2) Declare a custom class with a helper function. The class has two variables, Btn and MC, and a function with both vars passed as parameters. When the function is called, it assigns a listener to Btn that animates the MC. Sorry - I'm too lazy to write the code out now... For me, option 1 ended up being easiest to implement; not sure which is actually "better". |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Classes | tox0tes | Flash & Multimedia Forum | 1 | Nov 9th, 2007 14:12 |
| Classes in PHP | pas2gether | PHP Forum | 11 | Oct 13th, 2007 17:24 |
| Using listeners with dynamic textBoxes | DrGonzo | Flash & Multimedia Forum | 0 | Aug 8th, 2007 10:24 |
| Classes | pa007 | PHP Forum | 6 | Jul 12th, 2007 15:22 |
| Classes | Gee Bee | JavaScript Forum | 1 | Mar 8th, 2006 08:31 |