Not many people do this but I've gotten good advice here in the past.
I'm doing my first client project in Actionscript 3 and I'm hitting a few snags with AS3's new rules.
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
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 communicated 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.
this is a discord of mostly PA people interested in fighting games:
https://discord.gg/DZWa97d5rz
we also talk about other random shit and clown upon each other
Posts
"Stage" isn't an object in AS3, it's a class name. Now, every display object has a property "stage" (or "this.stage") which refers to the main area - "this.stage" is for AS3 what "_root" used to be.
In your "for each" example, if you were to change "Stage" to "this.stage", I still don't think it will work. You're basically saying "give me each element within stage, treat it as a StoreClip, and do something with it", whereas I think you're trying to say "get me all the things that are StoreClips within the stage." I'm not sure how you would do this.
Also, just as a side note, stage probably only contains one element - a Timeline object representing your main timeline, and all your movie clips are part of that timeline. You might be adding the movie clips directly to the stage itself, but typically you add them to the timeline instead.
Have you thought about having the constructor of the movie clip just make its own event handler? Like, in the constructor, saying "this.addEventListener(blah)"? If you can avoid having the movie clips add themselves to a big list I would do that, but you might not be able to.
Anyway, concrete suggestions: to fix (2), if you are adding the movie clips to the timeline, you might have to say "parent.parent" - try tracing parent and see what it actually is. A slightly messier suggestion, keep everything rolled up within the StoreClip class by having the constructor say "prototype.storeClipArray" - each instance of StoreClip shares one common prototype, so you could stow your array in there and all the clips could have access to the list.
Sorry for the disjointed text, hope something in there helps!
The reason I want to put the clips in a large list is because I'm going to have to dynamically interact with them without using mouse events.
To be specific, I have a dropdown list which contains a series of store categories, selecting a category would then highlight all the stores in that category.
I don't think "Oh hey, you selected Clothing"
store4.highlight();
store7.highlight();
store24.highlight();
Will wouldn't be very pretty.
They took away eval(), so I was planning on handling this functionality by looping through the array of store clips and checking conditions against my data arrays to see if that particular store needs to be highlighted.
Something like
For (i=0;i<storeClipArray.lengh;i++)
{
//Check to see if this storeID is associated with X category
}
I suppose the "real" way to do this would be to create my own custom event handlers, but.... yeesh, I'm not sure I'm ready for that quite yet.
we also talk about other random shit and clown upon each other