ActionScript 3 movieclip with interchangeable images - actionscript-3

I'm creating a game using Flash Develop and ActionScript 3.0 and I can't figure out how to make a "Character Creation" menu, in the sense that, I want to animate a movieclip full of images (head, torso, arms, etc.) and then change out any image with another.
So I'd like players to be able to choose what kind of sunglasses they want their character to have, for example, and the different sunglasses will keep the animation that I made with the original ones.
From what I know so far I can export a movie clip as a .swf and use it as such, but how do I change out images and keep the animation?
Any suggestions are greatly appreciated.
Thanks!

I don't know how much actionscript you know.. but if you just want an idea how to do it and not the whole thing in code...
I would personally make different movie clips for the different parts of the body that can be changed and then change frames in that move clip. For example one movie clip with different hairstyles, one with (sun)glasses and so on.. and then just go to then next frame in the "hairMC" to change the hairstyle.

The way I'd do it is to create MovieClips that all implement the same Interface and then have other MC's higher up that know how to use the particular Interface. For example, if you had an IArm, it might know how to swing and how to grasp (and it might grasp by using an IHand). A fat ITorso might attach the arms at a different spot than a thin one.
And your Character might have an IHead, ITorso, etc. When you created a Character, you could either pass in these components via the constructor (I'm not a big fan of constructor arguments for Views, but it's one way to do this), or you can expose setters on your Character that allow you to set these properties one at a time.
This gives you tremendous flexibility in how to put your character together--none of the pieces know precisely how the others are put together, but the methods they need to operate on are in place, so you can put in any implementation you can think of.

Related

Understanding AS3 parent/child relationships

I've looked around the site, but as a beginner, the AS3 lingo is a bit beyond me. I know that parent/child is used to pass information, commands, and variables between scenes and movie clips embedded in each other, but I don't quite understand HOW or WHY it works.
When I say beginner, I mean it. This is my first flash project. In case it helps, this is what I'm trying to do:
I'm making a type effectiveness calculator for Pokemon. I've successfully made 3 movie clip "dials" that will cycle through the different Pokemon Types when buttons on them are pressed. 18 Types, 18 frames per "dial". 19 frames on the third "dial", for a blank type.
I've also made a 4th movie clip that will display the effectiveness, from 0.25x up to 4x.
So, basically, I need to...
1) Pull either a numerical variable (or frame number) up from each of the "dials"
2) Calculate the effectiveness based on those numbers in Scene 1 (or a new, all-inclusive movie clip if that's easier)
3) Then send the result (or desired frame number) down to the 4th movie clip to display the effectiveness.
Aaaaaaaand I have zero clue how to do that. I'd appreciate an explanation as opposed to just telling me how. I WANT to understand.
Thanks in advance, everyone!
You are wanting to understand Object Oriented Programming. Specifically the concept of "containers". Google "AS3 OOP containers tutorial" and you'll find what you need.

coloring multiple frames in Flash Professional CC

I'm brand new to Flash Professional and wanted to make a short 10 second clip. Instead of looking into using tweens and symbols (I wish I did) I used Flash Professional as a flip book, illustrating sketches for each keyframe.
I'm now in the colouring process and want to know if there is a way to colour an object (I've drawn with the brush tool) throughout multiple frames. is this even possible?
I understand there are some short cuts to repetitive tasks using ActionScript. But, once again I am brand new to Flash Professional and haven't tried anything in the ActionScript. I do however have a very basic knowledge of HTML coding and some javaScript if it helps at all…
If there is an alternate solution like exporting the file to another Adobe program that has a "colouring multiple frames" feature, that would be great too.
Sorry to say, to do that, you WILL have to work with symbols. However, this is an easy fix.
Select the object you want to color, click Modify--> Convert to Symbol. Give it a good name, and set it to MovieClip. Click OK.
Now, in the Library panel, double-click the icon next to your symbol name. Color as you wish.
There are multiple ways to put this on your timeline. You could replace each instance of that drawing with the symbol. Or, better, you could create a new layer with only one keyframe (and regular frames after that to the end of your animation. Place your object on that layer, and then remove all the old versions of that drawing.
NOTE: You will need to be mindful of where in the stack you put layers, as that sets the z-index of everything on that layer.

Working with Graphics in Actionscript

i haven't worked with graphics until now.. so I have not much ideas about using graphics objects in flash cs6.
I want to move this character depending if the person has pressed a button and stop his movement once the button is released. I looked up on how to go about this process.. so far one thing that kept coming up was to turn my spritesheet into graphics.. but after that i couldn't really find anything on how to integrate this into actionscript. Plus when I convert an object into graphics it doesn't give me options to assign it a class name. so can somebody give me a good breakdown on what is the purpose of these graphics objects? and how should I go about making a sprite move?
Disregard information concerning sprite sheets. These are used as a completely different method of graphics rendering that I'm not going to cover here; for more advanced, high performance applications and games.
When you say Graphics, I am assuming that you mean you've created some drawings that you've converted to a Graphic like this:
These types of objects are used purely for timeline animation. What you want to use here is the type MovieClip. When you use this type, you'll be able to give the object a class name like you mentioned:
After doing this, you'll be able to refer to that library symbol in ActionScript like this:
var gr:MyGraphic = new MyGraphic();
addChild(gr);

How to create a foaming or gases effect in flash?

I am trying to create an animation for lemon juice and baking soda experiment, and I was wondering how can I create a foaming effect such as the one shown in this image:
The idea I have in mind is to simply draw a foam in photoshop and then use motion tween to change the size. I was hoping I could find a better solution to this.
I have something somewhat similar that you can probably use as a springboard for doing your own thing.
http://www.shaunhusain.com/SteamEffect/
http://www.shaunhusain.com/SteamEffect/srcview/index.html
Currently I'm just drawing some circles with this and then setting a blur on them (not very efficient I know but it served the purposed as I didn't need it to create a bajillion particles to still be effective as "steam" which was the intended goal). You could swap out the shapes/filter I'm using for your own drawing and use the same basic structure.
EDIT
Perhaps this requires at least a little explanation:
Basically you'd want to look at the two files SteamCanvas.mxml and BitOfSteam.as. To be honest I have no idea why I decided to write SteamCanvas as an mxml file. I chose to use Canvas as the base class so I could just wrap it around any other component as a container and be able to detect mouse clicks anywhere within a region. If this is being used in a pure Flash environment, that is one not using the Flex libraries (or mxmlc compiler) it could be changed to extend from Sprite and be written purely in AS3, essentially just the creationComplete code should be moved to the constructor. How this works is the SteamCanvas is a wrapper for whatever controls or components you want to put in it (just like a normal canvas uses absolute positioning, but could have containers that define layout nested within it if need be). The SteamCanvas sets up a timer and if the mouse is down when the timer ticks, it creates instances of BitOfSteam and sets the properties for the steam based on the SteamCanvases own currently set properties. In the project you'll also see a SteamEffectTest.mxml which is just the file you see running that has the sliders on it to change the properties of the SteamCanvas, I used these to come up with what I thought were good values to make somewhat realistic steam. If I remember I'll revisit this component tomorrow and try to take Marty's suggestions to get it updated.

Representing a Monopoly board in flash?

I'm brand new to Flash (and game programming, really), but want to learn a bit of it. My overall learning project is to create a Monopoly clone in Flash. Unfortunately, I'm struggling to get over even my first hurdle - how to create the board graphically, and how then to deal with it in the code. So far, my thoughts are to break the board down into the different sizes of tiles (the normal property ones, the corner 4 and a large one for the middle section), then somehow place these all in the correct position relative to each other and keep that positioning correct as the pieces (and thus the camera view) move about the board. (And, hopefully some day have a zooming ability too...)
Is this a good approach, or is there a better one? Does anyone know where I can find a tutorial specifically on creating board games in Flash (any sort really, wouldn't have to be Monopoly but just a game that has a board which tokens move across - and preferably which has to pan as well).
Also, as an aside, is there any way to have a dynamically coloured rectangle in a flash MovieClip (like you can have dynamic textboxs)? I ask because it would be useful if there was, as I could generate every property tile with just one MovieClip which took a name, a value and a colour...
everything you describe here you can do pretty easily once you get the hang of component sprites. personally i would make a single sprite that will then hold all of the "tiles" in the game, this would allow you to "zoom" the board while keeping all the pieces relative:
if you create this parent to have an addTile() and getTile(index:int):Sprite method then you can easily push the tiles and retrieve them from an array, so that Go is at index 0, old kent road is at 1 etc. that way you can use a single integer value to determine the position of the player piece as you can then use getTile(int).x etc.
the position of the tiles themselves can be worked out relative to the others. if you have a tile that is 20px wide and 40px high then you can position the tile as x = index * 20 for the first row, after the initial 11, you need to rotate them all and then use the y index instead (rotation = 90; x = 11*20; y = (index-11)*20) this will depend exactly on your origin point of your Sprite.
to draw coloured boxes you use the graphics of the Sprite, there are plenty of tuts on API drawing out there, but here is a basic box of 10x10px:
var drawing:Sprite = new Sprite();
drawing.graphics.beginFill(0x0000FF);
drawing.graphics.drawRect(0, 0, 10, 10);
drawing.graphics.endFill();
Another approach to your question could be to learn about Object Oriented Programming. That may not solve your representing the board graphically straight away, but it would definitely help you structure your game.
With OOP, you could define a "Property" Class with a set of properties such as streetName , color , price etc... I haven't played Monopoly in a while but you can get the general idea, i.e. to create a base object and make it specific by setting the object's properties. Your question about the colored rectangle can actually apply to other properties, a great way to avoid unnecessary repetition.
Broadly speaking OOP tends to emulate real life situations, so you could actually look at your Monopoly game, break it into its various parts, find common properties etc... I won't start a lesson here :) I'd be pretty bad at it, but there's plenty of resources out there . Look for OOP, Design Patterns & Actionscript3.
After a little research, you may find that your question about how to handle graphics may not be such a problem after all.
Your questions are way too general. I'm sure you don't want us to walk you through your whole project right?
Now to gain some experience, I suggest to you simply work through a few flash gaming tutorials. There are a LOT of those, I googled for 2-3 seconds and found this:
http://pelfusion.com/tutorials/35-flash-game-development-tutorials-fla-files/
I'm sure you feel disappointed by this answer, but this is the first step in solving your own problems. The internet has more than enough general game tutorials already. If you have specific problems, we might be of better help to you.
I assume with dynamically colored rectangles, you mean simply changing the color during runtime. Well you simply give the rectangle a name, and change the color property of it in code. Like this: rectangle.Color = Something.
You might want to start out with a simpler project just to learn some of the basics, maybe a little game where the player has to move a rectangle from one side of the screen to the other using the arrow keys or mouse, upon which a score is incremented or something. This will help teach you how the coordinate system works, among other things.
To draw stuff using code, you can create a new Sprite or MovieClip object and use its graphics property to draw primitive shapes (rectangles, etc.) to it at runtime.