Not Repeating Items in a List
Submitted by rosenz on Mon, 04/14/2008 - 15:49.Markus Wrote:
This is a pretty common task. If your list is shuffled into a random order, though, then you don't have to worry about it. For instance, if you have 100 words, and then put them in a random order, and then take one word from the list at a time, then you should never end up with the same word twice as you are removing words from the list as you go. The key is to shuffle the array or words, and then remove them as you use them. For an example, see the section "Randomizing the Questions" in chapter 10 of the book.
hitTestObject Not As Expected
Submitted by rosenz on Wed, 04/09/2008 - 17:58.John Writes:
I want to test when the ball is touching the actual movie clip - not the area around it - how do I do that?
You are right. The hitTestObject function just looks at the bounding boxes, not the actual shape of the objects. If you think about it, this makes sense. Can you imagine the complexities of looking at the shape of two Flash display objects and determining if they overlap? Such a function would be very slow, which is why I imagine it doesn't exist. I talk a bit about how hitTestObject and hitTestPoint work in chapter 2, in the section on Collision Detection.
So, to your problem. If the ball is small enough, then you can simply use hitTestPoint with the point being the center of the ball. But if the ball is too large, then you'll need to dig into deeper math to determine when the ball actually touches the side of the rectangle. You can do a Google search on "collision detection circle line" to see some articles on the subject. It is pretty complex if you don't have a background in math.
FlashGameU.com Video Tutorial: Countdown Clock
Submitted by rosenz on Thu, 04/03/2008 - 18:39.Gary Rosenzweig from FlashGameU.com shows you how to build a simple clock to count down time until the end of a game.
Random Direction and Background
Submitted by rosenz on Tue, 02/26/2008 - 16:03.Yours sincerly
Brian
If you are looking to create a random number from -1 to 1, which includes all stops in between, then you would need a range of 2, but lowered by 1 so it is -1 to 1 instead of 0 to 2. So, the statement would be var myRandomNumber:Number = Math.random()*2-1;
However, if your intention is to create a number that is -1 half the time and 1 half the time, then you can't simply round the number, as you would get -1, 0 and 1 at various times. So you would probably want: var myRandomDirection:int = (Math.random() < .5) ? -1 : 1;
The ? and : statement has three parts. The first checks to see if Math.random() is less than .5, which will happen 50% of the time. If so, then -1 is returned. Otherwise 1 is returned.
One way to create a random background color is to have a sprite that is a solid fill behind everything else. Then use the colorTransform to set its color. Like this:
myColorTransform.color = 0xFF0000;
myBackgroundMC.transform.colorTransform = myColorTransform;
To make it random, have the color value chosen at random from an array of possible colors.
FlashGameU.com Video Tutorial: Mouse Fade and Base Classes
Submitted by rosenz on Thu, 02/21/2008 - 20:51.Gary Rosenzweig from FlashGameU.com shows you how to make a movie clip fade away according to the distance to the cursor location. He uses a Base Class to assign this same script to two different movie clips.
Class or Object By Name in AS3
Submitted by rosenz on Wed, 02/20/2008 - 14:19.I know Java can convert string name to class or object...
regards
Ed
Hello Ed. Yes, you can do this. The secret is the getDefinitionByNamefunction. Here is an example:
var myObject:Object = new classRef();
So myObject can be a Sound, a MovieClip, whatever. It is amazing how little attention this function gets when it is absolutely necessary for programming anything that uses a large library of named objects like sounds, graphics, etc.
FlashGameU.com Video Tutorial: Creating a Snake Game, Part 2
Submitted by rosenz on Mon, 01/14/2008 - 17:30.In this mini-chapter two-part episode, Gary Rosenzweig completes a snake game in ActionScript 3.
FlashGameU.com Video Tutorial: Creating a Snake Game, Part 1
Submitted by rosenz on Sat, 01/12/2008 - 00:19.In this mini-chapter two-part episode, Gary Rosenzweig starts building a snake game in ActionScript 3.
Ask Gary: Variable Names
Submitted by rosenz on Wed, 01/09/2008 - 23:45.I teach AS and have for some time been telling my students to append
suffixes such as _mc to movieClips, _btn to buttons, etc. This seems to
really make life easier when troubleshooting. I have to wonder if I'm
really out of the loop on this one because I don't see anyone else doing
that.
In AS3 if you type your variables well, then you really don't need to use suffixes to help identify variables when troubleshooting. Furthermore, if you use descriptive names, then the problem goes away. For instance, if I was putting playing cards on the stage, I would place them all in a sprite and call the sprite "cardSprite".
While I'm not a huge fan of using fixed suffixes like "_mc" in variable names, I'm not against it either. Whatever makes it easier for you or your programming team to get the job done.
FlashGameU.com Video Tutorial: Playing Multiple Flash Movies Inside a Single Flash Application
Submitted by rosenz on Sat, 12/08/2007 - 02:00.Gary Rosenzweig takes a look at how to put two Flash games together, inside of a single Flash movie. The trick is to use the Loader object.
Copyright Gary Rosenzweig
