Best way to be able to pick multiple colors/designs of symbols dynamically from flash

混江龙づ霸主 提交于 2019-12-24 10:36:23

问题


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!


回答1:


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!)


(source: webfactional.com)




回答2:


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.



来源:https://stackoverflow.com/questions/2435039/best-way-to-be-able-to-pick-multiple-colors-designs-of-symbols-dynamically-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!