| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Jul 2007
Posts: 10
|
Here's the scenario:
I have a map, with 50 movieclips each representing a store in a mall. Each one of these movieclips has a value appended to them of .storeID so I just set clipname.storeID = 1; and then some mojo fires off based on that later on. My problem is that the mojo can't fire off unless I attach event handlers to each one of these clips. There are 50 of them, and somehow I doubt Adobe's intention was to simply have us type out clipname.addEventListener 50 times. I had two ideas, neither of which I can get to work in AS3. Idea #1) Create a for each on the main timeline, the store clips are actually a special class that extends MovieClip so the actual line I imagined would look something like Code: for each (var clip:StoreClip in Stage) { clip.addEventListener(arg1, arg2); } However the Stage, parent, and this properties seem to be sliiiightly different than they were in Flash 8. If I try any of those, it just doesn't execute the loop at all. I know this works, I just don't know, nor can I find, the proper syntax. Idea #2) Create an array on the main timeline that would store the object reference to each one of the clips, and the clip itself would add itself to the array when it is created. So in the StoreClip constructor, there is a line parent.storeClipArray.push(this); However, this raises a compiler error saying that storeClipArray does not exist, despite the fact that it clearly does. on line 2 of Frame 1 of the FLA. I've been reading that classes communicating with function and variables on the main timeline, hell, even in other instantiated classes is a big no-no, which raises the question, wtf? Any help/links would be appreciated. Thanks. |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Jan 2008
Posts: 13
|
If all of the movie clips are contained within someDisplayObject, try something like this:
var i:int = 0; while (someDisplayObject.getChildAt(i)) { // code here will execute for every child of someDisplayObject. // You could refer to the currently referenced movie clip by first storing it in a variable var thisStore:MovieClip = someDisplayObject.getChildAt(i); // then do stuff to it // dont forget to increment i each time so you can refer to the next child i++; } I assume that there might be children contained within someDisplayObject that aren't stores and you don't want to treat them the same. You could do some type of conditional first to make sure the object you are referencing is in fact one of your "store" movie clips. Does this help? |
|
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A couple of questions about slideshows. | brownmola | ActionScript 3.0 | 4 | 01-21-2008 06:59 PM |
| Couple of questions | deep82 | ActionScript 2.0 | 3 | 09-19-2006 03:59 PM |
| couple of questions | beginner3k | ActionScript 2.0 | 3 | 06-21-2006 10:46 PM |
| a couple of fast questions! | zerosk8 | ActionScript 2.0 | 5 | 05-13-2006 02:10 AM |
| A couple of questions | Lucremonkey | ActionScript 1.0 (and below) | 8 | 08-16-2002 11:48 AM |