So if you haven’t seen my fun badge there on the right side of my blog… —>
I will be speaking at 360|Flex San Jose.
If you haven’t attended a 360|Flex conference before, you really should. In my opinion, 360|Flex is the best conference out there for Flex developers. It’s put on by developers for developers.
It is a very focused conference, where you can really get into the nitty gritty of Flex and geek out with other members of the community. Plus the food isn’t half bad.
When are you speaking?
I’ll be speaking on Wednesday, March 10th (my birthday) from 1:00 pm – 2:20 pm.
What will you be speaking about?
Session Title: Flexible Games… game development with stuff you already know.
Session Level: Intermediate
Description: I don’t know about you… but as an enterprise software developer, sometimes I need to take a break from the corporate world and want to develop something fun. In this session Nate Beck will take you through the basics of game development using the Flex SDK you know and love.
Nate will walk you through setting up your development environment, the basics of game development, using the open source PushButton game engine and building a functioning game.
Since the incident, Doug has vowed to get payback. And if you don’t know Doug, he is a scary creative guy. So we’ll have to see what he comes up with. Find out, along with me at my session.
Alright I’m convinced, where do I sign up?
Either click here or click the 360|Flex San Jose badge on the top right of my blog.
More information about travel and the conference in general can be found on the 360|Flex Website.
As I spend more and more time on the PushButton Engine Forums, it’s funny how often the same topic seems to come up. Today a topic showed up again, regarding running Flash swf files locally. You see this same topic in many different flavors…
When I email my game to the client it won’t run on his computer
Playing the game only works inside my Flash Builder (or Flex Builder) project development folder
My game worked perfectly in one folder, but no longer works when moved to another folder
These issues are all part of the same underlying problem, a misunderstanding of Flash Player Security.
The first question you should ask yourself is… what security sandbox type is my game running in?
What is a Sandbox Type?
The sandbox type indicates the type of security zone in which the SWF file is operating.
In the PushButton Engine we make identifying the security sandbox easy. When your game starts it logs the security sandbox that your swf is currently running (you can also get this by using the built in “version” console command). It looks like this:
In this case, the game is running in “localTrusted”. Most games that you run from Flash Builder will run in the localTrusted sandbox type. This is because Flash Builder configures your system to trust files in Flash Builder project directories. This is meant to make our lives easier as Flash developers… but it can cause confusion.
So what are the types of sandboxes?
In Flash Player, all SWF files are placed into one of four types of sandbox:
remote All files from non-local URLs are placed in a remote sandbox. Basically anything loaded from the web (ex: http, https) falls into this category. There is no access to the local filesystem.
local-with-filesystem This is the default sandbox for local files. SWF files in this sandbox may not contact the Internet (or any servers) in any way. They may not access network endpoints with addresses such as http URLs.
local-with-networking A SWF file in this sandbox may communicate over the network but may not read from local file systems. It is the exact opposite of local-with-filesystem.
local-trusted This sandbox is not restricted. Any local file can be placed in this sandbox if given authorization by the end user. This authorization can come in two forms: interactively through the Settings Manager or non-interactively through an executable installer (or created manually) that creates Flash Player configuration files on the user’s computer.
I added use-network=false to the compiler / flex-config file and it fixed it!
That’s great, but you still need to understand what is happening.
When you add the “use-network=false” parameter to your compilation, you are forcing the swf into the local-with-filesystem sandbox (“user-network=true” forces local-with-networking). This may end up giving you the desired behavior that you want, a swf that will run locally when you send it to your client or friends. However, you may run into some issues later on.
What if you and your friends were competitive, and you then decided your game needs to post a high score? You would need to make a request to a server to submit the score. When running in the local-with-filesystem sandbox you are not able to make requests of any kind to the internet, and therefore you can’t post to the score board.
So what is the solution?
You could teach all of your friends how to setup their game to run in localTrusted, by configuring their security files. But there has got to be a better way.
Well there is, and it all depends on how you plan to deploy your game.
I want to distribute a local game.
The recommended way to distribute flash games to be run locally is using the Adobe AIR runtime. It’s a great platform, and gives you much more flexibility and functionality.
I want to put it on a website.
So the best way to test your game then would be, to put it on a website. Now don’t get scared, this isn’t going to change your development workflow all that much.
You then build your game (setup your output directory to drop the files in the web root) and launch your web-browser. Running a game swf from http://localhost will put your swf into the “remote” sandbox. You will want to do all of your testing within this sandbox, because it best mirrors the environment when you deploy your game to the web.
More Information
This post is just a brief overview of a very complex topic, for more information check out these resources:
A full hour presentation from MAX 2008 by Deneb Meketa, explaining how Flash Player Security works and why it does it that way (if you don’t want to watch the whole thing, 47:12 is where it talks about local file security). I highly recommend everyone watch it: Understanding the Flash Player Security Model
Once your game is running, to access the console press the default hot key, which is the Tilde (~) / Grave (`) key.
As of this post, the latest revision of the PushButton Engine is revision 702. In this version there are some commands registered by default:
help – List known commands.
clear – Clears the console history.
listDisplayObjects – Outputs the display list.
showFps – Show an FPS/Memory usage indicator.
verbose – Set verbosity level of console output.
version – Echo PushButton Engine version information.
Quick Tricks
The console supports a few shortcuts to make your life easier:
The console is not case-sensitive, so don’t worry if you put showFps or shOwFPS, the same command will execute.
You can use the up and down arrows to move through your command history.
By pressing enter on an empty command line, you can add new lines. This is helpful for adding space between commands to make it easier to read.
You can use the “name” property on a DisplayObject to make meaningful names show up in the listDisplayObjects command.
Different Log Levels are colored by default, to change the colors edit com.pblabs.engine.debug.LogColor.
Creating custom commands for the console
The PBE console also supports the ability for the developer to add their own commands.
package
{import com.pblabs.engine.PBE;
import com.pblabs.engine.debug.Console;
import com.pblabs.engine.debug.Logger;
import flash.display.Sprite;
publicclass ConsoleCommand extends Sprite
{publicfunction ConsoleCommand(){
PBE.startup(this);
Console.registerCommand("test", onTestCommand, "This is a test command.");
Console.registerCommand("testStrict", onTestStrict, "Test strict parameters.");
}
protected function onTestCommand(... args):void{
Logger.print(this, "onTestCommand: "+args);
}
protected function onTestStrict(str:String, num:Number):void{
Logger.print(this, "You passed in the string: "+str);
Logger.print(this, "You passed in the number: "+num);
}}}
Parameters are passed in sequence using spaces. So to run the test command, I would open the console, and then type “test a b c 1 2 3″. This would then call the onTestCommand method and pass in an array with 6 elements.
Below is an example of what using custom commands in the console looks like.
Changing the Console HotKey
Some of our good friends over in the Netherlands use different keyboard layouts, so they requested the ability to change the hot key binding to another key.
WARNING!!! When changing the hot key to another key, the input textfield doesn’t escape the new key binding. So you must remove focus from the input field to use the hot key to close the console.
More information on this can be found in issue 98.
What’s coming?
I do have plans on adding either tab-complete or a drop-down auto complete list into the console which will match avaliable commands.
Another thing that I’m currently working on is code-named Tumbler. It’s and Adobe AIR version of the console which has additional features to assist in debugging and troubleshooting your games.
It’s a proof-of-concept at the moment… but if there is enough interest in it… I may spend more time on it.
So I know I haven’t posted in quite some time. Between work, BugQuash, MAX, contributing to PushButton Engine, my country’s 500th anniversary to plan, my wedding to arrange, my wife to murder and Guilder to frame for it, I’ve been swamped.
But tonight… I break my blog silence. As I just mentioned, I’ve been contributing to the PushButton Flash Game Engine. I’m now going to show you how to set up Flex Builder 3 or Flash Builder 4 in a way that allows you to develop games on PushButton Engine, as well as how to work on the core engine itself. I’m breaking this down into very small pieces so that everyone can follow along. So it’s going to be a long post with lots of pretty pictures.
After writing this post, it ended up being longer than I hoped. So I’m going to write a series of posts about developing games using PushButton Engine. This post will focus only getting set up inside Flash and Flex Builder. The plan is to add other IDEs in as well, for example FlashDevelop, FDT, etc…
Step 1 : Download the PushButton Engine source code.
[note] If you are not familiar with Subversion or you need a primer to the basics of contributing to or working with open source projects please check out my “Getting Dirty with the Flex SDK” post, more specifically the TechWed Presentation. [/note]
WARNING!! For these steps to work, you must use at least revision 602 of the PushButton Engine.
Download the PushButton Engine core from Google Code. Since I am a developer in the engine, I have checked out trunk and all of the branches. My working copy is located in /pbe (or C:/pbe on Windows). I will use that location throughout the rest of this post. Make sure that if you choose a different location that you sub it in wherever I use “/pbe”.
So on OS X, to checkout the source code, open up Terminal and type in the following lines:
Step 2 : Import the PBEngine Library project within Flex/Flash Builder.
Open up Flex Builder (or Flash Builder), right click in the Flex Navigator and choose Import. (You can also use File > Import > Other).
Open up the “General” folder and choose “Existing Projects into Workspace” and click “Next”.
Click the “Browse” button next to “Select root directory”.
In revision 600 of the PushButton Engine I added “FB3″ and “FB4″ directories underneath “trunk/development”. These directories have a Flex Library project skeleton within them that can be imported directly into Flex Builder.
If you are using Flex Builder 3, use the FB3 directory, and if you’re using Flash Builder 4, use the FB4 directory.
Click Finish.
You will see a Flex Library project in the Flex Navigator now. You will also have an error, don’t worry, we’ll fix that in the next step.
Step 3 : Setup the a Linked Resource for PBE
So here is the error that you will see: configuration variable ‘compiler.source-path’ value contains unknown token ‘PBE’
The project skeleton uses something called a “Linked Resource”, so that it can find the PushButton Engine source files. To set this Linked Resource, you do the following:
Open up Flex Builder’s preferences.
Under General > Workspace > Linked Resources… Click “New…”
Click on the “Folder…” button and navigate to the PushButton Engine “trunk” folder, “/pbe/trunk” (C:/pbe/trunk on Windows).
Hit “OK” and you should see PBE listed in the Linked Resources now.
Clean the project to incorporate and rebuild all of the changes.
If you see PBEngine.swc underneath the bin folder, you are good to go! Nice work!
:: UPDATE ::
There have been file renames and other changes in the PushButton engine since this post. If your SWC is failing to build do the following.
In the Flex Navigator, right click on the PBEngine Flex Library project. Click Properties. Go to “Flex Build Library Path”, under “Classes” uncheck [source path] src and recheck it. If you are using Flash Builder 4, you can simply select “Include all classes from all source paths”. Any other questions… post a comment and I’ll answer them.
Step 4 : Create your game!
For this example I’m going to create a VERY simple Hello World game to show that we have everything working correctly.
Right-click in Flex Navigator and choose “New” > “ActionScript Project”.
Give it a name of “HelloGame”, and click Finish.
Now, to use the PBEngine Library within our HelloGame project, we need to create a link between the two.
To do this, right click on the “HelloGame” project and choose “Properties”.
Choose “ActionScript Build Path” from the list, and then click on “Add Project…”
You should see “PBEngine” in the list.
If you don’t see PBEngine, or you get a message that tells you, “There are no Flex Library projects in your workspace”, make sure that a) you have created a PBEngine Library by following the previous steps and b) the project is not closed.
Select “PBEngine” and click “OK”. You will now see PBEngine listed in the Build path libraries box.
Now that the two projects are linked, you can start using classes right out of the PushButton Engine. Code completion works, and everything compiles. Woot!
Great, now let’s write our impressive Hello World game.
Run or Debug the game. At first you will see a blank screen, that is expected… Press the ~ (tilde or `) key, and the PushButton Console should come up.
The console has some commands by default: help, version, showFps and verbose (1 || 2)
You can add your own custom commands to the console to assist you while developing your games… but that is a post for another time.
Any questions, be sure to hit us up over on the PushButton Engine Forums or in the freenode IRC channel: #pbengine.
I’d like to thank everyone who attended my TechWed presentation yesterday. We had around 85 people in attendance! Thanks to Stacy Sison for convincing me that I should present.
I will be giving this presentation again tonight at the Seattle Flex User Group, so if you are in Seattle… show up. We’ll have a bit more time for questions at tonight’s presentation.
[Disclaimer]
Identites have been protected in this blog post by means of Doug’s Safe Sexting application. Any resemblance to persons living or dead should be obvious to them. (You know who you are) [/Disclaimer]
So a fortnight (I wait two weeks to tell anyone anything… so I can use the word fortnight) ago, I had the opportunity, nay the privilege, to attend Doug McCune’s “Cool Shit” session at 360|Flex. As many of you may heard, read or watched, there was an… incident that occurred during Doug’s session.
Apparently, I have been thrown under the bus as the co-conspirator of said incident.
So let us take a journey… starting two nights prior to Doug’s session.
Monday Night
A couple friends and I were hanging around the hotel after partying at the Rock Bottom. We weren’t ready to call it a night. So we decided to see what else Indianapolis could offer us and we hit the streets. We quickly found ourselves at Monument Circle. That’s when one of my colleagues remembered that there was some sort of crazy bowling in Indy.
We had no idea where to go until we ran into Tanner (a horse) and Sky (a man… I think). He gave us directions to duckpin bowling. However, It was too far to walk, so we went back to the hotel where we ran into some other “accomplices”. After a few minutes of trying to figure out what time the duckpin bowling alley closed, one of the Crowne Plaza employees informed us that Jillians had bowling.
We headed over there with the crew. Unfortunately, the bowling alley was full. Undeterred, we went down to the video arcade. We enjoyed Hyper Bowling, Super Shot Deluxe Basketball and Ski Ball. The party came crashing down when a Jillians employee informed us that they will be closing in 30 minutes. With thousands of credits still left on our cards, we decided to see how many tickets we could win before they kicked us to the curb.
So I went to the game that gave us the greatest chance of winning loads of tickets… I’m not sure what it’s called. It’s the dome game with the circle of lights… Well wouldn’t you know it… the first time I hit the button… I hit the jackpot of 375 tickets! I have ninja-like reflexes.
Here is a picture of one of my accomplices with a handful of tickets.
We were able to accrue around 645 tickets in less than 30 minutes, but what do you do with all of those tickets? Well, we decided to cash them out in bouncy balls… all bouncy balls (with the exception of one paratrooper).
Tuesday Night
After a great day at 360|Flex Indy. A group of us decided to try our luck at the bowling alley.
While bowling, we discussed the countless applications of 42 multi-colored, rubber bouncy balls.
Someone mentioned that Doug McCune had tweeted about shaving his chest for his session, and the ideas started flowing. Now as much as I’d love to claim that the brilliant idea of throwing bouncy balls at Doug during his session was all mine… it was truly a group effort.
Wednesday Morning
Wednesday morning rolled around, and I loaded the cup of bouncy balls into my backpack and made my way to the final keynote. We knew Doug’s session would be crowded, so we were sure to sit near the stairs that led up to the room where his session would be held.
After the keynote was finished, we rushed up the stairs to Doug’s room. It was already packed… people had camped out up there during the keynote.
Luckily, I was able to grab a seat in the front row. As soon as I sat down, I noticed that Doug had left the room, probably to refill his glass with water… or vodka. I quickly grabbed a handful of bouncy balls and went to work. Handing them out to the first few rows and giving them the simple instructions of.. “When Doug takes his shirt off, throw the ball at him”.
I wasn’t able to hand out all of the bouncy balls, as Doug re-entered the room and made his way to the front.
Then as the story goes… Doug took his shirt off…
There was a visual hesitation the moment Doug took off his shirt. Nobody was going to throw their ball… and it wasn’t me… but to whomever threw their ball first… bravo!
And finally… the video speaks for itself…
And there you have it… consider yourself in the know.
I also wanted to thank Doug for being such a great sport about the whole thing. You my friend are a rockstar… Keep up the great work!