views:

54

answers:

2

Sorry the title's so convoluted... I must've tried for ten minutes to get a good, descriptive title! Basically, here's the scenario.

Let's say a user can pick fifty different hat colors and styles to put on an avatar. The avatar can move his head around, so we'd need the same types of movements in the symbol for when that happens.

Additionally, it gets which hat should be on the 'avatar' from a database. The problem is that we can't just make 50 different frames with a different hat on each. And each hat symbol will have the same movements, it'll just be different styles, colors and sizes.

So how can I make one variable that is the HAT, that way we can just put the appropriate hat symbol into the variable and always be able to call Hat.gotoAndplay('tip_hat') or any other generic functions.... Does that make sense?

Hope that's not too confusing. Sorry, I'm not great at the visual Flash stuff, but it's gotta be done! Thanks!

+2  A: 

You could do that a number of ways; firstly you could have each different hat as a different symbol in the Flash Library (if you're using the IDE), and then in their properties tick to 'Export for Actionscript', and choose some appropriate name. It'll tell you that there's no definition for the class path, and one will be created automatically (or something), but that's no problem as you don't need to create a class file for these objects - they're simply MovieClip extensions with some specific data in them.

So if you do that with each hat, let's say you name them Hat_1, Hat_2, etc; then you need to create a 'hat' object inside your avatar's head object. Whenever the hat is changed, you call a new instance of that specific hat object, and put it on the stage:

//when user chooses a hat, however this is done:
var newHat:Hat_1 = new Hat_1();
avatarBody.avatarHead.hat.addChild(newHat);

Then that hat symbol gets added to the hat object of your avatar, and will move with the head object as you'd expect. You can change up the hat on the fly, by simply calling a different hat type and removing the previous one.

Alternatively you could do it by loading in the hat symbols from external images, and storing them in variables for when they need to be added to the avatar object. You'd do this using XML; if you don't know how that's done, I can explain.

debu
Well your first option was what I was going to do. but I quickly found out that we'd end up with a LOT of hats, etc. (the other body parts have this same issue) I guess I was hoping I was missing something and I could have one hat object that I could load in and out the symbol at will. (Or is that basically what you were saying?) Also... which of those two optiosn you suggested are quicker loading?
Cyprus106
I'm not sure what other way you could do it really, but the way I was suggesting would have a dedicated 'hat' object, that could be empty or be filled with whatever you want. It would be the thing you animate, and so anything inside it would animate with it. You would then instantiate a hat, and addChild it to that hat object; yeah I guess you'd have a lot of potential hats, but there's not really a way to get around that. Unless the hat has just one shape and all you're changing is colour / scale?
debu
As for being quicker loading, it again depends on what you're using for the hat objects. If they're vector objects inside Flash's IDE, they'll load quicker than jpegs, and if they're inside the IDE, they'll load when the swf loads (on a webpage for example). If you load each hat in as jpegs, that will have to happen once the swf itself has loaded. Depending on how quickly they load (how small they are), this might be preferable as it means your swf will load faster initially. See what I'm getting at? All depends on how you're doing things I guess :)
debu
Thanks! What would the hat object -be- that the actual symbol? And several hats are different colors only, and then there's a couple different varieties. I've never tried to change a symbol's color. I don't even know if you can, but thanks for the tip! I would have to do less than half the # of hats!
Cyprus106
+1 for hat-related programming question! Think we may need to create a special tag for this... :)
Richard Inglis
So the hat object (the permanent one) could be a MovieClip. Inside your avatar object you'd create that MC, like: var hat:MovieClip = new MovieClip(); and you'd do avatar.addChild(hat); and position it correctly. That object is then the 'container' object for your *actual* hat graphic objects, which are then added and removed as you wish from the hat *container* . Like: avatar.hat.addChild(someHatGraphic); It's definitely possible to do colour changes to MCs, not quite sure how but it'll be easy, so that'd save you having ridiculous numbers of hat graphics :)
debu
+2  A: 

debu's suggestion about a hat container makes sense in order to separate out control of the hat movement.

You could take this further by separating out different aspects of the appearance of each hat (not just the colours, but also style, pattern, size, orientation etc) - this would allow you produce a wide variety of different hats from just a few parameters.

So for example 6 styles x 4 patterns x 8 colours = 192 different hats (without having to draw each one!)

parametric hats diagram

Richard Inglis
Aye, that's a top idea; it'd keep the number of separate images down while maintaining a super large variety :D
debu
It would have toque you much longer to draw them all individually...
Richard Inglis
Excellent comment, and def a +1 for the picture!! That's exactly what I'm doing.
Cyprus106