Subscribe by E-mail:

Tutorial: How to Draw Simple Shapes in AS3


Written By Mr Sun on Sep 13, 2008 at 8:00 am

Hey guys, today we’re going to learn something fun and exciting! That is, drawing shapes in ActionScript 3.0. I’ve actually covered a little bit of this in my platform tutorial, but I want to make it the focus of this tutorial. So, let’s get started shall we?

First of all, we’re going to create a new flash file. Then, we’ll name “Layer 1″ to “actions” because that will be the only layer that we’ll need to use today.

Drawing Circles

In order to draw a circle, we have to place the following code into the first frame:

//defining a new variable that will be the circle
var newCircle:Shape = new Shape();
//now we begin adding a fill to the variable
//this will make the circle red
newCircle.graphics.beginFill(0xFF0000);
//now we call a function that will draw the circle
//the first value (100) is the x value
//the second value (100) is the y value
//and the third value(50), is the radius
//the x and y values count for the center of the circle,
//now the left corner like you'd usually see
newCircle.graphics.drawCircle(100,100,50);
//this function just tells actionscript that we're done
//using this red fill
newCircle.graphics.endFill();
//adding the circle to the stage
addChild(newCircle);

I really commented out this one so hopefully you can understand what this code does. This will just draw a red circle that is 50 pixels in radius, 50 pixels from left and top of the stage. Without the comments, it only takes 5 lines, so it isn’t too complicated.

End Product

(I made the stage a bit smaller)

Drawing Rectangles/Squares

Drawing a rectangle or square is very similar to the circle, except with a different function called. Here’s the commented code for doing so:

var newRect:Shape = new Shape();
newRect.graphics.beginFill(0xFF0000);
//now we call a function that will draw the square
//the first value (50) is the x value
//the second value (50) is the y value
//the third value (100), is the width
//and the final value (100), is the height
newRect.graphics.drawRect(50,50,100,100);
newRect.graphics.endFill();
addChild(newRect);

I just commented the new stuff that was added in.

The End Product

10 Amazing Blog Designs

I know these kinds of posts are a bit overdone, but here’s my choice of amazing blog designs.
1. N.Design Studio

2. Noupe

3. Veerle’s Blog

4. Design Disease

5. Vikiworks Studio

6. Web Designer Wall

7. Janko at Warp Speed

8. Abduzeedo

9. Paul Enderson’s Reflections

10. Ten Thousand Things

Skills that All Game Developers Need Part 1: Advertising

The game development process can be filled with quite a bit of interesting steps. In order to complete all of these steps, you need to have the correct kind of skills. Some of these skills, you may not think you need. But, once explained, you will see how essential they really are. In these series, [...]

5 Ways to Make Sure Gamers Read Your Game’s Instructions

When you, as a flash developer, make a game, it is important that you inform your user how to play it. Usually if your game is simple enough, the user doesn’t need to read the instructions, but with more complicated games, they are required. There is one problem with making instructions, however. If you have [...]

5 Reasons NOT to Create a Flash Arcade Site

A few online flash arcade sites have become very popular around the web. There is no wonder why hundreds of webmasters have decided to create a portal of their own in hopes of earning a modest sum of revenue. Almost all of them fail. Here are the reasons why you shouldn’t be one of these [...]

How to Make a Fair Scoring System in Your Game

Scoring Systems are found in almost every game out there. They are a key component in your game, but often are forgotten among all of the other pieces of the game that are thought to be key.
The idea of scoring is simple. Whenever the player accomplishes a task within the game, they are rewarded with [...]

Link Post Sunday 09/07

Flash Links

Flash says Screw You to Silverlight… Sort of by The Way I Think
Silverlight and Flash Running on Google Chrome by Samiq Bits
Which is Faster? Flash or Silverlight? by Code Climber
43 Hot Flex and ActionScript 3.0 APIs, tips, and tools for Autumn 2008 by Sean the Flex Guy
Improving SWF Compression by Kaioa

Web Design Links

10 Challenging [...]

Tutorial: Simple Dynamic Perspective in AS2 and AS3

This tutorial will show you how to create a simple illusion of perspective, dynamically in both ActionScript 2.0 and ActionScript 3.0. Although this technique isn’t the most advanced or realistic, it gets the job done. Let’s see it, shall we?
ActionScript 2.0
We’ll first make the effect in ActionScript 2.0. To begin, we have to create an [...]

Sell Your Game’s Source Code on Flash Den

I’ve recently come accross a website called Flash Den. It’s basically a marketplace where you can either buy or sell flash stuff. You could buy or sell a variety of flash-related things, from components to preloaders. But right now, I want to focus on selling your game’s source code. I myself haven’t tried it out, [...]

2 Simple Steps to Developing Your Perfect Game

Develop your Game
Release your Game

Page 3 of 12 -«12345»...Last »