AS3 Why Your Bitmap Doesn’t Care About Your Input!

Over the past couple of years of doing AS3 coding, it has frustrated me to no end as to why I couldn’t create a new Bitmap object and add Mouse Event Listeners to it.  As I first got into optimizing AS3 display code, trying to shy away from MovieClips everywhere, I started using Sprites more.  As I started learning about the efficiency and pixel-level control of the Bitmap/BitmapData class, I started using those classes more and more.  And every once in a while, I would want to add Mouse Event Listeners to a Bitmap.  Every time during those every once in a while times… it never worked.

Read More…
FacebookTwitterGoogle+Share

AS3 External XML Animation Scripting with TweenMax

Continuing my foray into preparing for collaborative Flash Game Developement, I’ve been thinking a lot about tools, how to set the project up to allow for a maximum variety of skill levels and skill sets to collaborate on the project while trying to keep Flash and Actionscript as much removed as possible. In a recent post, I mentioned 3 things I had learned so far about collaborative game dev.  During one of my first “test runs” of the engine ( aka.. one of the ‘more successful failures’ ) I had realized that with a number of people working on the project, most of which have no idea what the inside of Flash looks like.  Which is great!  We all have our strengths, and because they dont know Flash, it just leaves more room for things that *I* dont know.

Read More…

AS3 Date Class, PHP and Unix Timestamps

This is a real quick post about Unix Timestamps, PHP, and ActionScript 3’s Date class.  When creating a new Date instance, you can pass in a Unix Timestamp into the Date constructor. var myDate:Date = new Date( unix_timestamp_from_php ); trace( myDate.toString() );  // Invalid Date When I was working with this, I continually received Invalid date in my output window.  Looking into the matter, if you read php.net’s time() function description and then taking a look at livedocs Date class we’ll quickly see the problem.

Read More…

3 Lessons Learned in Noob Collaborative Game Development

I’m currently working on a 2D RPG Game Engine ( think Zelda or FinalFantasyII/IV ) in AS3. At the start of this project, as typical projects with friends go, it seems like a completely easy task. “Hey you know AS3… can you write us a quick game engine for this idea we have?” Sure… I’ve finished a simple little game before, I can totally do that. Take 1: From previous (limited) game dev experience I know I’ll need to set up a heirarchy of classes to handle Player Characters, Enemies, Scenes, Buttons, etc. So, thinking things out logically (read: noobishly (?) ) the first thing the team will want to see is going to be a the big-picture, visual framework. I sit down and start hammering out a SceneManager to handle scene changes easily. I’ve created an IZFScene interface to standardize the methods of all of my Scene objects for the SceneManager to manipulate. I’ve got my placeholder backgrounds that I tossed into the Flash Library from photoshop ( or MSPaint ) and I’m off and running creating smooth fade-in/fade-out transitions between scenes. The engine process looks like:

Read More…

AS3 – AMFPHP High Score Database

This is a little tutorial covering using ActionScript 3, PHP and AMFPHP to create a MySQL-based High Score Database.  You should have some familiarity with each as this isn’t exactly a “Beginner’s How-To.” For a recent game project I’ve been working on, one of the requirements was a simple High Score Database. After finishing it, I thought I’d post about how I went about coding it. Let’s jump right in with the ActionScript first… So from the game’s .as files, the idea was to display a DataGrid that shows all the scores submitted to the database. I also wanted to create a ScoresDB class that handles all of my database calls and parses the database results, all ready to be added to the DataGrid. So that we’re all on the same page, Main.as will refer to the main class that handles adding the DataGrid to the stage, and handles other game functions. ScoresDB.as will refer to the ScoresDB class that handles the AMFPHP/PHP/MySQL calls. HighScore.php will refer to the AMFPHP Service that actually interacts with the MySQL database and returns result sets.

Read More…

AS3 – AMFPHP – Secure Flash/MySQL Database Calls

I decided to split the original blog post into two separate posts as “Secure” Flash/MySQL DB calls is fairly short, and it was scattered about in a post more on how to set up a High Score DB with AMFPHP. So this will be a couple of very specific tips and things to set up when adding any sort of user-entered data from flash ( or PHP! ) to touch your database. You know the rule… never trust any data. Always make sure you strictly data type variables and typecast user-entered variables. First up, as the user enters data into Flash, via an input TextField, use the .restrict setter to restrict characters entered to only characters that you need.  This is the first layer of protection against SQL injection attacks , and just follows the same sort of common sense “best practices” type of coding as datatyping variables. nameInputTxt.restrict = "A-Z a-z 0-9"; This will restrict the characters allowed in this textField to only alpha-numeric, capitals and lower case. This excludes potential Injection-prone characters like the single apostrophe ” ‘ ” and semi-colon ” ; ” keys. After that data gets entered, we’re going to send those variables thru AMFPHP into our PHP Class.  In the case of our High Scores Database example, we’re sending both the nameInputTxt data, as well as an integer based score value which gets handled by the following PHP code: function addScore( $pName , $pScore ) { $created = date( "Y-m-d H:i:s"); $cleanName = mysql_real_escape_string( $pName ); $cleanScore = intval( $pScore ); return mysql_query( "INSERT INTO $this->table SET `name` = '{$cleanName}' , `score` = $cleanScore , `created` = '{$created}' "); } You’ll see the $cleanName and $cleanScore variables a couple of lines into the function. For String type user-entered data, always run it through PHP’s mysql_real_escape_string() […]

Read More…

FishEyeMenu Class Update… v1.1

Thanks to a comment posted by doggy, I’ve updated the FishEyeMenu class to listen for MouseDown events and keep track of selected items.   New Functions: public function get selected():* public function get lastSelected():*  public function set selected( clickedItemEvent:MouseEvent ):void   New Event Type FishEyeMenu.SELECTED_CHANGED – Triggered upon a change in selected menu item Once you’ve pushed an item into the FishEyeMenu object, it keeps track of it’s own MouseDown events on the items in it’s array.  When a user clicks on a menu item, it sets the _lastSelected property to whatever Was selected, and sets the _currentSelected property to whatever menu item was clicked.   You can now add an event listener for SELECTED_CHANGED which will dispatch upon MouseDown on a menu item. Please note, the getters for selected and lastSelected are going to return the actual Object that you pushed to the menu.  So it will return a reference to the actual TextField or MovieClip or Sprite or whatever you’re using in the menu.  If you check the Example FLA, you’ll see this code as an example // in the main function fishEyeMenu.addEventListener( FishEyeMenu.SELECTED_CHANGED , changedHandler );   //later in the code: /** * Simple test of usage, fishEyeMenu.selected returns the object selected * so it's just like calling the actual object that was clicked last and * you can set whatever properties that object has. * If this were a MovieClip, you could use fishEyeMenu.selected.gotoAndStop() ***/ private function changedHandler( e:* ) { trace( "Selected Item Changed to : " + fishEyeMenu.selected.name ); trace( "Selected Item Changed to : " + fishEyeMenu.lastSelected.name ); fishEyeMenu.selected.x +=20; } In the simple example, calling fishEyeMenu.selected.x += 20; just moves the object you clicked over 20 pixels to the right (+20). But you could also use fishEyeMenu.selected.gotoAndStop( “Selected” ); if you had […]

Read More…

Preloader to Game Transition with Stop Propagation

This will be a quick post on some gotcha’s to keep an eye out for when loading your ActionScript 3 game swf from a preloader swf. Nothing revolutionary here, back in mid-December, I had posted a blog on ActionScript 3’s Event Handling and the stopPropagation method and just the other day working on the code for a new game project, I ran into a situation where I should’ve used the method, didn’t, and ran into some issues. Note: If you’re here looking for code on how to write a flash preloader, Lee Brimlow’s video tutorial on Preloading in AS3 gives a beautiful example. When I was originally learning how to code a preloader, that tutorial, and a couple of other tutorials around the net that escape my memory at the moment, were absolutely perfect.

Read More…

Useful Air Apps, Reviews, Links

For those of you who haven’t seen or come across this yet, I thought I’d pass this along. AS3 Language Reference Air App I came across that early last month and it has saved me quite a bit of time. If you have AS3 Livedocs as one of your most visited bookmarks, this app brings livedocs to your desktop so you can load it up when you sit down to work on a project and you don’t have to open browsers and wait for pages to load or even be online at all.

Read More…

Internet Explorer 7/8 Transition Please?

February 17th was the date all TV’s in the US were supposed to all… something or other… I dont care.  Here’s the new Idea.  If Congress and … friends… in the FCC can mandate a day for you to lose the significantly inferior signal of analog cable, no matter how attached you’ve become to it… get ready… could we add a little sidenote into this legislation saying… On the Same Day TV’s go Digital, If you have not joined the latter half of your decade by upgrading from Internet Explorer 5/6 to at Least IE7, you will be at risk for the following: PC initiates self-format to erase your whole fail-worthy pc. all social networking & email sites will cancel and ban your account any amount of money currently held in a bank account you check regularly online will be forfeit to web developers and designers who have spent DAYS bent over backwards trying to accomodate and coddle your blatant disregard for the progress of technology by simply clicking “UPDATE NOW,” you will be formatted from the face of the interwebz!! polariods and hard copies of photos of cherished family members will go missing! your car will develop a strange smell that you’ll never be able to put your finger on nor will you be able to ignore it! I’m no writer nor politicial anything, so I’m sure someone removed from my current irritation can easily remove the hate from this fine, fine piece of legislation.  In the words of St. John Stewart, “Make it so, monkey paw!”

Read More…

AS3 FishEye Menu Downloadable Class + TweenLite Example

I made the mistake of looking over some of my past blogs.  My god the code I unleashed from this FishEye Menu Example post, how sloppy was that??!  Ah.. late nite coding.. gotta love it.   At the end of Jan, code hero Jack @ GreenSock released a hot new version of his TweenMax/Lite Tweening masterpiece.  Employing a new ‘plugin’ system for some of the options, it has made things smaller, faster, and more efficient than before.  It’s pretty slick and you should check it out. So, in honor of his update (more to keep up with said update) I created a FishEye Menu Reusable Class that can be downloaded here @ Google Code.  Keep in mind this is rather in its rough draft “beta” stage… as in, if it breaks your code and formats your harddrive and causes a separation with your significant other… well… thats “beta testing” for you!  It’s pretty solid from the testing I’ve done, but I’m interested in getting feedback and definitely in hearing of any errors you might receive.   Thats the most exciting thing about releasing code for me; finding out all the ways someone is trying to use my code that I didn’t pre-plan for.  So with that in mind, download the new FishEye Menu class, play around with it, and let me know how it works for you.  There is a second file there with the FLA and a Main class file that calls the FishEyeMenu class.   I’ve also got another AS3 pair of Classes that I’ll be posting soon… a Waypoint & WaypointList Class for use in AS3 game development.  Should be interesting.   Check out the Wiki for info on How to use the FishEyeMenu Class.

Read More…

AS3 Dictionary Class vs. Array vs. Object!

It’s some sort of crazy nerdtastic Data Structure Deathmatch! The Adobe Actionscript 3 Dictionary Class Vs Object Vs Array!  Man it’s awesome to have a language to work in, just like a great RPG where everyone’s got their strengths and weaknesses and it all works together to make awesome flashlove all over the web. “What is a Dictionary Class and Why Should I read this post?” Here’s the results from my testing right up front and I feel like it’s a good rough estimate of where each excells.

Read More…