Adobe MAX 2008 kicks off with Shantanu Narayen, troche Adobe CEO.

I will do some live blogging from MAX. All post are being typed on my iPhone, due to my broken laptop, so do not expect a lot of details.

Over 5000 in attendence.

Followed by 2 more MAX conferences in europe and Asia.

Flash catalyst announced, previously Thurmo.

(Red) Wire announced, delivered on AIR. $5 a month.

Kevin Lynch on stage.

Cloud and client. Across multiple screens/devices.

Flash player 10 is awesome.
Audio waveform data, 3D, text engine, drawing API, pixel blender.
FAST realtime processing.

Adobe MAX 2008 kicks off with Shantanu Narayen, troche Adobe CEO.

I will do some live blogging from MAX. All post are being typed on my iPhone, due to my broken laptop, so do not expect a lot of details.

Over 5000 in attendence.

Followed by 2 more MAX conferences in europe and Asia.

Flash catalyst announced, previously Thurmo.

(Red) Wire announced, delivered on AIR. $5 a month.

Kevin Lynch on stage.

Cloud and client. Across multiple screens/devices.

Flash player 10 is awesome.
Audio waveform data, 3D, text engine, drawing API, pixel blender.
FAST realtime processing.

Max keynote is available online now. keynote

I cannot do it justice from my iPhone, pilule so check it out.

Updates:

Apparantly the keynote video does not live at the address I placed above, visit web that is what was on the big screen at the end of the keynote. sorry about that.
Here are a couple links of real live blogging (bet they had a laptop).
Liveblogging MAX 2008 Day 1 General Session Keynote

Adobe MAX 2008: Monday – Keynote

Tour de Flex on a 20′ screen, shot by Greg Wilson. Tour de Flex on a 20 ft Screen
Adobe MAX 2008 kicks off with Shantanu Narayen, troche Adobe CEO.

I will do some live blogging from MAX. All post are being typed on my iPhone, due to my broken laptop, so do not expect a lot of details.

Over 5000 in attendence.

Followed by 2 more MAX conferences in europe and Asia.

Flash catalyst announced, previously Thurmo.

(Red) Wire announced, delivered on AIR. $5 a month.

Kevin Lynch on stage.

Cloud and client. Across multiple screens/devices.

Flash player 10 is awesome.
Audio waveform data, 3D, text engine, drawing API, pixel blender.
FAST realtime processing.

Max keynote is available online now. keynote

I cannot do it justice from my iPhone, pilule so check it out.

Updates:

Apparantly the keynote video does not live at the address I placed above, visit web that is what was on the big screen at the end of the keynote. sorry about that.
Here are a couple links of real live blogging (bet they had a laptop).
Liveblogging MAX 2008 Day 1 General Session Keynote

Adobe MAX 2008: Monday – Keynote

Tour de Flex on a 20′ screen, shot by Greg Wilson. Tour de Flex on a 20 ft Screen
The first day of MAX has ended at 10:30 pm Monday night. East coast time is taking it’s toll, sales but I know I am not the only one. I just finished moderating a video tips group that was full of drooping eyes.

Today was a success with 4 new t-shirts and a few new tips learned. All of the sessions are going to be available for free at Adobe TV. I have heard the Flash Catylist (thermo) sessions were really good, information pills the Flash Player Internals session had some nice insight on optimizing code, this my favorite one of the day. The Flex Tips session showed off some features of Flex Builder that I never new existed and now will not be able to live without.

MAX 2008 Sessions added to Adobe TV – 12/11/08

MAX 2008 on Adobe TV.

Adobe MAX 2008 kicks off with Shantanu Narayen, troche Adobe CEO.

I will do some live blogging from MAX. All post are being typed on my iPhone, due to my broken laptop, so do not expect a lot of details.

Over 5000 in attendence.

Followed by 2 more MAX conferences in europe and Asia.

Flash catalyst announced, previously Thurmo.

(Red) Wire announced, delivered on AIR. $5 a month.

Kevin Lynch on stage.

Cloud and client. Across multiple screens/devices.

Flash player 10 is awesome.
Audio waveform data, 3D, text engine, drawing API, pixel blender.
FAST realtime processing.

Max keynote is available online now. keynote

I cannot do it justice from my iPhone, pilule so check it out.

Updates:

Apparantly the keynote video does not live at the address I placed above, visit web that is what was on the big screen at the end of the keynote. sorry about that.
Here are a couple links of real live blogging (bet they had a laptop).
Liveblogging MAX 2008 Day 1 General Session Keynote

Adobe MAX 2008: Monday – Keynote

Tour de Flex on a 20′ screen, shot by Greg Wilson. Tour de Flex on a 20 ft Screen
The first day of MAX has ended at 10:30 pm Monday night. East coast time is taking it’s toll, sales but I know I am not the only one. I just finished moderating a video tips group that was full of drooping eyes.

Today was a success with 4 new t-shirts and a few new tips learned. All of the sessions are going to be available for free at Adobe TV. I have heard the Flash Catylist (thermo) sessions were really good, information pills the Flash Player Internals session had some nice insight on optimizing code, this my favorite one of the day. The Flex Tips session showed off some features of Flex Builder that I never new existed and now will not be able to live without.

MAX 2008 Sessions added to Adobe TV – 12/11/08

MAX 2008 on Adobe TV.

In a Birds-Of-A-Feather discussion group at Adobe MAX last week. No remarks were planned, search It was supposed to be a discussion, stuff we hoped to talk to other developers about what’s new in using Flash video. We did not get a bunch of new information but we did get a lot of hard questions. Some of them were not fully answered and others were speculated upon. When I was asked my tips, I gave all I could think of at the time. Later that evening I remembered a couple more, some of my best ones.

So for those who went to MAX and those that did not, here are my official video tips for Flash and Flex.

Disclaimer: Technology changes on a regular basis, as of the date of this post I feel very comfortable with the statements made below. As new versions of software are released some of the comments may become outdated.

1. Your source file is king when it comes to getting good quality video. A good source file is the difference between hulu and youtube video. If you have control over your video source, make sure you get a good high-res lossless video file. They are huge and some clients do not know what you are talking about when you ask for it, but try your best to get a good source file.

2. Encode your own files. There are many flv encoders out there, some even your clients can use. But if you want good quality, then encode them yourselves. Of course some clients are pretty savvy when it comes to these things, in that case train them.

3. Use the Flash Video Encoder standalone application. *I have exported flv’s from many other programs, but quality is more consistent with the Flash Video Encoder application. Plus the encoding speed is a lot better with the Flash Video Encoder. It does suck to encode something twice, once to a lossless file, then a second time to flv, but in my testing it has been worth it.
(*H.264 can be encoded from other applications with equal quality. I have not compared them yet, but it is a very standard codec.)

4. If you do not have Flash CS4, use on2 VP6 encoding, it is much better than the other codec options. H.264 is a great improvement even over on2 VP6. Mp4 files can use different codecs, so make sure you are using H.246 and mp3 audio if you are encoding with other applications.

[ad#content_banner]

5. Not all video files are the same. Video containing a lot of motion/action can not handle as much compression as a low motion, talking head video. You will have to test your video files and encode each file with different settings to get optimum performance, size and quality. Also if you have control over the editing of your source files, certain video transitions (cross dissolve) encode worse than others.

6. Do not change frame rate when encoding an flv. This will cause your a/v sync to drift. Any edits to frame rate needs to be made in your source file before you encode. This does not apply to video without sound.

7. Dropping FPS and lowering the Key Frame Interval can lower file size of the flv, but there are consequences. For lowering frame rate, see number 6. Lowering the frame rate interval will effect fast-forwarding and rewinding and may effect syncing between key frames. If you need smooth fast forward and rewind, then leave the key frame interval to automatic or raise it a little more. I believe it is set to 24 frames by default.

8. If you want to have good streaming performance, place your streaming files on a server setup for streaming content. There could be cross-domain security sandbox issues, if your files do not load, first check if you need a crossdomain.xml file.

9. Video has come along way from the timeline full of image sequences from pre Flash MX days. Video still has a large file size that can only be compressed so far. Video needs to buffer before playing and can consume a lot of CPU. If possible stop other animations, visual effects, and any processor intense code while your videos are playing.

10. There are still times when video is not the best solution. I still use image sequences if the job requires it, even though video can be the easier way to go in most cases. You may have to push your animation skills to pull off video type effects. Building your animation in Flash will give you more control over the size and quality of your project.
Adobe MAX 2008 kicks off with Shantanu Narayen, troche Adobe CEO.

I will do some live blogging from MAX. All post are being typed on my iPhone, due to my broken laptop, so do not expect a lot of details.

Over 5000 in attendence.

Followed by 2 more MAX conferences in europe and Asia.

Flash catalyst announced, previously Thurmo.

(Red) Wire announced, delivered on AIR. $5 a month.

Kevin Lynch on stage.

Cloud and client. Across multiple screens/devices.

Flash player 10 is awesome.
Audio waveform data, 3D, text engine, drawing API, pixel blender.
FAST realtime processing.

Max keynote is available online now. keynote

I cannot do it justice from my iPhone, pilule so check it out.

Updates:

Apparantly the keynote video does not live at the address I placed above, visit web that is what was on the big screen at the end of the keynote. sorry about that.
Here are a couple links of real live blogging (bet they had a laptop).
Liveblogging MAX 2008 Day 1 General Session Keynote

Adobe MAX 2008: Monday – Keynote

Tour de Flex on a 20′ screen, shot by Greg Wilson. Tour de Flex on a 20 ft Screen
The first day of MAX has ended at 10:30 pm Monday night. East coast time is taking it’s toll, sales but I know I am not the only one. I just finished moderating a video tips group that was full of drooping eyes.

Today was a success with 4 new t-shirts and a few new tips learned. All of the sessions are going to be available for free at Adobe TV. I have heard the Flash Catylist (thermo) sessions were really good, information pills the Flash Player Internals session had some nice insight on optimizing code, this my favorite one of the day. The Flex Tips session showed off some features of Flex Builder that I never new existed and now will not be able to live without.

MAX 2008 Sessions added to Adobe TV – 12/11/08

MAX 2008 on Adobe TV.

In a Birds-Of-A-Feather discussion group at Adobe MAX last week. No remarks were planned, search It was supposed to be a discussion, stuff we hoped to talk to other developers about what’s new in using Flash video. We did not get a bunch of new information but we did get a lot of hard questions. Some of them were not fully answered and others were speculated upon. When I was asked my tips, I gave all I could think of at the time. Later that evening I remembered a couple more, some of my best ones.

So for those who went to MAX and those that did not, here are my official video tips for Flash and Flex.

Disclaimer: Technology changes on a regular basis, as of the date of this post I feel very comfortable with the statements made below. As new versions of software are released some of the comments may become outdated.

1. Your source file is king when it comes to getting good quality video. A good source file is the difference between hulu and youtube video. If you have control over your video source, make sure you get a good high-res lossless video file. They are huge and some clients do not know what you are talking about when you ask for it, but try your best to get a good source file.

2. Encode your own files. There are many flv encoders out there, some even your clients can use. But if you want good quality, then encode them yourselves. Of course some clients are pretty savvy when it comes to these things, in that case train them.

3. Use the Flash Video Encoder standalone application. *I have exported flv’s from many other programs, but quality is more consistent with the Flash Video Encoder application. Plus the encoding speed is a lot better with the Flash Video Encoder. It does suck to encode something twice, once to a lossless file, then a second time to flv, but in my testing it has been worth it.
(*H.264 can be encoded from other applications with equal quality. I have not compared them yet, but it is a very standard codec.)

4. If you do not have Flash CS4, use on2 VP6 encoding, it is much better than the other codec options. H.264 is a great improvement even over on2 VP6. Mp4 files can use different codecs, so make sure you are using H.246 and mp3 audio if you are encoding with other applications.

[ad#content_banner]

5. Not all video files are the same. Video containing a lot of motion/action can not handle as much compression as a low motion, talking head video. You will have to test your video files and encode each file with different settings to get optimum performance, size and quality. Also if you have control over the editing of your source files, certain video transitions (cross dissolve) encode worse than others.

6. Do not change frame rate when encoding an flv. This will cause your a/v sync to drift. Any edits to frame rate needs to be made in your source file before you encode. This does not apply to video without sound.

7. Dropping FPS and lowering the Key Frame Interval can lower file size of the flv, but there are consequences. For lowering frame rate, see number 6. Lowering the frame rate interval will effect fast-forwarding and rewinding and may effect syncing between key frames. If you need smooth fast forward and rewind, then leave the key frame interval to automatic or raise it a little more. I believe it is set to 24 frames by default.

8. If you want to have good streaming performance, place your streaming files on a server setup for streaming content. There could be cross-domain security sandbox issues, if your files do not load, first check if you need a crossdomain.xml file.

9. Video has come along way from the timeline full of image sequences from pre Flash MX days. Video still has a large file size that can only be compressed so far. Video needs to buffer before playing and can consume a lot of CPU. If possible stop other animations, visual effects, and any processor intense code while your videos are playing.

10. There are still times when video is not the best solution. I still use image sequences if the job requires it, even though video can be the easier way to go in most cases. You may have to push your animation skills to pull off video type effects. Building your animation in Flash will give you more control over the size and quality of your project.

Using Random in Game Development, buy with strict guidelines, order can bring some variety to game play.

This sample is not a single solution but an approached I used in developing Whacky Voting – a politically smashing game. It uses random with some strict rules to get rid of sequences that some players can easily remember, yet keeping game play consistent from one game to the next.

This demo starts with a configuration section, used to set up how we want the game to act. The engine it self could be organized a little better to be more transportable. It is commented pretty well though, so it should be easy enough to understand the approach as well as practical usage. Random is used to shuffle all of the objects that appear on screen as well as what container the objects are associated with.

Configuration:
We use config data for each game so that we can easily tweak game-play without hacking our code later. We can use arrays, xml or other data sources. Plan ahead and build config options into your game as it is developed.

This array designates slots or containers to hold each appearing object. Use this to limit how many objects appear at a time and where they are placed on screen. this can represent MovieClips or other classes.

var objHolderArr:Array = [];
objHolderArr[0] = {obj:"object0",id:0,stat:false,timer:20,type:"",score:0,targ:null,xCoor:10};
objHolderArr[1] = {obj:"object1",id:1,stat:false,timer:20,type:"",score:0,targ:null,xCoor:90};
objHolderArr[2] = {obj:"object2",id:2,stat:false,timer:20,type:"",score:0,targ:null,xCoor:170};
objHolderArr[3] = {obj:"object3",id:3,stat:false,timer:20,type:"",score:0,targ:null,xCoor:250};
objHolderArr[4] = {obj:"object4",id:4,stat:false,timer:20,type:"",score:0,targ:null,xCoor:330};
objHolderArr[5] = {obj:"object5",id:5,stat:false,timer:20,type:"",score:0,targ:null,xCoor:410};

Next is an array of objects to appear, this is to control what type of objects appear and to make sure they are nicely distributed through out each level. You may have different scores, wilds and/or bonus score objects that need to get incorporated into the object list, but using random by it self will not allow them to be distributed appropriately for consistent game play.

var objSequenceArr:Array = [];
objSequenceArr[0] = {obj:"type0", count:20,score:100};
objSequenceArr[1] = {obj:"type1", count:15, score:150};
objSequenceArr[2] = {obj:"type2", count:5, score:500};
objSequenceArr[3] = {obj:"type3", count:5, score:1000};
objSequenceArr[4] = {obj:"null", count:5, score:0};

//timer increment for the engine to trigger an event
var timeInc:int = 500;

// integer to keep track of increment of game engine
var arrLoc:int = 0;

// random key
var randomKey:int = 1000;

// time for each object to stay visible;
var delay:int = 4;

[ad#content_banner]

It is good to set game status variables to allow games controls to be a little more intuitive. Sometimes I use a gameStatus string variable and a string to denote the current status. That way I can get more mileage out of one variable.

var gameOver:Boolean;

//or

var gameStatus:String = "_play";

Build Config Data for Engine:
The current level array built from config data above. The method then adds to the level array all the objects that we want to appear during the game.

var levelArr:Array = [];

function buildConfigData():void{
for(var p:String in objSequenceArr){
var loopCnt:int = objSequenceArr[p].count;
for(var i:uint = 0; i < loopCnt; i++){
var randNum:int = randomNumber(randomKey);
levelArr.push({obj:objSequenceArr[p].obj, score:objSequenceArr[p].score, key:randNum});
}
}

levelArr.sortOn("key",Array.NUMERIC || Array.DESCENDING);
}
buildConfigData();

Last, we sort the list so that it is shuffled which gives us the first random effect. All the objects are placed in the array in order of the sequence array, but we added a random number as the key to sort the array with. Now all of the objects will be randomly placed throughout the array and we will always have the right amount of objects for consistent game play.

Game Engine:
Now that we have our data, we are ready to start the engine.

1. Pull first random number

2. Loop until random number is not a slot that is already taken. We add a break and status variable to stop the loop if we can not find an available object. On a break, we will wait until the next TimerEvent and try again.

3. We have an active slot that is not already taken, we set it's status to true and show and configure our object.

4. Use this timer event to also run our Active Checker Method below. The more you can piggy-back off of single timers and EnterFrame events the better.

var timer:Timer = new Timer(timeInc,0);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();

function timerHandler(ev:TimerEvent):void{

//1.
var randSlot:int = randomNumber(objHolderArr.length);

//2.
if(arrLoc < levelArr.length){
if(levelArr[arrLoc].obj != "null"){
var breakCnt:int
var breakStatus:Boolean;
while(objHolderArr[randSlot].stat == true){
randSlot = randomNumber(objHolderArr.length);
breakCnt ++;
if(breakCnt >= 100){
breakStatus = true;
break;
}
}

if(!breakStatus){
//3.
var slotObj:Object = objHolderArr[randSlot];
slotObj.stat = true;
slotObj.timer = delay;
slotObj.score = levelArr[arrLoc].score;
slotObj.type = levelArr[arrLoc].type;

//******* add code here to initiate your visual objects.
var tempBO:ballObj = new ballObj();
tempBO.x = slotObj.xCoor;
tempBO.y = 20;
tempBO.objIDStr = arrLoc.toString();
tempBO.objScoreStr = levelArr[arrLoc].score;
tempBO.objTypeStr = levelArr[arrLoc].obj;
addChild(tempBO);

//********* end visual code here.

slotObj.targ = tempBO;
activeObjArr.push(slotObj);
// we advance the array location variable.
arrLoc ++;
}
}
else{
arrLoc ++;
}
}

//4.
activeChecker();
}

After each object is initiated, we need to give them an amount of time to be active. This is the activeObject array, we will track the time, if the user does not score with the object then it will be removed by the timer.

1. Loop through the active array to decrease each object's timer.

2. If the timer is run out, remove the object from the array and reset the object's status.

var activeObjArr:Array = [];

function activeChecker():void{
for(var p:String in activeObjArr){
//1.
activeObjArr[p].timer --;

//2.
if(activeObjArr[p].timer <= 0){
activeObjArr[p].stat = false;
removeChild(activeObjArr[p].targ);
activeObjArr.splice(int(p),1);

if(arrLoc >= levelArr.length && activeObjArr.length == 0){
//game is over.
gameOver = true;
timer.stop();
btn.enabled = true;
btn.alpha = 1;
}
}
}
}

Here is where you can place your event handlers for a user interactive with an object. We have to remove and reset the object, shown above and add the objects score to the main score.

We will also need a method for when the game clears the last array object.

Utilities:
method to pull random numbers just so I do not need to write this same code more than once.

function randomNumber(limit:int):int{
var randNum:int = Math.random()*limit;
return randNum;
}

Controls:
A restart control availble when game is over

btn.addEventListener(MouseEvent.CLICK,clickHandler);
btn.enabled = false;
btn.alpha = 0.2;
function clickHandler(ev:MouseEvent):void{
if(gameOver){
// rebuild data to show off shuffling.
levelArr = [];
buildConfigData();

//reset game controls and game engine.
arrLoc = 0;
timer.start();
gameOver = false;
btn.enabled = false;
btn.alpha = 0.2;
}
}

The Ball Object:
The ball object is a simple class that displays the data for each object. You would normally place a button or some other way to capture user interaction and send it back to the engine to initiate scores and feedback.

package{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.Event;

public class ballObj extends MovieClip{

public var objIDStr:String = "";
public var objTypeStr:String = "";
public var objScoreStr:String = "";

public function ballObj():void{
init();
stop();
}

private function init():void{
this.addEventListener(Event.ADDED,addedHandler);
}

private function addedHandler(ev:Event):void{
objID.text = objIDStr;
objScore.text = objScoreStr;
objType.text = objTypeStr;

}
}
}

[kml_flashembed movie="http://www.taterboy.com/blog/flash/GameRandomAS3.swf" height="150" width="500" fversion="9" /]

Source Here
Adobe MAX 2008 kicks off with Shantanu Narayen, troche Adobe CEO.

I will do some live blogging from MAX. All post are being typed on my iPhone, due to my broken laptop, so do not expect a lot of details.

Over 5000 in attendence.

Followed by 2 more MAX conferences in europe and Asia.

Flash catalyst announced, previously Thurmo.

(Red) Wire announced, delivered on AIR. $5 a month.

Kevin Lynch on stage.

Cloud and client. Across multiple screens/devices.

Flash player 10 is awesome.
Audio waveform data, 3D, text engine, drawing API, pixel blender.
FAST realtime processing.

Max keynote is available online now. keynote

I cannot do it justice from my iPhone, pilule so check it out.

Updates:

Apparantly the keynote video does not live at the address I placed above, visit web that is what was on the big screen at the end of the keynote. sorry about that.
Here are a couple links of real live blogging (bet they had a laptop).
Liveblogging MAX 2008 Day 1 General Session Keynote

Adobe MAX 2008: Monday - Keynote

Tour de Flex on a 20' screen, shot by Greg Wilson. Tour de Flex on a 20 ft Screen
The first day of MAX has ended at 10:30 pm Monday night. East coast time is taking it's toll, sales but I know I am not the only one. I just finished moderating a video tips group that was full of drooping eyes.

Today was a success with 4 new t-shirts and a few new tips learned. All of the sessions are going to be available for free at Adobe TV. I have heard the Flash Catylist (thermo) sessions were really good, information pills the Flash Player Internals session had some nice insight on optimizing code, this my favorite one of the day. The Flex Tips session showed off some features of Flex Builder that I never new existed and now will not be able to live without.

MAX 2008 Sessions added to Adobe TV - 12/11/08

MAX 2008 on Adobe TV.

In a Birds-Of-A-Feather discussion group at Adobe MAX last week. No remarks were planned, search It was supposed to be a discussion, stuff we hoped to talk to other developers about what's new in using Flash video. We did not get a bunch of new information but we did get a lot of hard questions. Some of them were not fully answered and others were speculated upon. When I was asked my tips, I gave all I could think of at the time. Later that evening I remembered a couple more, some of my best ones.

So for those who went to MAX and those that did not, here are my official video tips for Flash and Flex.

Disclaimer: Technology changes on a regular basis, as of the date of this post I feel very comfortable with the statements made below. As new versions of software are released some of the comments may become outdated.

1. Your source file is king when it comes to getting good quality video. A good source file is the difference between hulu and youtube video. If you have control over your video source, make sure you get a good high-res lossless video file. They are huge and some clients do not know what you are talking about when you ask for it, but try your best to get a good source file.

2. Encode your own files. There are many flv encoders out there, some even your clients can use. But if you want good quality, then encode them yourselves. Of course some clients are pretty savvy when it comes to these things, in that case train them.

3. Use the Flash Video Encoder standalone application. *I have exported flv's from many other programs, but quality is more consistent with the Flash Video Encoder application. Plus the encoding speed is a lot better with the Flash Video Encoder. It does suck to encode something twice, once to a lossless file, then a second time to flv, but in my testing it has been worth it.
(*H.264 can be encoded from other applications with equal quality. I have not compared them yet, but it is a very standard codec.)

4. If you do not have Flash CS4, use on2 VP6 encoding, it is much better than the other codec options. H.264 is a great improvement even over on2 VP6. Mp4 files can use different codecs, so make sure you are using H.246 and mp3 audio if you are encoding with other applications.

[ad#content_banner]

5. Not all video files are the same. Video containing a lot of motion/action can not handle as much compression as a low motion, talking head video. You will have to test your video files and encode each file with different settings to get optimum performance, size and quality. Also if you have control over the editing of your source files, certain video transitions (cross dissolve) encode worse than others.

6. Do not change frame rate when encoding an flv. This will cause your a/v sync to drift. Any edits to frame rate needs to be made in your source file before you encode. This does not apply to video without sound.

7. Dropping FPS and lowering the Key Frame Interval can lower file size of the flv, but there are consequences. For lowering frame rate, see number 6. Lowering the frame rate interval will effect fast-forwarding and rewinding and may effect syncing between key frames. If you need smooth fast forward and rewind, then leave the key frame interval to automatic or raise it a little more. I believe it is set to 24 frames by default.

8. If you want to have good streaming performance, place your streaming files on a server setup for streaming content. There could be cross-domain security sandbox issues, if your files do not load, first check if you need a crossdomain.xml file.

9. Video has come along way from the timeline full of image sequences from pre Flash MX days. Video still has a large file size that can only be compressed so far. Video needs to buffer before playing and can consume a lot of CPU. If possible stop other animations, visual effects, and any processor intense code while your videos are playing.

10. There are still times when video is not the best solution. I still use image sequences if the job requires it, even though video can be the easier way to go in most cases. You may have to push your animation skills to pull off video type effects. Building your animation in Flash will give you more control over the size and quality of your project.

Using Random in Game Development, buy with strict guidelines, order can bring some variety to game play.

This sample is not a single solution but an approached I used in developing Whacky Voting - a politically smashing game. It uses random with some strict rules to get rid of sequences that some players can easily remember, yet keeping game play consistent from one game to the next.

This demo starts with a configuration section, used to set up how we want the game to act. The engine it self could be organized a little better to be more transportable. It is commented pretty well though, so it should be easy enough to understand the approach as well as practical usage. Random is used to shuffle all of the objects that appear on screen as well as what container the objects are associated with.

Configuration:
We use config data for each game so that we can easily tweak game-play without hacking our code later. We can use arrays, xml or other data sources. Plan ahead and build config options into your game as it is developed.

This array designates slots or containers to hold each appearing object. Use this to limit how many objects appear at a time and where they are placed on screen. this can represent MovieClips or other classes.

var objHolderArr:Array = [];
objHolderArr[0] = {obj:"object0",id:0,stat:false,timer:20,type:"",score:0,targ:null,xCoor:10};
objHolderArr[1] = {obj:"object1",id:1,stat:false,timer:20,type:"",score:0,targ:null,xCoor:90};
objHolderArr[2] = {obj:"object2",id:2,stat:false,timer:20,type:"",score:0,targ:null,xCoor:170};
objHolderArr[3] = {obj:"object3",id:3,stat:false,timer:20,type:"",score:0,targ:null,xCoor:250};
objHolderArr[4] = {obj:"object4",id:4,stat:false,timer:20,type:"",score:0,targ:null,xCoor:330};
objHolderArr[5] = {obj:"object5",id:5,stat:false,timer:20,type:"",score:0,targ:null,xCoor:410};

Next is an array of objects to appear, this is to control what type of objects appear and to make sure they are nicely distributed through out each level. You may have different scores, wilds and/or bonus score objects that need to get incorporated into the object list, but using random by it self will not allow them to be distributed appropriately for consistent game play.

var objSequenceArr:Array = [];
objSequenceArr[0] = {obj:"type0", count:20,score:100};
objSequenceArr[1] = {obj:"type1", count:15, score:150};
objSequenceArr[2] = {obj:"type2", count:5, score:500};
objSequenceArr[3] = {obj:"type3", count:5, score:1000};
objSequenceArr[4] = {obj:"null", count:5, score:0};

//timer increment for the engine to trigger an event
var timeInc:int = 500;

// integer to keep track of increment of game engine
var arrLoc:int = 0;

// random key
var randomKey:int = 1000;

// time for each object to stay visible;
var delay:int = 4;

[ad#content_banner]

It is good to set game status variables to allow games controls to be a little more intuitive. Sometimes I use a gameStatus string variable and a string to denote the current status. That way I can get more mileage out of one variable.

var gameOver:Boolean;

//or

var gameStatus:String = "_play";

Build Config Data for Engine:
The current level array built from config data above. The method then adds to the level array all the objects that we want to appear during the game.

var levelArr:Array = [];

function buildConfigData():void{
for(var p:String in objSequenceArr){
var loopCnt:int = objSequenceArr[p].count;
for(var i:uint = 0; i < loopCnt; i++){
var randNum:int = randomNumber(randomKey);
levelArr.push({obj:objSequenceArr[p].obj, score:objSequenceArr[p].score, key:randNum});
}
}

levelArr.sortOn("key",Array.NUMERIC || Array.DESCENDING);
}
buildConfigData();

Last, we sort the list so that it is shuffled which gives us the first random effect. All the objects are placed in the array in order of the sequence array, but we added a random number as the key to sort the array with. Now all of the objects will be randomly placed throughout the array and we will always have the right amount of objects for consistent game play.

Game Engine:
Now that we have our data, we are ready to start the engine.

1. Pull first random number

2. Loop until random number is not a slot that is already taken. We add a break and status variable to stop the loop if we can not find an available object. On a break, we will wait until the next TimerEvent and try again.

3. We have an active slot that is not already taken, we set it's status to true and show and configure our object.

4. Use this timer event to also run our Active Checker Method below. The more you can piggy-back off of single timers and EnterFrame events the better.

var timer:Timer = new Timer(timeInc,0);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();

function timerHandler(ev:TimerEvent):void{

//1.
var randSlot:int = randomNumber(objHolderArr.length);

//2.
if(arrLoc < levelArr.length){
if(levelArr[arrLoc].obj != "null"){
var breakCnt:int
var breakStatus:Boolean;
while(objHolderArr[randSlot].stat == true){
randSlot = randomNumber(objHolderArr.length);
breakCnt ++;
if(breakCnt >= 100){
breakStatus = true;
break;
}
}

if(!breakStatus){
//3.
var slotObj:Object = objHolderArr[randSlot];
slotObj.stat = true;
slotObj.timer = delay;
slotObj.score = levelArr[arrLoc].score;
slotObj.type = levelArr[arrLoc].type;

//******* add code here to initiate your visual objects.
var tempBO:ballObj = new ballObj();
tempBO.x = slotObj.xCoor;
tempBO.y = 20;
tempBO.objIDStr = arrLoc.toString();
tempBO.objScoreStr = levelArr[arrLoc].score;
tempBO.objTypeStr = levelArr[arrLoc].obj;
addChild(tempBO);

//********* end visual code here.

slotObj.targ = tempBO;
activeObjArr.push(slotObj);
// we advance the array location variable.
arrLoc ++;
}
}
else{
arrLoc ++;
}
}

//4.
activeChecker();
}

After each object is initiated, we need to give them an amount of time to be active. This is the activeObject array, we will track the time, if the user does not score with the object then it will be removed by the timer.

1. Loop through the active array to decrease each object's timer.

2. If the timer is run out, remove the object from the array and reset the object's status.

var activeObjArr:Array = [];

function activeChecker():void{
for(var p:String in activeObjArr){
//1.
activeObjArr[p].timer --;

//2.
if(activeObjArr[p].timer <= 0){
activeObjArr[p].stat = false;
removeChild(activeObjArr[p].targ);
activeObjArr.splice(int(p),1);

if(arrLoc >= levelArr.length && activeObjArr.length == 0){
//game is over.
gameOver = true;
timer.stop();
btn.enabled = true;
btn.alpha = 1;
}
}
}
}

Here is where you can place your event handlers for a user interactive with an object. We have to remove and reset the object, shown above and add the objects score to the main score.

We will also need a method for when the game clears the last array object.

Utilities:
method to pull random numbers just so I do not need to write this same code more than once.

function randomNumber(limit:int):int{
var randNum:int = Math.random()*limit;
return randNum;
}

Controls:
A restart control availble when game is over

btn.addEventListener(MouseEvent.CLICK,clickHandler);
btn.enabled = false;
btn.alpha = 0.2;
function clickHandler(ev:MouseEvent):void{
if(gameOver){
// rebuild data to show off shuffling.
levelArr = [];
buildConfigData();

//reset game controls and game engine.
arrLoc = 0;
timer.start();
gameOver = false;
btn.enabled = false;
btn.alpha = 0.2;
}
}

The Ball Object:
The ball object is a simple class that displays the data for each object. You would normally place a button or some other way to capture user interaction and send it back to the engine to initiate scores and feedback.

package{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.Event;

public class ballObj extends MovieClip{

public var objIDStr:String = "";
public var objTypeStr:String = "";
public var objScoreStr:String = "";

public function ballObj():void{
init();
stop();
}

private function init():void{
this.addEventListener(Event.ADDED,addedHandler);
}

private function addedHandler(ev:Event):void{
objID.text = objIDStr;
objScore.text = objScoreStr;
objType.text = objTypeStr;

}
}
}

[kml_flashembed movie="http://www.taterboy.com/blog/flash/GameRandomAS3.swf" height="150" width="500" fversion="9" /]

Source Here
This is it, about it the very first bit of actionscript code I ever learned, site besides play() and gotoAndStop() of course. The lesson went down with an experienced programmer looking over my shoulder telling me what to type. After this little app was finished, approved my brain hurt only understanding a few of the lines we wrote. That code was referenced and/or modified on more then a few projects that came after, each time deciphering more and applying it to new functionalities.

The original script was back in the day of AS1, but I am going to present it to you in AS3. If you are a beginner to ActionScript then it is the perfect time to learn AS3.

We are going to start really remedial for a minute and go over the basics of the classes and objects we will be using. It is kind-of long, so if you already have the basics covered, you can skip to the Application code.

The Variable:
Remember Pre-Algebra? 2+x = y? Variables are used for more then just place holders in a math equation. Programming is a very literal language, variables are how we make it figurative. Now instead of addressing one object with a snippet of code, that code can be applied to the many objects and properties our variables represent.

To use a variable, we must declare it using these three letters "var". Then comes the creative part, we get to think of a name. This can be a lot of fun making up funny names for things until someone else has to figure out your code or you forget that you called the variable that is going to bring balance to your application "anakin", oops, or was that "luke"?

After naming the variable, we have to declare it's type. We really don't have to, but it is a good idea. This variable will be a Number, because we will need it to include decimals.

Here are some examples of how variables can be used. Think about if we were selling apples that costs 65¢ a peace. A person wants to buy 5 apples. so we build an equation to handle the transaction.

var totalCost:Number;
totalCost = 0.65 * 5; //3.25

Ok, so we went conservitive, using "totalCost" for the total of apples purchased. Now what do we do when someone wants to buy 4 apples, or 6, or 8? Now we should add a new variable to represent the amount of apples. This variables declaration is an "int" (integer) as we will not be selling fractions of apples.

var numApples:int = 5;
var totalCost:Number;
totalCost = 0.65 * numApples; // 3.25

Everyone is happy until next week when there is an apple shortage and the price increases to 85¢ a piece. Now you have to go through you app and change all the prices from 65¢ to 85¢. If we use variables we can easily modify the app when the price changes, better yet, now this same app could be used to handle bananas, grapefruit and pears which all have different prices.

var cost:Number = 0.85;
var numFruit = 5;
var totalCost:Numer;
totalCost = cost * numFruit; // $4.25

[ad#content_banner]

Array:
Array is one of the most powerful classes in Flash. It's power comes from the way an array holds a collection of information. Not only do we have access to the information, but we can loop through all the items in an array and monitor the length of the collection.

This is how we might set up some variables without arrays. If we add or take away an item, we have to update a separate variable to keep track of the total amount. Looping through this is information is possible, but tricky.

var fuit1:String = "apple";
var fruit2:String = "banana";
var fruit3:String = "pear";
var fruits:int = 3;

// Or we can do the same thing with an array.

var fruitArr:Array = ["apple","banana","pear"];

trace(fruitArr[0]); //"apple
trace(fruitArr.length); //3

One thing that you must remember when using arrays is that they are zero indexed, meaning the first position in the array is 0. This can cause a little confusion because we teach our children to start counting at 1, not 0. This will hopefully make more sense later or maybe more confusion, but at least you will know why you are confused.

Tip: instead of useing var fruitArr:Array = new Array(); which you may have seen before. Using the square braces will do same thing. var fruitArr:Array = [];

If we think of our application as if it were an engine, the data objects (arrays, XML) are the fuel. The part of the application that interates like loops, enter frame events and timers are the heart of the engine, like the pistons, cams and crank shaft. This engine starts once the app loads and runs until we stop everything or close the app.

for() Loop:
Interates or repeats a a specified amount allowing our engine to apply the same code to multiple objects. Loops will run and complete in between each frame, before each render. This means you will not visually see what the loop is doing until it completes and the stage renders.

// This is a loop using the array from above:
for(var p:String in fruitArr){
trace(fruitArr[p] + " | index = " + p);
}

output:
apple | index = 0
banana | index = 1
pear | index = 2

First we assign a variable to the item that is going to loop trough the array. p stands for property and is a string. Here you can see the output of "p" which is showing the index or location of each item in the array. Notice that "apple" is the first item, which has an index of 0. If we get the length of the array (fruitArr.length) it will return a 3 which is 1 more then the last index in the array (2). Length counts like we do, starting at #1, index counts like computers do, starting at 0.

Tip: The p variable outputs a number in this case. This number is not really a number, it is a string using number characters. If we tried to add these "numbers" up, we would get "012" instead of the sum of 3. This is one reason declaring variable types are important. The compiler will tell us immediately if we are passing a string into an equation where a number or integer should be. Many external data sources will pass numbers into Flash as strings. Declaring variable types adds integrity to our applications.

Function:
A function is like a little wrapper or snippet of code that we can call at a later time. They are like the transmission, servos, clutch and any other metaphorical mechanism that takes energy and makes stuff happen.

Functions can run with or without feedback, adding a few arguments they can become very flexible. Let's use our fruit price calculator equation as a sample. This function receives two arguments (quantity and price), does the calculation, then returns the price. Nothing happens when the script loads, only when the function is called, see below.

function chaChing(quantity:int, price:Number):Number{
var calc:Number = price * quantity;
return calc;
}
var totalCost:Number = chaChing(5, 0.85);
trace(totalCost); //$4.25

// Notice the declaration :Number after the close parenthases
// on the function name.
function chaChing():Number{
}

// This lets the compiler know that the function is returning
// a value when it is called. If we do not need to return a value
// when the funciton is called, we would use void.

function chaChing():void{
}

This is a really simple one line function, but even this is a valid use. If you ever use the same equation or sequence more then once in your application, wrap it in a function.

Tip: A variables declared inside of a function will not be accessable outside of that function, but variables decaleared outside of the function are visible to it.

Tip: The words method and function are interchangeable.

Tip: Most "Real" programmers will put the opening curly brace one the next line under the function name.

if / else Condition:
Basically a switch, if a cindition is met, do one thing, if not then do something different.

Event:
These enable our controls and is the triggering system for our functions. Events monitors the engine and user input, they can be considered part of the engines electrical system.

Finally the Application:
The simple application we are going to build is an image loader. We will build a custom button, the code will place a button on the stage for each image. We will then hook up these controls to dynamically load in each image.

The beginning of our app is the config area, this is where we set up all of our variables and any constants.

/*
* first is the array, this is a list of image urls.
* We are going to loop through this array to create the correct amount of buttons.
* When the buttons are pressed, we will use the array to pull to corresponding image url.
*/
var imageArr:Array = ["images/apple.jpg","images/banana.jpg","images/pear.jpg"];


/****************************************************
* variables
****************************************************/
// buffHeight: will be use this to calulate the y possition of each button.
// 22 is the y coordinate to start the first button.
var buffHeight:int = 22;

// loadX and loadY: This will place our image in the correct spot on the stage.
var loadX:int = 156;
var loady:int = 22;

/****************************************************
* the loop:
* Iterates through the array, adds a button for each item, adds event listeners,
* updates the buffHeight variable then stops when it reaches the end of the array.
*****************************************************/

// There are a few different types of loops, this one is based on the items of an array.
// The first part of the loop conditions is declaring a variable to represent the index
// as the loop iterates through the array.

for(var p:String in imageArr){

// create new ImageButton
var imgBtn:ImageButton = new ImageButton();

// add a button label
imgBtn.labelText.text = "Image " + p;

// give the button a id from "p" which references the index
// of the current item in the array.
imgBtn.id = int(p);

// set the y property using the buffHeight variable.
imgBtn.y = buffHeight;
imgBtn.x = 20;

// add the eventListener to capture the button clicks
imgBtn.addEventListener(MouseEvent.CLICK,clickHandler);

//add the button to the stage.
addChild(imgBtn);

//update the variable with the height of this button, so the next button's y position will be below it.
buffHeight += imgBtn.height + 5;
}

/****************************************************
* function clickHandler(MouseEvent)
* handler for the Click MouseEvent assigned to each button in the loop.
****************************************************/
function clickHandler(ev:MouseEvent):void{

// the event's target property tells which button fired the event, now we can get the correct id.
var id:int = ev.currentTarget.id;

//use the id and the imageArr to get the correct image url.
var url:String = imageArr[id];

//call the loadImage function with the url as an argument.
loadImage(url);
}

/****************************************************
* function loadImage(url:String)
* function for loading the images
****************************************************/
function loadImage(url:String):void{

// new variable of new loader object
var ldr:Loader = new Loader();

// new URLRequest using the url we passed in as an argument.
// this converts the string into a url request we can pass to the loader to load the image.
var req:URLRequest = new URLRequest(url);

//loading the image
ldr.load(req);

ldr.x = loadX;
ldr.y = loady;

// add loader to MovieClip referenced by loadTarget.
addChild(ldr);
}

stop();

Button code and instructions:
Make a new MovieClip. Inside this new MovieClip create some artwork to be used as the button background. Add a textField and variable declaration for id (we will pass in the id during the loop). Then check the Export to ActionScript option in the MovieClips *properties window.

*To get to the MovieClips property window, right-click on the MovieClip in the Library, then choose properties. You may need to click the advanced button to see all the options.

We are using a MovieClip instead of a button, so that we can pass in an id and control the text. So we are going to build a MovieClip to act as a button.

[kml_flashembed movie="http://www.taterboy.com/blog/flash/AS3_101/AS3_101.swf" height="280" width="500" fversion="9" /]

Source Here

Where to go from here:
1. Play with the application variables and the array. Expand the app by giving each button a better name. Maybe build the array using names in stead of urls, then you can create the new url string using "images/" + name + ".jpg". You could also create a name array in the same sequence or use slice on the url to pull the name out.

2. Expand the buttons, if you really want to get fancy, create an on-state for each button, so that you can tell which image is currently displayed.

3. Add the calculator code to display how much each item cost when you click a button and a loader.

Tip: The ldr function above places one item on top of another, this may cause an issue if you want to show something behind each image while it is loading.

Take the existing code and come up with another uses for it. If you come up with some cool ideas, post some links below. Also if you figure out any of the previous enhancement, post some code.

To put your code in a code block, you can wrap it in these tags. Take out the "[" and "]" ,square brackets.
[<]pre lang="actionscript"[>]
// all code goes here.
[<]/pre[>]

Adobe MAX 2008 kicks off with Shantanu Narayen, troche Adobe CEO.

I will do some live blogging from MAX. All post are being typed on my iPhone, due to my broken laptop, so do not expect a lot of details.

Over 5000 in attendence.

Followed by 2 more MAX conferences in europe and Asia.

Flash catalyst announced, previously Thurmo.

(Red) Wire announced, delivered on AIR. $5 a month.

Kevin Lynch on stage.

Cloud and client. Across multiple screens/devices.

Flash player 10 is awesome.
Audio waveform data, 3D, text engine, drawing API, pixel blender.
FAST realtime processing.

Max keynote is available online now. keynote

I cannot do it justice from my iPhone, pilule so check it out.

Updates:

Apparantly the keynote video does not live at the address I placed above, visit web that is what was on the big screen at the end of the keynote. sorry about that.
Here are a couple links of real live blogging (bet they had a laptop).
Liveblogging MAX 2008 Day 1 General Session Keynote

Adobe MAX 2008: Monday - Keynote

Tour de Flex on a 20' screen, shot by Greg Wilson. Tour de Flex on a 20 ft Screen
The first day of MAX has ended at 10:30 pm Monday night. East coast time is taking it's toll, sales but I know I am not the only one. I just finished moderating a video tips group that was full of drooping eyes.

Today was a success with 4 new t-shirts and a few new tips learned. All of the sessions are going to be available for free at Adobe TV. I have heard the Flash Catylist (thermo) sessions were really good, information pills the Flash Player Internals session had some nice insight on optimizing code, this my favorite one of the day. The Flex Tips session showed off some features of Flex Builder that I never new existed and now will not be able to live without.

MAX 2008 Sessions added to Adobe TV - 12/11/08

MAX 2008 on Adobe TV.

In a Birds-Of-A-Feather discussion group at Adobe MAX last week. No remarks were planned, search It was supposed to be a discussion, stuff we hoped to talk to other developers about what's new in using Flash video. We did not get a bunch of new information but we did get a lot of hard questions. Some of them were not fully answered and others were speculated upon. When I was asked my tips, I gave all I could think of at the time. Later that evening I remembered a couple more, some of my best ones.

So for those who went to MAX and those that did not, here are my official video tips for Flash and Flex.

Disclaimer: Technology changes on a regular basis, as of the date of this post I feel very comfortable with the statements made below. As new versions of software are released some of the comments may become outdated.

1. Your source file is king when it comes to getting good quality video. A good source file is the difference between hulu and youtube video. If you have control over your video source, make sure you get a good high-res lossless video file. They are huge and some clients do not know what you are talking about when you ask for it, but try your best to get a good source file.

2. Encode your own files. There are many flv encoders out there, some even your clients can use. But if you want good quality, then encode them yourselves. Of course some clients are pretty savvy when it comes to these things, in that case train them.

3. Use the Flash Video Encoder standalone application. *I have exported flv's from many other programs, but quality is more consistent with the Flash Video Encoder application. Plus the encoding speed is a lot better with the Flash Video Encoder. It does suck to encode something twice, once to a lossless file, then a second time to flv, but in my testing it has been worth it.
(*H.264 can be encoded from other applications with equal quality. I have not compared them yet, but it is a very standard codec.)

4. If you do not have Flash CS4, use on2 VP6 encoding, it is much better than the other codec options. H.264 is a great improvement even over on2 VP6. Mp4 files can use different codecs, so make sure you are using H.246 and mp3 audio if you are encoding with other applications.

[ad#content_banner]

5. Not all video files are the same. Video containing a lot of motion/action can not handle as much compression as a low motion, talking head video. You will have to test your video files and encode each file with different settings to get optimum performance, size and quality. Also if you have control over the editing of your source files, certain video transitions (cross dissolve) encode worse than others.

6. Do not change frame rate when encoding an flv. This will cause your a/v sync to drift. Any edits to frame rate needs to be made in your source file before you encode. This does not apply to video without sound.

7. Dropping FPS and lowering the Key Frame Interval can lower file size of the flv, but there are consequences. For lowering frame rate, see number 6. Lowering the frame rate interval will effect fast-forwarding and rewinding and may effect syncing between key frames. If you need smooth fast forward and rewind, then leave the key frame interval to automatic or raise it a little more. I believe it is set to 24 frames by default.

8. If you want to have good streaming performance, place your streaming files on a server setup for streaming content. There could be cross-domain security sandbox issues, if your files do not load, first check if you need a crossdomain.xml file.

9. Video has come along way from the timeline full of image sequences from pre Flash MX days. Video still has a large file size that can only be compressed so far. Video needs to buffer before playing and can consume a lot of CPU. If possible stop other animations, visual effects, and any processor intense code while your videos are playing.

10. There are still times when video is not the best solution. I still use image sequences if the job requires it, even though video can be the easier way to go in most cases. You may have to push your animation skills to pull off video type effects. Building your animation in Flash will give you more control over the size and quality of your project.

Using Random in Game Development, buy with strict guidelines, order can bring some variety to game play.

This sample is not a single solution but an approached I used in developing Whacky Voting - a politically smashing game. It uses random with some strict rules to get rid of sequences that some players can easily remember, yet keeping game play consistent from one game to the next.

This demo starts with a configuration section, used to set up how we want the game to act. The engine it self could be organized a little better to be more transportable. It is commented pretty well though, so it should be easy enough to understand the approach as well as practical usage. Random is used to shuffle all of the objects that appear on screen as well as what container the objects are associated with.

Configuration:
We use config data for each game so that we can easily tweak game-play without hacking our code later. We can use arrays, xml or other data sources. Plan ahead and build config options into your game as it is developed.

This array designates slots or containers to hold each appearing object. Use this to limit how many objects appear at a time and where they are placed on screen. this can represent MovieClips or other classes.

var objHolderArr:Array = [];
objHolderArr[0] = {obj:"object0",id:0,stat:false,timer:20,type:"",score:0,targ:null,xCoor:10};
objHolderArr[1] = {obj:"object1",id:1,stat:false,timer:20,type:"",score:0,targ:null,xCoor:90};
objHolderArr[2] = {obj:"object2",id:2,stat:false,timer:20,type:"",score:0,targ:null,xCoor:170};
objHolderArr[3] = {obj:"object3",id:3,stat:false,timer:20,type:"",score:0,targ:null,xCoor:250};
objHolderArr[4] = {obj:"object4",id:4,stat:false,timer:20,type:"",score:0,targ:null,xCoor:330};
objHolderArr[5] = {obj:"object5",id:5,stat:false,timer:20,type:"",score:0,targ:null,xCoor:410};

Next is an array of objects to appear, this is to control what type of objects appear and to make sure they are nicely distributed through out each level. You may have different scores, wilds and/or bonus score objects that need to get incorporated into the object list, but using random by it self will not allow them to be distributed appropriately for consistent game play.

var objSequenceArr:Array = [];
objSequenceArr[0] = {obj:"type0", count:20,score:100};
objSequenceArr[1] = {obj:"type1", count:15, score:150};
objSequenceArr[2] = {obj:"type2", count:5, score:500};
objSequenceArr[3] = {obj:"type3", count:5, score:1000};
objSequenceArr[4] = {obj:"null", count:5, score:0};

//timer increment for the engine to trigger an event
var timeInc:int = 500;

// integer to keep track of increment of game engine
var arrLoc:int = 0;

// random key
var randomKey:int = 1000;

// time for each object to stay visible;
var delay:int = 4;

[ad#content_banner]

It is good to set game status variables to allow games controls to be a little more intuitive. Sometimes I use a gameStatus string variable and a string to denote the current status. That way I can get more mileage out of one variable.

var gameOver:Boolean;

//or

var gameStatus:String = "_play";

Build Config Data for Engine:
The current level array built from config data above. The method then adds to the level array all the objects that we want to appear during the game.

var levelArr:Array = [];

function buildConfigData():void{
for(var p:String in objSequenceArr){
var loopCnt:int = objSequenceArr[p].count;
for(var i:uint = 0; i < loopCnt; i++){
var randNum:int = randomNumber(randomKey);
levelArr.push({obj:objSequenceArr[p].obj, score:objSequenceArr[p].score, key:randNum});
}
}

levelArr.sortOn("key",Array.NUMERIC || Array.DESCENDING);
}
buildConfigData();

Last, we sort the list so that it is shuffled which gives us the first random effect. All the objects are placed in the array in order of the sequence array, but we added a random number as the key to sort the array with. Now all of the objects will be randomly placed throughout the array and we will always have the right amount of objects for consistent game play.

Game Engine:
Now that we have our data, we are ready to start the engine.

1. Pull first random number

2. Loop until random number is not a slot that is already taken. We add a break and status variable to stop the loop if we can not find an available object. On a break, we will wait until the next TimerEvent and try again.

3. We have an active slot that is not already taken, we set it's status to true and show and configure our object.

4. Use this timer event to also run our Active Checker Method below. The more you can piggy-back off of single timers and EnterFrame events the better.

var timer:Timer = new Timer(timeInc,0);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();

function timerHandler(ev:TimerEvent):void{

//1.
var randSlot:int = randomNumber(objHolderArr.length);

//2.
if(arrLoc < levelArr.length){
if(levelArr[arrLoc].obj != "null"){
var breakCnt:int
var breakStatus:Boolean;
while(objHolderArr[randSlot].stat == true){
randSlot = randomNumber(objHolderArr.length);
breakCnt ++;
if(breakCnt >= 100){
breakStatus = true;
break;
}
}

if(!breakStatus){
//3.
var slotObj:Object = objHolderArr[randSlot];
slotObj.stat = true;
slotObj.timer = delay;
slotObj.score = levelArr[arrLoc].score;
slotObj.type = levelArr[arrLoc].type;

//******* add code here to initiate your visual objects.
var tempBO:ballObj = new ballObj();
tempBO.x = slotObj.xCoor;
tempBO.y = 20;
tempBO.objIDStr = arrLoc.toString();
tempBO.objScoreStr = levelArr[arrLoc].score;
tempBO.objTypeStr = levelArr[arrLoc].obj;
addChild(tempBO);

//********* end visual code here.

slotObj.targ = tempBO;
activeObjArr.push(slotObj);
// we advance the array location variable.
arrLoc ++;
}
}
else{
arrLoc ++;
}
}

//4.
activeChecker();
}

After each object is initiated, we need to give them an amount of time to be active. This is the activeObject array, we will track the time, if the user does not score with the object then it will be removed by the timer.

1. Loop through the active array to decrease each object's timer.

2. If the timer is run out, remove the object from the array and reset the object's status.

var activeObjArr:Array = [];

function activeChecker():void{
for(var p:String in activeObjArr){
//1.
activeObjArr[p].timer --;

//2.
if(activeObjArr[p].timer <= 0){
activeObjArr[p].stat = false;
removeChild(activeObjArr[p].targ);
activeObjArr.splice(int(p),1);

if(arrLoc >= levelArr.length && activeObjArr.length == 0){
//game is over.
gameOver = true;
timer.stop();
btn.enabled = true;
btn.alpha = 1;
}
}
}
}

Here is where you can place your event handlers for a user interactive with an object. We have to remove and reset the object, shown above and add the objects score to the main score.

We will also need a method for when the game clears the last array object.

Utilities:
method to pull random numbers just so I do not need to write this same code more than once.

function randomNumber(limit:int):int{
var randNum:int = Math.random()*limit;
return randNum;
}

Controls:
A restart control availble when game is over

btn.addEventListener(MouseEvent.CLICK,clickHandler);
btn.enabled = false;
btn.alpha = 0.2;
function clickHandler(ev:MouseEvent):void{
if(gameOver){
// rebuild data to show off shuffling.
levelArr = [];
buildConfigData();

//reset game controls and game engine.
arrLoc = 0;
timer.start();
gameOver = false;
btn.enabled = false;
btn.alpha = 0.2;
}
}

The Ball Object:
The ball object is a simple class that displays the data for each object. You would normally place a button or some other way to capture user interaction and send it back to the engine to initiate scores and feedback.

package{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.Event;

public class ballObj extends MovieClip{

public var objIDStr:String = "";
public var objTypeStr:String = "";
public var objScoreStr:String = "";

public function ballObj():void{
init();
stop();
}

private function init():void{
this.addEventListener(Event.ADDED,addedHandler);
}

private function addedHandler(ev:Event):void{
objID.text = objIDStr;
objScore.text = objScoreStr;
objType.text = objTypeStr;

}
}
}

[kml_flashembed movie="http://www.taterboy.com/blog/flash/GameRandomAS3.swf" height="150" width="500" fversion="9" /]

Source Here
This is it, about it the very first bit of actionscript code I ever learned, site besides play() and gotoAndStop() of course. The lesson went down with an experienced programmer looking over my shoulder telling me what to type. After this little app was finished, approved my brain hurt only understanding a few of the lines we wrote. That code was referenced and/or modified on more then a few projects that came after, each time deciphering more and applying it to new functionalities.

The original script was back in the day of AS1, but I am going to present it to you in AS3. If you are a beginner to ActionScript then it is the perfect time to learn AS3.

We are going to start really remedial for a minute and go over the basics of the classes and objects we will be using. It is kind-of long, so if you already have the basics covered, you can skip to the Application code.

The Variable:
Remember Pre-Algebra? 2+x = y? Variables are used for more then just place holders in a math equation. Programming is a very literal language, variables are how we make it figurative. Now instead of addressing one object with a snippet of code, that code can be applied to the many objects and properties our variables represent.

To use a variable, we must declare it using these three letters "var". Then comes the creative part, we get to think of a name. This can be a lot of fun making up funny names for things until someone else has to figure out your code or you forget that you called the variable that is going to bring balance to your application "anakin", oops, or was that "luke"?

After naming the variable, we have to declare it's type. We really don't have to, but it is a good idea. This variable will be a Number, because we will need it to include decimals.

Here are some examples of how variables can be used. Think about if we were selling apples that costs 65¢ a peace. A person wants to buy 5 apples. so we build an equation to handle the transaction.

var totalCost:Number;
totalCost = 0.65 * 5; //3.25

Ok, so we went conservitive, using "totalCost" for the total of apples purchased. Now what do we do when someone wants to buy 4 apples, or 6, or 8? Now we should add a new variable to represent the amount of apples. This variables declaration is an "int" (integer) as we will not be selling fractions of apples.

var numApples:int = 5;
var totalCost:Number;
totalCost = 0.65 * numApples; // 3.25

Everyone is happy until next week when there is an apple shortage and the price increases to 85¢ a piece. Now you have to go through you app and change all the prices from 65¢ to 85¢. If we use variables we can easily modify the app when the price changes, better yet, now this same app could be used to handle bananas, grapefruit and pears which all have different prices.

var cost:Number = 0.85;
var numFruit = 5;
var totalCost:Numer;
totalCost = cost * numFruit; // $4.25

[ad#content_banner]

Array:
Array is one of the most powerful classes in Flash. It's power comes from the way an array holds a collection of information. Not only do we have access to the information, but we can loop through all the items in an array and monitor the length of the collection.

This is how we might set up some variables without arrays. If we add or take away an item, we have to update a separate variable to keep track of the total amount. Looping through this is information is possible, but tricky.

var fuit1:String = "apple";
var fruit2:String = "banana";
var fruit3:String = "pear";
var fruits:int = 3;

// Or we can do the same thing with an array.

var fruitArr:Array = ["apple","banana","pear"];

trace(fruitArr[0]); //"apple
trace(fruitArr.length); //3

One thing that you must remember when using arrays is that they are zero indexed, meaning the first position in the array is 0. This can cause a little confusion because we teach our children to start counting at 1, not 0. This will hopefully make more sense later or maybe more confusion, but at least you will know why you are confused.

Tip: instead of useing var fruitArr:Array = new Array(); which you may have seen before. Using the square braces will do same thing. var fruitArr:Array = [];

If we think of our application as if it were an engine, the data objects (arrays, XML) are the fuel. The part of the application that interates like loops, enter frame events and timers are the heart of the engine, like the pistons, cams and crank shaft. This engine starts once the app loads and runs until we stop everything or close the app.

for() Loop:
Interates or repeats a a specified amount allowing our engine to apply the same code to multiple objects. Loops will run and complete in between each frame, before each render. This means you will not visually see what the loop is doing until it completes and the stage renders.

// This is a loop using the array from above:
for(var p:String in fruitArr){
trace(fruitArr[p] + " | index = " + p);
}

output:
apple | index = 0
banana | index = 1
pear | index = 2

First we assign a variable to the item that is going to loop trough the array. p stands for property and is a string. Here you can see the output of "p" which is showing the index or location of each item in the array. Notice that "apple" is the first item, which has an index of 0. If we get the length of the array (fruitArr.length) it will return a 3 which is 1 more then the last index in the array (2). Length counts like we do, starting at #1, index counts like computers do, starting at 0.

Tip: The p variable outputs a number in this case. This number is not really a number, it is a string using number characters. If we tried to add these "numbers" up, we would get "012" instead of the sum of 3. This is one reason declaring variable types are important. The compiler will tell us immediately if we are passing a string into an equation where a number or integer should be. Many external data sources will pass numbers into Flash as strings. Declaring variable types adds integrity to our applications.

Function:
A function is like a little wrapper or snippet of code that we can call at a later time. They are like the transmission, servos, clutch and any other metaphorical mechanism that takes energy and makes stuff happen.

Functions can run with or without feedback, adding a few arguments they can become very flexible. Let's use our fruit price calculator equation as a sample. This function receives two arguments (quantity and price), does the calculation, then returns the price. Nothing happens when the script loads, only when the function is called, see below.

function chaChing(quantity:int, price:Number):Number{
var calc:Number = price * quantity;
return calc;
}
var totalCost:Number = chaChing(5, 0.85);
trace(totalCost); //$4.25

// Notice the declaration :Number after the close parenthases
// on the function name.
function chaChing():Number{
}

// This lets the compiler know that the function is returning
// a value when it is called. If we do not need to return a value
// when the funciton is called, we would use void.

function chaChing():void{
}

This is a really simple one line function, but even this is a valid use. If you ever use the same equation or sequence more then once in your application, wrap it in a function.

Tip: A variables declared inside of a function will not be accessable outside of that function, but variables decaleared outside of the function are visible to it.

Tip: The words method and function are interchangeable.

Tip: Most "Real" programmers will put the opening curly brace one the next line under the function name.

if / else Condition:
Basically a switch, if a cindition is met, do one thing, if not then do something different.

Event:
These enable our controls and is the triggering system for our functions. Events monitors the engine and user input, they can be considered part of the engines electrical system.

Finally the Application:
The simple application we are going to build is an image loader. We will build a custom button, the code will place a button on the stage for each image. We will then hook up these controls to dynamically load in each image.

The beginning of our app is the config area, this is where we set up all of our variables and any constants.

/*
* first is the array, this is a list of image urls.
* We are going to loop through this array to create the correct amount of buttons.
* When the buttons are pressed, we will use the array to pull to corresponding image url.
*/
var imageArr:Array = ["images/apple.jpg","images/banana.jpg","images/pear.jpg"];


/****************************************************
* variables
****************************************************/
// buffHeight: will be use this to calulate the y possition of each button.
// 22 is the y coordinate to start the first button.
var buffHeight:int = 22;

// loadX and loadY: This will place our image in the correct spot on the stage.
var loadX:int = 156;
var loady:int = 22;

/****************************************************
* the loop:
* Iterates through the array, adds a button for each item, adds event listeners,
* updates the buffHeight variable then stops when it reaches the end of the array.
*****************************************************/

// There are a few different types of loops, this one is based on the items of an array.
// The first part of the loop conditions is declaring a variable to represent the index
// as the loop iterates through the array.

for(var p:String in imageArr){

// create new ImageButton
var imgBtn:ImageButton = new ImageButton();

// add a button label
imgBtn.labelText.text = "Image " + p;

// give the button a id from "p" which references the index
// of the current item in the array.
imgBtn.id = int(p);

// set the y property using the buffHeight variable.
imgBtn.y = buffHeight;
imgBtn.x = 20;

// add the eventListener to capture the button clicks
imgBtn.addEventListener(MouseEvent.CLICK,clickHandler);

//add the button to the stage.
addChild(imgBtn);

//update the variable with the height of this button, so the next button's y position will be below it.
buffHeight += imgBtn.height + 5;
}

/****************************************************
* function clickHandler(MouseEvent)
* handler for the Click MouseEvent assigned to each button in the loop.
****************************************************/
function clickHandler(ev:MouseEvent):void{

// the event's target property tells which button fired the event, now we can get the correct id.
var id:int = ev.currentTarget.id;

//use the id and the imageArr to get the correct image url.
var url:String = imageArr[id];

//call the loadImage function with the url as an argument.
loadImage(url);
}

/****************************************************
* function loadImage(url:String)
* function for loading the images
****************************************************/
function loadImage(url:String):void{

// new variable of new loader object
var ldr:Loader = new Loader();

// new URLRequest using the url we passed in as an argument.
// this converts the string into a url request we can pass to the loader to load the image.
var req:URLRequest = new URLRequest(url);

//loading the image
ldr.load(req);

ldr.x = loadX;
ldr.y = loady;

// add loader to MovieClip referenced by loadTarget.
addChild(ldr);
}

stop();

Button code and instructions:
Make a new MovieClip. Inside this new MovieClip create some artwork to be used as the button background. Add a textField and variable declaration for id (we will pass in the id during the loop). Then check the Export to ActionScript option in the MovieClips *properties window.

*To get to the MovieClips property window, right-click on the MovieClip in the Library, then choose properties. You may need to click the advanced button to see all the options.

We are using a MovieClip instead of a button, so that we can pass in an id and control the text. So we are going to build a MovieClip to act as a button.

[kml_flashembed movie="http://www.taterboy.com/blog/flash/AS3_101/AS3_101.swf" height="280" width="500" fversion="9" /]

Source Here

Where to go from here:
1. Play with the application variables and the array. Expand the app by giving each button a better name. Maybe build the array using names in stead of urls, then you can create the new url string using "images/" + name + ".jpg". You could also create a name array in the same sequence or use slice on the url to pull the name out.

2. Expand the buttons, if you really want to get fancy, create an on-state for each button, so that you can tell which image is currently displayed.

3. Add the calculator code to display how much each item cost when you click a button and a loader.

Tip: The ldr function above places one item on top of another, this may cause an issue if you want to show something behind each image while it is loading.

Take the existing code and come up with another uses for it. If you come up with some cool ideas, post some links below. Also if you figure out any of the previous enhancement, post some code.

To put your code in a code block, you can wrap it in these tags. Take out the "[" and "]" ,square brackets.
[<]pre lang="actionscript"[>]
// all code goes here.
[<]/pre[>]

Construction

Wether I am illustrating an imaginary device or something I use everyday, mind it is good to understand how the object is or should be constructed. Other information like functionality, page and how these objects are interacted with are very important in making our illustrations more convincing.

Questions you could ask yourself are how much heft and mass does this object possess, What kids of materials are used to build this object? How does this information effect how light reflects/refracts off the object. These evaluations help us understand how the details should be rendered.

The object could be steel, but is it built assembled with welds, bolts or both? The object could be made from concrete, Styrofoam, wood, glass or plastic molds. Each material is assembled differently with different types of joints. The time when an object is built also will give us a clue as to the type of assembly would have been used. We should carry that information or hints of that information into our illustration.

We do not have to have an engineering degree to know that some buildings are made from glass and steal, brick/concrete block, or wood. A glass building would be smooth and shiny on the outside with little definition where each glass plate comes together. Brick buildings have thick walls so windows are inset into the wall. Wood buildings have window frames that are used to hold the window into the wall.

These are the types of things that should be going through our heads as we sketch, construct, color, and touch up our work. In the meantime we are building our forms in Illustrator, here are some techniques to speed up our work as we construct our illustrations with the provided tools.

Using divide and Unite:
Divide and Unite are two pathfinder tools I use the most. You should set these to actions with keyboard shortcuts.

Divide Tip 1:
Create a shadow, reflection, glare on a larger shape. One of the rules for quick illustration in Illustrator is to never draw the same line twice. Another rule is divide does not have to be destructive. If you have ever used Divide before on a shape and zoomed out, sometimes you will notice a little background seeping through where the Divide incision are applied.

Draw the path how you would like your incision, over lapping on both ends and making sure the path has no fill. Select the larger shape first, Copy and Paste in Front (Command + F / Cntr + F) then select the line you created for your incision. Apply the Divide to the shape and delete the unwanted piece.

This creates a smaller shape on top of the original shape, in seconds, with no gaps and non-destructive. If we do not like the way it looks, we can always delete it and start over with our original shape still intact.

[ad#content_banner]

Divide Tip 2:
Again Divide does not have to be destructive. If you have a few overlapping paths, Divide with create a joined shape and trim off the excess paths. This can come in handy when using a grid, copy the lines we want to use from the grid, and apply a Divide. You will now have a new shape that matches your guides without having to draw anything. We drew the lines once for the guide, we should not have to draw them a gain.

Divide Tip 3:
Overlap your paths with working with divide. It is much easier to make sure your division are complete if you see your incision paths are overlapping your original shape.

Unite Tip 1:
Sometimes Divide can have some unwelcome results, but they can be cleaned up quickly with Unite.

Unite Tip 2:
Unite goes hand with Outline Stroke. If you have a fill and a stroke, using Outline Stroke then Unite will convert a path into a new solid shape. I like to use this for making nice outlines or inking effects. Depending on your Illustrator Preference settings, paths will scale on one machine and not another. It is also a good idea to Outline & Unite paths if the size relationship is important.

Below is a simple funny faced frog made almost intierly with the oval tool and Outlined paths.

For a better explanation of these tips, watch Illustrating in Illustrator, the Happy Frog video tutorial.

Flash tip: Paths have never translated well to Flash, so try Outline & Unite before importing to Flash.

Offset Stroke:
Found in the Object:Path menu, is similar to Outline Stroke. In CS3 and before the new path is automatically grouped to the original path. So if you have a few paths being made from the Outline Stroke command, you will have to select all the pieces and Cut & Paste them out of the group to work with them easier. I still use it very often, mostly on simpler shapes.

In Illustrator CS4 Outline Stroke works much better and mimics the functionality mentioned in Unite Tip 2.

Duplicate and Transform:
There are many times while we are illustrating that we come across many objects that are similar like windows, bolts, or even spider eyes. By completing on object, then copying and distributing those copies around will make creating all these objects less redundant. Even if shapes, size, perspective differ, there may be parts that are reusable, or a quick transform can really help save time.

Drawing vs Editing:
We have discussed never drawing the same line twice and was to create new shapes from exiting ones. Also we went over duplicating shapes and objects to help speed things up. The rules in this series are just like most rules, there is very often an exception. If you are comfortable with the pen tool in Illustrator, it is almost always faster to draw a new line then it is to edit an existing one. If you are tweaking a couple points on an existing path, that is one thing, but if you copy an path with the intent on modifying many points, it is most likely faster to draw a whole new path. Or at least delete the points you would like to edit, and draw a new path in it's place.

Join and Average:
Even drawing paths holding down the shift key will not always get our lines straight. The keyboard shortcut for Average is Command + Option + J on a Mac and Control + Alt + J on PC. Any lines that are supposed to be straight that for some reason are not, is just a second away from be so, but you have to remember the keyboard short cut to really make it worth while.

Another Keyboard shortcut to remember is Join. Command + J on a Mac and Control + J on PC, will be used over and over again to clean up stray points. Divide, Outline Stroke and other wonderful tools we have covered so far are great time savers but can put unwanted points in our paths. One of our objectives it to create Clean artwork. Extra points and text Miter spikes will not do, so a quick select with the Hollow Arrow, or Hollow Lasso, then Join, will clean those points up quickly.

Group and Layer as you go:
As discussed in Part 1 of the series, grouping is important in speeding up our work. It is much easier to grab a bunch of paths that have been grouped with the solid arrow, then selecting many paths to do a tweak. Many time you will be working on something else in the illustration and you will notice something you want to tweak something that was done previously. As you finish objects with multiple paths they should be grouped.

Distributing artwork in layer is a great way to create a groups too. The results of good groups is easy selection and/or isolation of parts of the illustration. Using Lock and Hide as well as layers are great ways to isolate our work.

Next - Illustrating In Illustrator 101 Part 3 of 5: Defining Shapes

For a better explanation of these tips, watch Illustrating in Illustrator, the Happy Frog video tutorial.

One Reply to “Illustrating In Illustrator 101 Part 2 of 5”

  1. i was searching for a psychology term for art history and found your site. what a great resource for illustrating! im so glad google sent me your way!

Leave a Reply