Showing only posts with tag actionscript
With Flash version 10, Adobe added the Vector class, which is similar to an Array but more strict. Each Vector can only contain data of the same type and its data type must be declared during instantiation. I'm not going to go over the syntax to use Vectors in this post, but they are very similar to Arrays and have a lot of the same methods and properties...
If you're unfamiliar with object pooling, it is a way to speed up processing time by keeping objects in memory and reusing them, instead of always instantiating new ones and garbage collecting them.This example uses package and custom class syntax. If you are unfamiliar with these, see my introduction to package and classes post...
There are two common methods to determine if a property/attribute/variable of some object exists. Both use the property name as a string and neither rely on checking for an error report.The first is using the hasOwnProperty method:
var myObject:Object = {name:'Jenkins'};
if(myObject.hasOwnProperty('name'))
{
// Do something
}
if(myObject.hasOwnProperty('name'))
{
// Do something
}
This error is often caused by the accidental use of a colon (:) to terminate a statement instead of a semi-colon (;). The error report should give you the error location...Here's a quick description of a unit vector for those that don't know. A unit vector is a vector with a magnitude (distance) of 1. The vector can be pointing in any direction, but the magnitude will always be 1. To get a unit vector from any old vector, you "normalize" that vector, which gives you a new vector with the same direction but a magnitude of 1. Unit vector and normalized vector are often used interchangeably...
When working with BitmapData and copyPixels, you'll quickly run into the limitation of not having an alpha attribute with which to change the transparency level of objects. If you're like me, you started out using Sprite and MovieClip in your games and could easily fade-in or fade-out objects using the alpha attribute. Unfortunately, BitmapData does not have the alpha attribute, so how do you adjust transparency dynamically while using copyPixels?
Creating semi-transparent BitmapData in ActionScript 3 is done using an ARGB hexadecimal value (32-bit). ARGB stands for Alpha-Red-Green-Blue and is just like an RGB hex value but with an alpha level at the beginning. Due to the alpha level, ARGB hex values are 8 hex digits and not 6. If you aren't familiar with hexadecimal, I suggest reading up on it before continuing...
Most Flash Actionscript 3 developers start out by writing code directly into the Actions window (F9), or into a separate .as file and using include to include that code into the Actions window. This works fine for quick, simple programs, but to get the most out of Flash and Actionscript 3, you should learn how to use Packages and Classes...
Passing variables to a Flash movie that is embedded in a web page can be done using either the query string or FlashVars. The difference between these methods is that using query string will cause browsers to re-download the Flash movie each visit, while FlashVars allows browsers to use the cached version. Depending on the functionality you want, one method may suit you better than the other...In order to use int typecasting in place of Math.floor or Math.ceil, you must first understand exactly what these functions do: Math.floor takes a number and returns the next lowest whole integer. Passing 0.9 will return 0 and -0.9 will return -1. Math.ceil returns the next highest integer, so will return 1 from 0.9 and 0 from -0.9. This is different than truncating, which would return 0 in all cases, and is why typecasting using int (usually used to truncate) wouldn't seem to work at first.
In order to make int typecasting work, you need to add a condition check to see if the number is negative or positive (negative for floor, positive for ceil), and adjust it by 1 if it is. Why do this instead of just using Math.floor or Math.ceil? Because it is faster and you can avoid a function call if desired. Look at these examples...
In order to make int typecasting work, you need to add a condition check to see if the number is negative or positive (negative for floor, positive for ceil), and adjust it by 1 if it is. Why do this instead of just using Math.floor or Math.ceil? Because it is faster and you can avoid a function call if desired. Look at these examples...
Page 1 of 2
