Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com
polyGeek.com

Pledge drive: Help me help 360|Flex who is helping me

The 360|Flex conference is coming up soon - March 8-10 in San Jose. It seems that John and Tom - the organizers - have everything ready to go except for one little item: getting a sponsor for the USB Thumbdrive that comes in the swag-bag. They offered it to me but it's a little out of my marketing budget for RunPee.com - which is zero dollars. But they are on the hook either way so we worked out a deal. I'll start a pledge drive and try to raise as much money as I can to cover the cost of sponsoring the thumbdrive - $1,300 target. In exchange they will put RunPee.com on it. I'm not on the hook for anything except trying to raise money to cover their costs so that they don't take a loss.

We would all appreciate it if you chipped in a few bucks. I will give every dollar donated to my Paypal account to 360|Flex up until the conference is over. Let me know if you would like for your donation to be public or not because I'll keep a running tab on this page of who donated and how much.

Paypal donations to: Dan@polyGeek.com

Thanks for your support,
Dan Florio, John Wilker, Tom Ortega.

Dan Florio ( that's me )-$100, Lee Button-$100, Randy Troppmann-$100, David Ortinau-$50, Faisal Abid Founder-$55, Pintley.com-$50, Douglas Reynolds Consulting-$50, Nick Kwiatkowski-$25, Patrick McDonald-$10, Jeremy Saenz-$25, Ivan Alvarez-$25, Jen Floyd-$10, Matt LeGrand-$25, Jens Brynildsen-$25, Gates M Stoner-$20, Emerson Tyler Wright-$50, John Daily-$10, Jason Fincanon-$25, Evan Zeimet-$20 Here is a complete list of the people who have donated

Finding a MovieClip’s indexNumber

December 27th, 2006 . by polyGeek

Suppose you use a loop and the createEmptyMovieClip method to create some MovieClips like so:

If you ran this code and hit Ctrl+L you would see that you have created 5 empty MovieClips.

Level #0: Frame=1
Movie Clip: Frame=0 Target=”_level0.clip_0″
Movie Clip: Frame=0 Target=”_level0.clip_1″
Movie Clip: Frame=0 Target=”_level0.clip_2″
Movie Clip: Frame=0 Target=”_level0.clip_3″
Movie Clip: Frame=0 Target=”_level0.clip_4″

Presumably you would then attach some assets or load something into these clips.

In such instances it’s pretty common that you will write code to deal with user interactions with these clips. If so you’ll need to know which clip is being interacted with. It’s probably best to dynamically create variables on the clip that will help you identify it but you know what? You already have. You have the MovieClips name clip_#. So what you really need to know is what is the index number at the end of the MovieClips’ name.

That’s easy enough to find using the split(“_”) method as such:

this._name.split(“_”)[1];

That works well enough assuming you used an underscore during the creation of the MovieClips. What if you used a hyphen or even no separator at all?

I’ve had to deal with this often enough that I created a utility class to deal with it. Here’s the general code removed from the class that you can use or you can download the Find class which has this method plus a lot of others for helping you find MovieClips by size, _alpha, position, etc.



Note that this function returns a Number not a String. So if you have a clip named clip_01 then what you will get back by calling mcIndex(clip_01) is the Number 1.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

4 Responses to “Finding a MovieClip’s indexNumber”


comment number 1 by: Keith Peters

I hate to say it, but that’s a really overly complex way of doing it. Just assign an index variable at creation time:

this.createEmptyMovieClip(”clip_” + i, i, {index:i});

then you can get the index as a direct property.

trace(someMc.index);

comment number 2 by: polyGeek

@Keith, Thanks for pointing that out. You’re absolutely right. Many of the developers I work with aren’t really comfortable with that approach. It seems simple enough to me, and you, but many developers out there are confused enough by scope issues and such but they have a handle on instance names. So I created this utility for them.
In my code I would do something like this:

var mc:MovieClip = this.createEmptyMovieClip(“clip_” + i, i);
mc.index = i;
mc.onRelease = function…

Oddly, I know how to use the notation that you suggested but I never do. It just doesn’t seem as readable as my approach. To each his own.

comment number 3 by: Keith Peters

Yeah, in practice, I’d actually do it the way you wrote it. I’m not a big fan of the initialization object. Not very readable.

comment number 4 by: Randy

I think it is better to use events to deal with movieclip interactions. So if a movieclip is interacted with it broadcasts the event and when you capture the event you will have a reference to said movieclip. But on second thought, if a developer has trouble with scope, event handling may not be the best idea. (apparently I cant add ;)

   Welcome back (Change)

Leave a Reply

comment feed RSS   subscribe to this comment thread

Recent Posts

   



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud