How to structure code/frames in Flash - actionscript-3

I'm working on a Flash game where there are scenes that display a few stages of animation; the animation is controlled by user-clickable buttons (1 through 4) and a progress bar which increases by some amount with a timer.
Right now I have each stage of the animation on a different frame, but I'm not sure how to share the Actionscript and state (e.g. value of the progress var) across the frames.
Should I consolidate these frames into one and let each piece (the buttons, progress bar, and animation) all be three separate movie clips that are controlled by the actionscript of that frame? Or is there another way to do this properly?

What you said is probably the best solution in this case: put everything on one frame and control with ActionScript. The buttons can be their own MovieClips (or Buttons), the progress bar and animation as well. You can then have each stage of the animation on a different frame within the MovieClip, and control which frame appears when using gotoAndStop().
Generally I only use the base frames (i.e. those at the root of an SWF) as animation frames if the SWF is purely animation with no or minimal ActionScript involved. In any other case (games, applications, etc) it's always better to have animations in their own MovieClips, so that you can control and manipulate them easily.

Related

8-direction Figure Animation with Arrow Keys

I've been charged with designing a demo for an isometric video game in ActionScript 3. I have the bitmap spritesheets that show the avatar I'm using standing and walking in each direction. The walking animation is made up of three frames.
My problem, though, is that I need to figure out how to make use of them. I'm not familiar with animation in Flash, and I need input on how to gotoAndPlay() the walking frames for the right direction. I don't think isolating the necessary DIRECTION is going to be a challenge, so much as starting it and keeping it going while the arrow keys are down.
My current code is basically comprised of keyboard handlers for KEY_UP and KEY_DOWN, each containing a switch-case statement that changes the Avatar.currentDirection property. The handler continues to fire while the keys are down, but I need to add animation to the game.
I've seen some examples where they simply embed the animations into an SWF, propagate an array of the various walking stages, and alternate between them using an EnterFrame event handler, but this seems really clunky. I guess in the end I'm trying to make use of Adobe Animate, but I don't know how you're supposed to do that.
Ops, fortunately i'm working with sprites (atlas animations) right now!.
if i'm right, you just needs to use them for playing some animation with functionality.
if you have a well sized sprite which is tiled with isometric slots like it:
(9 frames sized 64x128)
your work is very easy, only create new movieclip from library, inside it, create a borderless rectangle (which is our mask) in a layer (named mask) then import image to the project, and its better to disabling smooth ability from image properties,
now, inside your movieclip, you have to create new layer (under the mask layer) and add your sprite image for each frame, and change its position:
at last, enable masking for mask layer, then its time of coding,
name your animation queries (like image 3) and for loopable animations, insert gotoAndPlay('anim_name') inside last frame. i hope you are familiar with controling movieclip animations which is basic consept of any flash project.
now to extend it for 8 directions support, you just need to play and switch between dirctions according single and multi keypreses,

AS3 Wheel of Fortune spinning

I'm working on wheel of fortune project but i'm currently struggling with the code.
I have attached the design of the wheel. I'm not a coder, i'm a designer and I need to do all the animation and the effects but I want to do it professional and that part is very important.
What I want to do is when you click on the spin button the wheel to rotate for 4-5 seconds with ease in/out effect and to stop each time on different random sector. Ill do different animations for each sector in separate movie clip and when it stops on a sector I want the movie clip related with that sector to start playing.
My idea is to make the wheel as a movie clip and each sector animation movie clips to be nested in it so when it stops that specific movie clip starts. Maybe I need to make each position of the wheel on key frame and to place the animations on these frames, but not sure if that is the right way.
One of the thing is that these movie clips with the effects should be easy for re position. I need to move them on the stage if needed and that's why i don't want them to be triggered with code.
If you can guide me step by step how to do that part I will appreciate your help. wheel design
Ok guys. There is a thread already for that and its something what I'm looking for. I like the example of the last answer in that thread, but I think that the first code will be more useful for my needs after that.
Can someone help me to make the code working, because I couldn't. All I need at the moment is to make the wheel spinning for 4-5 seconds on button pressed with ease in/out and it stops on random sector. Here is the link of the thread.
Spinning Wheel in flash AS3
I suggest you not to use keyframes at all. Use only one single frame, and in code, using a main class, instantiate all elements you need. To spin the wheel, you can consider using Greensock TweenMax or embedded tweening classes from Adobe. Also, spinning the entire wheel with all movieclips with nested animations inside, in spite animations are not running, forces to render all nested movieclips at each frame with a very heavy calculation load. I would suggest to either use 2 different clips, and add the animated one only when you need it, or at least to cache tentire wheel as a bitmap, and then uncache it when some animation is running inside.

Settings screen in Cocos2D game

How are settings screens created in Cocos2D games?
I've considered using a UIViewController subclass however pushing it in Cocos2D seems hacky. I've also considered using a CCLayer with buttons etc as child nodes. Then I could animate this layer in/out when appropriate. Is this the common way?
If you are using Cocos2D for your game, you should probably get in the habit of building your settings screens as Cocos2D scenes or layers, which offers the benefit of easily animating them into and out of the frame during your game. Adding a view controller is not necessary and actually complicates things when it is so easy to just create a CCScene or CCLayer.
I prefer the CCLayer approach, then I can animate the layer swooshing into the frame when a user presses a Settings button. The underlying game play is not erased since it is the same scene.
Another approach is to pop a settings scene onto the current scene.

How to handle mouse events on occluded (overlapped) display objects in flash/flex?

my questions is little similar to some of the questions asked previously about overlapped sprites/movieclips like this. But my requirement is slightly different than them.
I want to handle the mouseevents for all the sprites on the stage including the one those are hidden behind (or overlapped or occluded) and the main condition is that I want to handle the occluded sprite (that hidden behind other sprite). example, say I have sprite1 and sprite2 on stage and I want to start drag whenever i click on the sprite and stop drag after another click.
This can be done easily, but the problem and my main requirement is that if I drag the sprite1 and drop it exactly on top of the sprite2 then sprite2 will be hidden behind the sprite1 I wont be able to drag the sprite2 without moving the sprite1 first. if you have played zynga's empires and allais game on facebook, it is handled seperatly, it is how it works in that game, the mouse event is triggered on the sprite behind the overlapping sprite, if you have two sprites overlapping one sprite than the mouse event is triggered on the sprite which is last and not the one in front irrespective of whether there is only one sprite overlapping or two or three and this happens to irregular shaped sprites (not just rectangles)
if any one can give me hit on how zynga might have implemented this or help me find out how to achive it it will be great help
thanks
One possibility is that the game is not listening to the click events from each separate sprite.
When programming games, you often implement a grid system. If this is the case, the programmer has a record of where all sprites are placed on the grid. The programmer could then listen for a click on the entire grid renderer and work out the selected object by referencing the mouse position against the grid records.

Let system time determine animation speed, not program FPS

I'm writing a card game in ActionScript 3. Each card is represented by an instance of a class extending movieclip exported from Flash CS4 that contains the card graphics and a flip animation. When I want to flip a card I call gotoAndPlay on this movieclip.
When the frame rate slows down all animations take longer to finish. It seems Flash will by default animate movieclips in a way that makes sure all frames in the clip will be drawn. Therefor, when the program frame rate goes below the frame rate of the clip, the animation will be played at a slower pace.
I would like to have an animation always play at the same speed and as a consequence always be shown on the screen for the same amount of time. If the frame rate is too slow to show all frames, frames are dropped. Is is possible to tell Flash to animate in this way? If not, what is the easiest way to program this behavior myself?
The easiest way would be to use a Timer (or a setInterval) triggering every 1000/fps milliseconds, telling your MovieClip to go to its next frame.
If you need something more accurate, you'll have to check the time spent since the last update (stolen from the first comment of this article from Keith Peters' blog, which explains everything pretty well).
It's been a while since I used Flash but from what I understand it's not possible because Flash uses a frame based animation model.
Silverlight however uses a time based animation model and will just draw as many intermediate frames as the frame-rate allows.
The tween class (fl.transitions.Tween) is perfect for this situation. By setting the last argument of the constructor to TRUE then it bases its animations/triggers off of seconds, and as far as I know it compensates for FPS loss/gain.
You can easily use it like the Timer class by passing a new object (Trigger(new Object(), "x") to the constructor and creating a listener for MOTION_FINISH (TweenEvent.MOTION_FINISH) to trigger your event!
I use Tweens for a LOT of things because they're easy, fast, and supported by everything. And like I said, it should solve your FPS/lag issues since it adjusts to FPS changes in real-time (as far as I know!).