Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 01-29-2008, 07:53 PM   #1
Jasconius
Registered User
 
Join Date: Jul 2007
Posts: 10
Default A couple of AS3 questions

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.
Jasconius is offline   Reply With Quote
Old 01-29-2008, 09:05 PM   #2
tommymcglynn
Registered User
 
Join Date: Jan 2008
Posts: 13
Default Try this

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?
tommymcglynn is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 05:24 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.