Copy link to clipboard
Copied
Hi !
This is a trouble I've been facing for YEARS, and no way for me to solve it. Save me my heros.
I'm trying to animate a character with Flash whose face can be changed.
So I have a Character MovieClip in which I have 4 frames. In each frame there is an animation of the little guy : one going down, one going left, right, and up.
In each animation there is the MovieClip Head in which you can attach a hat, sunglasses, hair etc... Am I clear enough ?
Here is the problem : since the head is going to be changed by the player, the MovieClip Head MUST have the same reference in each frame in each animation. Unfortunatly, Flash thinks the MovieClip Head is a new one on each animation of the little guy running. So for instance, if I attach sunglasses on the clip Head, then they will disappear as soon as the character will change his direction since Flash doesn't know the Head I'm using in the new animation isn't a new one.
What am I doing wrong ?
If I'm not clear enough, please tell me. I REALLY want to understand how to make such a thing on Flash.
Copy link to clipboard
Copied
remove the head movieclips from the 4 frames.
use addChild to add your head movieclip to your 4 frame movieclip. position it appropriately depending on which of the 4 frames is being displayed.
Copy link to clipboard
Copied
Thanks for your reply! That's what I first wanted to do. The problem is that the movieclip Head has to move during the animation, so I can't just simply attach it with a constant position. How would you solve it?
Copy link to clipboard
Copied
What you need to do is simply have your body be a Graphic symbol that is set to "play once". Put this inside a Character movie clip that is 4 frames long. Put the head in a separate layer that extends all 4 frames. Now, when your Character MC is in frame 1, you'll see frame 1 of the body, but the head will stay the same. When you go to frame 2, you'll see frame 2 of the body, and again the head will stay the same, etc.
For more on this, see Flash's Underrated "Graphic" Symbol. I'd also highly suggest How to Cheat at Adobe Flash, as it is a great exploration of the animator features of Flash.
Copy link to clipboard
Copied
you attach it to your 4 frame movieclip. it will then move with your character.
Copy link to clipboard
Copied
I'm so sorry but I want to be sure to understand what you tell me to do.
My Character class is made of a Head MC that has one animation per direction to go to. For instance, when you're facing right doing nothing, the head keeps moving up and down like if the little guy was breathing. So what you tell me to do is to remove the Head MC from each of animations and then attach a Head MC. But then the animation would be empty. How the Head could know how it has to move ?
Can you explain me once again? I'm so sorry for wasting your time...
Copy link to clipboard
Copied
Your Head MC would still be a MC with all the head stuff in it. Your Body MC would be a graphic symbol without the head in it. You can actually set it to be a graphic on the timeline and leave it as a MC in the library if you want. You'd then have a Character MC that contains both the head and the body.
I'm assuming that your head already does what you want based on the fact that you want it to be a single instance, but you might need to use goToAndStop to get it on the frame that is pointed in the correct direction. It's a little fuzzy whether the hats and such have to change directtion with the head, so it's hard to give you 100% of your solution.
Did you read that article that explains the basics of graphic symbols? You're probably better off gaining the foundational knowledge yourself and looking at your own code and figuring out how the concepts apply vs. asking someone who is not able to see your code to spoon-feed you the entire solution.
An entirely different solution is to use a getter/setter pair for your head property instead of just using a public var declaration and then just set up any head you get based on what the current state of the hats should be.
Yet another solution is to watch for ADDED_TO_STAGE and update any new "head" objects you get based on state.
I've used all of these solutions. Which one I choose depends on a lot of factors, and it's difficult to know which is best based on the limited amount I know about your project.
Copy link to clipboard
Copied
Thank you for making things a bit more clear, Amy. This is something that seems pretty simple to solve but each time I think about it I get really confused. I've read your article but it shows a way to do that would not fit to what I need.
I get confused when you speak about the body and the head so let's make things clear : my character is made of a big head, legs and arms. Here it is : http://kromahtique.bl.ee/swf/char/cabine.swf
As you can see I have a character class made of 2 frames : one with the man standing, the other one walking (don't mind the other frames, let's only focus to those two). So each frame in the class character is made of one single movieclip containing the head (http://kromahtique.bl.ee/swf/char/corps.swf), arms, and legs moving or not. That's how I get stuck. If I want to attach something to the head (like a fancy hat) then I have to access the head through the animating mc. That's why I can't simply attach the head dynamically to another clip since it has to be include into a movement interpolation to be animated. Do you see what I mean ?
I really feel like I'm upsetting with this so please tell me if I get to confusing or whatever.
Thanks you so much for your long answer by the way.
Copy link to clipboard
Copied
Kromah wrote:
Thank you for making things a bit more clear, Amy. This is something that seems pretty simple to solve but each time I think about it I get really confused. I've read your article but it shows a way to do that would not fit to what I need.
I get confused when you speak about the body and the head so let's make things clear : my character is made of a big head, legs and arms. Here it is : http://kromahtique.bl.ee/swf/char/cabine.swf
As you can see I have a character class made of 2 frames : one with the man standing, the other one walking (don't mind the other frames, let's only focus to those two). So each frame in the class character is made of one single movieclip containing the head (http://kromahtique.bl.ee/swf/char/corps.swf), arms, and legs moving or not. That's how I get stuck. If I want to attach something to the head (like a fancy hat) then I have to access the head through the animating mc. That's why I can't simply attach the head dynamically to another clip since it has to be include into a movement interpolation to be animated. Do you see what I mean ?
I really feel like I'm upsetting with this so please tell me if I get to confusing or whatever.
Thanks you so much for your long answer by the way.
I think maybe we're miscommunicating, so I created a demo that shows the graphic solution I first mentioned. Can you tell me where that's not meeting your needs? If necessary, I can build out the other two solutions--I created the foundational code so it's really easy to add the other solutions.
Copy link to clipboard
Copied
Thank you so much for your response and for your example. It did help me a lot even if I had to look at it for a long time to understand some of the things you've done. You have a way to code which is totally different from what I'm used to doing, which makes me think I should rethink my way of doing.
I've made a little example to show you exactly what I need to do. You can see a Character MovieClip which can do different actions : wait, dance and sit. Each animation is a MovieClip in which there are the body doing the action and the head, attached to the body. You can also see a button "Put a hat" which is not working. That's the thing I need to know from the begginning of this thread. How can I access the head to put a hat on it ? And how can this hat can keep being on the head, even if the character goes from an action to another (dancing -> sitting -> waiting -> dancing...).
Direct link to download it : http://kromahtique.bl.ee/Kromah_Example.zip
Oh and if you see some things that I should be doing in my code, do tell me. I'm here to learn
Copy link to clipboard
Copied
Hi, Kromah
I've edited your files and updated here.
From looking at your files, I decided that the easiest solution without totally restructuring what you had would be the third solution, watching the stage for heads to be added, then updating any head you happen to get.
To make this work, I ran the Set Instance Name on Multiple Frames extension to set all of the Head layers to "head." The reasoning behind this was that you didn't have a Class name assigned to your Head instance, so I fell back on checking to see if the instance name was "head." So the instance name needed to be assigned to be head.
A few other things I noticed:
Update: The Apache Flex standards (which is what the old Adobe standards became) can be found here.
Message was edited by: Amy Blankenship
Copy link to clipboard
Copied
Hi Amy. I can't thank you enough for what you did. You figured out how to solve my problem very easily and your solution is perfectly working. You did a great job ! I'm taking your advises very seriously and I'll do my best to apply them as soon as possible. There's only a little point I didn't get in your solution. You made me download an extension to be able to name an instance on multiple frames. I did install it but it appeared that your solution is perfectly working without this extension as well. Would you be able to tell me why ?
Anyway, I insist on thanking you again for you solution which is very clean and that I'm now very proud to use.
Copy link to clipboard
Copied
I already ran the extension, so everything was already renamed. I was just telling you where to get the extension for future reference. You may want to poke around on the site and look at all their other extensions. I use many of them daily .
Copy link to clipboard
Copied
Well I finally found how to solve this but I guess it's not the best solution. I decided not to have animation clips at all and then put every character animation together and separate them with labels. Doing this way, accessing Head mc is really easy and i can do whatever I want with it. What a shame it's not a good looking solution...