Posted May 31, 2011 by Nick Vogt in Programming
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?
You could create several versions of every image at different transparency levels. This is very tedious and will result in more file size and memory usage. Another way is to use a separate transparent BitmapData mask and apply it to any image that you want transparent.
Continue reading...
You could create several versions of every image at different transparency levels. This is very tedious and will result in more file size and memory usage. Another way is to use a separate transparent BitmapData mask and apply it to any image that you want transparent.
Continue reading...
Posted May 31, 2011 by Nick Vogt in Programming
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.
In the alpha level, 00 represents fully transparent and FF represents fully opaque (visible). For example, to create a fully opaque black, you would use FF000000 (0xFF000000). To create a semi-transparent black, you could use AA000000 (0xAA000000).
Continue reading...
In the alpha level, 00 represents fully transparent and FF represents fully opaque (visible). For example, to create a fully opaque black, you would use FF000000 (0xFF000000). To create a semi-transparent black, you could use AA000000 (0xAA000000).
Continue reading...
Posted May 17, 2011 by Nick Vogt in Programming
JSON stands for JavaScript Object Notation. It is a widely-used model for transferring variable data as text, and is often used in combination with AJAX to create the basis for highly-interactive, portable, and modular websites (Facebook, Twitter, etc).
If you are familiar with JavaScript objects, then you already know JSON! If you aren't, it is very easy to learn. A JavaScript object is just like an object in ActionScript 3 or an associative array in PHP, just with slightly different syntax.
Here is the basic syntax for JSON. This object contains two strings, an array, and an object:
Continue reading...
If you are familiar with JavaScript objects, then you already know JSON! If you aren't, it is very easy to learn. A JavaScript object is just like an object in ActionScript 3 or an associative array in PHP, just with slightly different syntax.
Here is the basic syntax for JSON. This object contains two strings, an array, and an object:
{
"one": "A Number",
"hello": "world",
"myarray": [
"orange",
"apple",
"banana"
],
"myobject": {
"library": "books",
"bar": "alcohol"
}
}
"one": "A Number",
"hello": "world",
"myarray": [
"orange",
"apple",
"banana"
],
"myobject": {
"library": "books",
"bar": "alcohol"
}
}
Continue reading...
Posted May 12, 2011 by Nick Vogt in Programming
In a nutshell, AJAX allows you to update parts of a page with server-side content using JavaScript, without reloading the whole page. AJAX is not a new language, it's just a method for using JavaScript to achieve this functionality.
To use AJAX you will need to know a bit of JavaScript and (for this example) PHP, and have a server that can parse PHP. If you don't have this, you can download Apache server and PHP for free from their respective websites (follow my guide on setting up Apache, MySQL, and PHP on Windows).
Before diving into AJAX, first take a look at this example:
Continue reading...
To use AJAX you will need to know a bit of JavaScript and (for this example) PHP, and have a server that can parse PHP. If you don't have this, you can download Apache server and PHP for free from their respective websites (follow my guide on setting up Apache, MySQL, and PHP on Windows).
Before diving into AJAX, first take a look at this example:
<html>
<head>
<script type="text/javascript">
function hello()
{
document.getElementById('content').innerHTML = 'Hello World!';
}
</script>
</head>
<body>
<input type="button" value="Click Me" onclick="hello();">
<div id="content">Nothing here yet.</div>
</body>
</html>
<head>
<script type="text/javascript">
function hello()
{
document.getElementById('content').innerHTML = 'Hello World!';
}
</script>
</head>
<body>
<input type="button" value="Click Me" onclick="hello();">
<div id="content">Nothing here yet.</div>
</body>
</html>
Continue reading...
Posted March 24, 2011 by Nick Vogt in Programming
Many websites have a print link that opens up documents in a separate window with special formatting for print. This works, but often times you can achieve the same result using CSS and the media="print" attribute. What I generally do is specify two external stylesheets, one for media="all" and one for media="print". For example:
Link tags should be between the head tags in your html.
The style_print.css document would contain tweaks that eliminate the website's layout and adjust dimensions to make the printed document look good. The end result is a cleanly printed document without requiring a separate page or forcing users to open up a new window/tab to print from.
There are other ways to implement a media declaration if you want to have inline css or all of it on a single css document. See W3Schools CSS Media Types for more information.
<link media="all" rel="stylesheet" type="text/css" href="style.css">
<link media="print" rel="stylesheet" type="text/css" href="style_print.css">
<link media="print" rel="stylesheet" type="text/css" href="style_print.css">
Link tags should be between the head tags in your html.
The style_print.css document would contain tweaks that eliminate the website's layout and adjust dimensions to make the printed document look good. The end result is a cleanly printed document without requiring a separate page or forcing users to open up a new window/tab to print from.
There are other ways to implement a media declaration if you want to have inline css or all of it on a single css document. See W3Schools CSS Media Types for more information.
Posted March 10, 2011 by Nick Vogt in Programming
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.
Programming using classes can be a little odd at first. Don't think of your program as one single block of code that performs a series of actions based on user input. Instead, think of your program as comprised of many separate, interacting objects, that each have their own tasks and can interact with each other.
Continue reading...
Programming using classes can be a little odd at first. Don't think of your program as one single block of code that performs a series of actions based on user input. Instead, think of your program as comprised of many separate, interacting objects, that each have their own tasks and can interact with each other.
Continue reading...
Posted February 22, 2011 by Nick Vogt in Programming
MySQL's full-text search allows you to quickly search a table for single or multiple keywords from multiple columns. It does this by using an index on the columns that you want to search. There are a few limitations that you should know of. Indexed columns can only be CHAR, VARCHAR, or TEXT, MySQL does not by default index words that are less than 4 characters, and any word that appears in over 50% of rows is excluded from the results. There are also stop words.
With that out of the way, let's start. First you need to create the index. The index should be on the columns that you will be searching. For example, to index the title, body, and tags column, run a MySQL query like this (for the table "posts"):
You can also create the index using phpMyAdmin. To do so, browse to the table, click on Structure to edit it, and towards the bottom you'll see something like "Create an index".

Continue reading...
With that out of the way, let's start. First you need to create the index. The index should be on the columns that you will be searching. For example, to index the title, body, and tags column, run a MySQL query like this (for the table "posts"):
ALTER TABLE posts ADD FULLTEXT(title, body, tags);
You can also create the index using phpMyAdmin. To do so, browse to the table, click on Structure to edit it, and towards the bottom you'll see something like "Create an index".

Continue reading...
Posted February 15, 2011 by Nick Vogt in Programming
Many of the sites I build require an image thumbnailer, so that users can upload an image and it will automatically be thumbnailed. I decided to write a function that I could incorporate into these sites quickly and easily. This function takes a number of arguments, and will create any number of thumbnails in any sizes, and also has the option of moving the original, unedited file into a folder. It handles jpg, png, and gif, and creates jpg thumbnails.
Download it here, name it and put it somewhere. Use php "include" or "require" where it is needed, then call the createthumbs function, which takes four arguments:
The first argument is the $_FILES[] variable that points to the file that was uploaded.
The second argument is the filename of the image.
The third argument is an array that contains the different sizes and locations to save the images. It is formatted like so: array('imgdir/thumb' => array(360,240), 'imgdir/large' => array(800,600)). Each key in the main array is the image folder, and each value is an array that contains the width and height. You can have as many as you want.
The fourth argument is optional, and is a string that points to the directory you want the original image to be saved in, if you want it saved.
Continue reading...
Download it here, name it and put it somewhere. Use php "include" or "require" where it is needed, then call the createthumbs function, which takes four arguments:
The first argument is the $_FILES[] variable that points to the file that was uploaded.
The second argument is the filename of the image.
The third argument is an array that contains the different sizes and locations to save the images. It is formatted like so: array('imgdir/thumb' => array(360,240), 'imgdir/large' => array(800,600)). Each key in the main array is the image folder, and each value is an array that contains the width and height. You can have as many as you want.
The fourth argument is optional, and is a string that points to the directory you want the original image to be saved in, if you want it saved.
Continue reading...
Posted January 17, 2011 by Nick Vogt in Programming
I mentioned I was working on an MP3 player in a previous post. I considered writing a tutorial but it would be really long. Instead, I'm releasing the MP3 player, free to use and modify, and am offering the full Actionscript 3 source code (plus Photoshop file) for download.
Here is the MP3 player. Let me know if you find any bugs. The initial values for the text in the title is changeable in the XML file. The scroll bar resizes based on the number of mp3s (or disappears if there aren't that many).
Continue reading...
Here is the MP3 player. Let me know if you find any bugs. The initial values for the text in the title is changeable in the XML file. The scroll bar resizes based on the number of mp3s (or disappears if there aren't that many).
Continue reading...
Posted January 17, 2011 by Nick Vogt in Programming
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.Here is an example of loading variables via FlashVars (use an & to separate each name/value pair):
<object>
<param name="movie" value="movie.swf">
<param name="FlashVars" value="name1=value1&name2=value2">
<embed src="movie.swf" FlashVars="name1=value1&name2=value2">
</object>
<param name="movie" value="movie.swf">
<param name="FlashVars" value="name1=value1&name2=value2">
<embed src="movie.swf" FlashVars="name1=value1&name2=value2">
</object>
And now via the query string:
Continue reading...
