This blog has moved to a new location! http://iqandreas.github.com/

Tuesday, January 17, 2012

Ubuntu: Adding FDT to the list of Applications

This post can be found on the new blog at Ubuntu: Adding FDT to the List of Applications
In this guide, we will add FDT to the list of installed applications, and optionally, install a script which "resets" the internal SWFViewer in case it won't open after closing improperly.




The following guide was written for 32bit FDT5, but may still work for future or previous versions of FDT. These instructions can of course also be used for any application that doesn't come with an Ubuntu installer, adjusting the  files appropriately.

If you are running Ubuntu, I'm assuming you already know how to use the basics of the command line and how to manipulate (create, delete, change permissions) of files. If anyone wants more details, post a comment and I'll clarify.

I'm assuming you have already downloaded FDT (they have a free version if you aren't already using FDT) and extracted the archive.

I would recommend saving the files to /opt/fdt5 (may require admin access, which is easily done without messing with the command line by running  gksu nautilus , assuming you are still using the default file browser) Depending on what extraction tool you use, you may also need to change the permission settings for the files to allow access for all users.

Download the FDT5 Launcher files

If you want to do this the easy way, download the pre-made files from the GitHub repository and install them to the locations specified in the README.
https://github.com/IQAndreas/FDT-Ubuntu-Launcher-Files/zipball/master

You are all done. Enjoy!

Alternatively, you can do all the dirty work yourself (if so, keep reading).

Creating the FDT5 Launcher Files manually

Create a new file named FDT5.desktop with the following contents:


If you want the file to be available to all users of the computer, save the file in /usr/share/applications/
Alternatively, if you only want the currently logged in user to have FDT show up in the application menu, save the file to ~/.local/share/applications/

Next, create the following script, and save it as /usr/bin/fdt5


Note that the script may be a tad more complicated than it needs to be, but this is the script I'm using since I had to jump through a few hoops getting FDT to work properly in Ubuntu.


You also need to set the icon for the application. The default Eclipse icon is okay, but on my system, both Eclipse for Java and FB4Linux use that same icon, so I would prefer being able to tell them apart.

I included FDT's fancy, blue dodecahedron icon in the repository, used with permission from Powerflasher GmbH. You can use the icon provided in the repository, or use your own, but which ever icon you use for FDT, make sure to save it to /opt/fdt5/fdt-icon.png

Finally, if you want FDT to stay in the launcher bar, start up FDT, right-click the icon in the launcher, and make sure "Keep in Launcher" is checked.



Cleaning the SWFViewer settings

If the built in FDT SWFViewer quits improperly (which happens from time to time when running into AS3 errors) it will not open the next time you run the SWF. The solution is to delete a few config files for the plugin, which is a simple task, but gets annoying when you need to constantly delete the files.

The following script will delete said config files (assuming FDT is installed to /opt/fdt5 as recommended) though I wish FDT had a button for this inside the IDE instead.


Save the script to /usr/bin/fdt5-clean and run it by typing fdt5-clean into the command prompt. The script does not require admin rights to run as long as your FDT install folder has full permission for all users.


Leave any further questions or problems in the comments and I'll try to help sort them out.

What Beginners need to know about Performance and Garbage Collection

Another category of beginner questions that often appear on the Kirupa forums are about performance and garbage collection. Some common concerns:
  • How do I make sure my MovieClips are garbage collected? Is setting everything to null enough?
  • Should I always remove all my event listeners?
  • Someone told me it's better to use int instead of uint because it's more efficient.
  • I used "while(--i)" instead, because it is much more efficient than for loops.
  • hitTest() is really slow! Every site tells me I should never use it.
My answer to all those questions: Don't worry about it.


Don't get me wrong, if you are the type of person who worries about these sorts of things right now, you will make a terrific developer one day! But worrying about these things now is just going to make your code more complicated and much more difficult to manage.

Strive to make your code clear and readable

As a beginner, this should be your first and foremost rule. If you scratch your head every time you read your own code, coding will be overwhelming and debugging will be hell.

Take these two identical chunks of code as an example:


The first chunk of code is much more efficient than the second, but I wouldn't want to be the developer that find bugs in that project.

So should I never worry about performance?

Not at this point, no. First make sure you have learned the basics and syntax of ActionScript.
Then, make sure you really know the basics of ActionScript (instead of just thinking that you do while perched on top of mount stupid. Believe me, we have all been there). Finally you can start learning about standard coding conventions and basic performance improvements.

Keep in mind, most performance optimization tips (such as using int instead of uint) will shave milliseconds off your total time if you do tens of thousands of calculations each frame.

Often times, the extra milliseconds won't make a hill of beans difference, so worrying about them while writing the code is a waste of resources. Test your code, and make sure your project works. Then, if (and only if!) there is a problem with performance after everything is complete and working, you can go back and find which areas need optimizing.


Why Garbage Collection doesn't matter

Same principle as with optimization, don't worry too much about garbage collection unless you are building an enterprise-level application. Flash is actually pretty good at taking care of things for you and making sure everything gets disposed of properly. Even if it misses an image here or there, what is one measly Bitmap for a computer with +2GB of RAM? Users won't notice the difference if your game uses 17 MB instead of 16 MB.

And remember, it's all disposed once you close the SWF anyway.

Monday, December 26, 2011

The Humble AIR Bundle

This post can be found on the new blog at The Humble AIR Bundle
I'd like to say straight off the bat that this bundle does not exist. It's just an idea I have been playing with in my mind.

Adobe recently announced that they will no longer be releasing updates for AIR for Linux. This saddens me, mainly because the reason I switched from working with .Net to Flash was the "multi-platformness" - the ability to compile once and have your game or application run on any operating system (it has a proper name, but it's still on the tip of my tongue).

A few games in previous Humble Indie Bundles were actually Flash games (even if the players don't notice it); Samorost 2, Machinarium, and Trauma. Even though Flash can't make the most powerful of games, it's fairly obvious that Flash games are at least playable.

AIR increases the functionality of Flash, and adds mobile devices to the available platforms, all with very little additional changes made to your existing game or application.


I'm sure if a small group of Flash game developers teamed up "Humble Bundle style" they could release a bundle with multi-platform, DRM-free AIR games, with proceeds either going towards charities, or perhaps towards the open source developers working on the AIR binaries for Linux. In either case, the bundle would provide positive publicity for AIR.


I don't have the influence or resources to do this, but do you?



Friday, November 25, 2011

Is High Score dead?

This post can be found on the new blog at Is High Score dead?
I have recently played with the thought of the classic high score system being "dead". These viewpoints are from the perspective as a player rather than a developer.


Remember the good old days of playing Pac-Man at the arcade, burning quarter after quarter until you were #1? You could then laugh in the face of the last high score holder, and brag to all the local children and challenge them to beat your score.
(Or maybe not, I was born a few years too late for the glory days of arcade games, so I'm guessing at how the high scores worked back then)

But today, with the rise of flash games, no matter how hard you work at getting to the top, your fantastic score of 189,335 points will place you at position #24,890 in the high score list, with the top scores always being held by cheaters or some Asian kid with an abnormal talent for games and hours of time on his hands.


Perhaps I'm just a pessimist, but if there is no cosmic chance of me even showing up on the top 100, 
what's the point of replaying the game to get a better score?


So, what do you think? Did the widespread availability of the internet and the surprisingly large amount of people on this planet kill the classic high score system? (leave a comment if you disagree, I could be wrong)

Or is the high score system still kept alive by Facebook games where you only see the scores of your friends?


High Score done right!

I recently purchased the game SpaceChem by Zachtronics Industries.
SIDE NOTE: I have long been a fan of that developer's flash games, and I'm happy his newest creation is having so much success. SpaceChem is one of my favorite games, and I would really recommend it if you enjoy puzzle games, and it definitely helps if you have a "programmers mindset". You can grab the demo if you want to try it before purchasing the game.

SpaceChem does an amazing job at including a high score system without "intimidating" the score you worked so hard for.

When you have finished a working design, you see a bar chart of how creation's efficiency compares to the average user. This allows you to see which areas you could realistically improve your score without being blown out of the water by Sum Yung Gui from Beijing.




If you know of any other games with unique and brilliant high score systems, share them in the comments.

Wednesday, October 19, 2011

Keeping POP emails synched?

I'm looking for a specific email client (or perhaps some sort of elaborate system or setup is needed, I worry). To describe it, I'll first explain what I love about my Hotmail email*.

There is a free web interface (at http://www.hotmail.com/)
There is a free desktop email client (Windows Live Mail, which is sadly Windows only) 
The key is that the messages are "synched" between the web interface and the client. So, if you delete messages, move messages to different folders, or even mark messages as read, the changes will be applied in both the web interface as well as the desktop client.

Sadly, the business email account I'm setting up does not use Hotmail. It uses POP for accessing the email (I believe the provider actually uses Google's mail servers rather than their own if that makes any difference).

Is there any way I can have this "synching" behavior with a standard POP email account?


* This post is not sponsored my Microsoft. I just happen to have been using my personal Hotmail email address for soon a decade and haven't gotten around to switching.

It seems that IMAP is just what I'm looking for:
http://www.kirupa.com/forum/showthread.php?369062-Keeping-POP-email-accounts-synched-between-web-and-desktop&p=2626258&viewfull=1#post2626258

Saturday, June 4, 2011

Does "Ponycorns" exploit the mentally ill?

This post can be found on the new blog at Does "Ponycorns" Exploit the Mentally Ill?
Untold Entertainment recently released a new game, "Sissy's Magical Ponycorn Adventure".



Already the game has had some positive media attention, from interviews on both local radio and television, to several internet news sites including Yahoo news and BoingBoing.

After only having been released for soon two weeks (as of today, June 4, 2011) the game has received about 200,000 plays and $2,500 in donations (and more is likely to follow as time progresses).


This game must be awesome!!

Is the game deserving of all this media attention by being awesome and fantastic, with hours of intricate puzzles, stunning graphics, and gripping story lines? No.

Then why so much popularity? The graphics, sound effects (including most of the dialog), and story were all designed by a 5 year old, little girl.


Assume for a second that this game had been released on Newgrounds (which is, from what I hear, the #1 portal for Flash content with not enough quality to be allowed on portals with "higher standards") and Ryan Creighton (the father and lead developer) had proudly announced that he had produced the game all on his own.

Ryan could then sit back and expect a steady stream of classic Newgrounds comments such as "OMGWTF gay", "-9999/10", and "giv me my 2mins of life bak".


"Ponycorns" exploits the mentally ill

At this point you are probably calling me an insensitive prick and have likely already started to flame me in the comments. But, I am trying to make a point here.

This game takes advantage of at least two "weaknesses" (couldn't find a better word) of human nature.


FW: FW: FW: FW: FW: Funny pictures (must see!)

First, people love babies, young children, and kittens (for various reasons you can likely dig up a lot of research on yourself). Anyone who doesn't believe me apparently doesn't have family members who have learned to use the "forward" button on their emails.

Seb Lee-Delisle's iPhone app, Kitten Conveyorbelt, is another game which takes advantage of this exploit ($1 for a slideshow of cats, seriously?)

Somewhat related, the "8 Beyblades for sale on eBay", despite having several "fake bids", still received a lot more bid amounts than selling the Beyblades on their own would have. Why? People feel sorry for these crying little children and their situation.

(Next time you try selling your car, include a picture of yourself next to it crying and see if it also works with grown-ups)


Good job, sweetie. I'll put this up on the fridge where everyone can see it

Second, humans (at least the empathetical ones) will value items and achievements higher if they were produced when the "creator" was under certain limitations (in the case of Cassie Creighton, limitations in age and game development experience).

Did your mother put your paintings of a giraffe with rockets strapped to it on the refrigerator because your work was comparable to Rembrandt?
And why would anyone otherwise care about "special olympics"?
And what makes Michael Phelps much more famous than all other swimmers?


On a related note, even I can draw better than this elephant! Why don't my YouTube videos get 6.5 million views?



What can we learn from all this?

Other than the obvious point of "Taking advantage of human psychological flaws leads to more attention and in return buckets of easy money", there is a broader point to be made (which is by far no new idea):
Presentation is key

As I still haven't produced even a single game, I feel like some sort of hypocrite (did I use that word correctly or is there a better term?) telling people how to design their games. After all, what do I know?

Luckily, the principle has many more applications. Often when presenting something, you are very limited, such as the title of a blog post, description of a game, or a small introduction in a conversation or speech.

Presenting any creation as "just another of many" will quickly cause the listener to loose interest. What makes your product unique? How does it stand out from the rest? (Note that I do not support lying or over-exaggerating in order to glorify what you are selling! Scumbags...)

Perhaps it will gain more attention if you release it for a good cause, such as donating all income from a game to earthquake/tsunami victims.

Perhaps even take advantage of a few other human psychological flaws, such as curiosity to reel in your listeners (this blog post title got you here, didn't it?)


Does Apple exploit the mentally ill?

I simply cannot end a discussion on exploiting human psychology without bringing up Apple.

As I have said many times before (which someone said before me, but I don't remember the source), Apple sells a religion, not a product. When you buy their iPhone, you buy an experience, and a ticket into the community of awesome people.

In a nutshell "Cigarettes Apple's products make you look cool!"



FAQ


Is Ryan Creighton exploiting our weaknesses for monetary gain?

It's possible, but I doubt it.

This may be a good place to add that all donations and income from Mochi Ads are going directly to Cassie's college fund (so help her education, and donate! Link is on the game's page)


Does this mean you hate the game?? And little children?!?

Alas, I am neither a Vulcan nor a sociopath, and susceptible to the same flaws of human psychology as everyone else, so yes, I thought it was cute.

The one thing in specific I enjoyed were the small witty bits of dialog. They reminded a bit of the the comments found in Lemony Snicket's books (sample excerpt)

My favorite quotes from the game (spoiler alert)
Your'e a mouse now. How do you like THEM apples?
That's what you get for being evil! AND a lemon!


Did you write this post to stir up conflict and flame wars, or perhaps to ride the wake of Ponycorn's success?

Neither, by writing this post I'm avoiding the PHP work on my plate, and since I'm still getting something done, I can avoid the feelings of guilt that come from procrastinating my real work.

Friday, June 3, 2011

[Experiment] Drop Painter

This post can be found on the new blog at Experiment: Drop Painter
No, it's not painting with drops (though, that seems like a great idea for another project). Instead this experiment drops pieces of a painting down from above which eventually form to assemble a complete picture.

DEMO: http://iqandreas.isbetterthanyou.org/public/kirupa.com/square-contest-2011/


The code is written in AS3 and uses Box2D for the physics and MinimalComps for the components.

At first I wrote the code up as a prototype just to test a concept (and rather than rewrite the code cleanly, I just kept adding onto it so it became one tightly-coupled mess).

Later I entered it into a contest held on the Kirupa Forums, and modified it slightly to fit the contest theme.


The source is available on GitHub in case anyone is curious how it was achieved (and yes, I did cheat. It's not actually dynamic. The movement of all those shapes are "pre-baked" during the "Loading" screen and simply played back afterwards, which is why it is able to take up so little CPU on playback.

Wednesday, March 30, 2011

Developing for the Playbook: Chapter 3 - The Emulator

This post can be found on the new blog at Developing for the Playbook: Chapter 3 - the Emulator



TODO: Insert chapter 1. (I was too lazy to repeat the steps just to take screenshots of the process. I don't feel like going through that again.)

TODO: Insert chapter 2. (Same reason as for chapter 1)


Chapter 3: The Emulator

















Stay tuned for "Chapter 4: The Code Signing!"

Tuesday, October 19, 2010

Understanding the AS3 Event System #3 - Easy Event Bubbling

This post can be found on the new blog at Understanding the AS3 Event System #3 - Easy Event Bubbling
This thread is part 3 in a "Understanding the AS3 Event System" series. It continues on the "office" illustration used in parts #1 and #2. If you have not read part 1, it is recommended that you do so:
http://iqandreas.blogspot.com/2010/10/understanding-as3-event-system-1-basics.html

This part describes how "Event Bubbling" works. Note that this is a strong simplification of the actual system (which is a bit more complex, but in the next part I will elaborate on that system), but for 99% of all Event uses, this is the only thing you really need to know about Event Bubbling.



At the office I work, a large part of our work system is set up as a hierarchy of responsibility and work delegation.

The Corporate Ladder
At the very top of the tree is Mr. Stan Stage. He's a great guy. Very friendly, a nice father figure, and a really good boss. He is the boss of all bosses, and in the end, everyone reports to him.

Since there is so much information passed around the office each day, he delegates a lot of the tasks to a handful of people who work right under him. These people are all "second in command". One of these second in command is my boss. Unlike Mr. Stage, my boss is very annoying and difficult, and to avoid his wrath, I will exclude his name, and instead just call him "My Boss".

My Boss has about 20 people working under him, including me. It's not a great position to be in, but it's still a very rewarding job. Some of us "third in command" workers have people working directly under us.

I am one of the lucky ones, and have five interns working directly for me. Since I am their boss, they obey my every whim, such as getting coffee for me each morning, or taking out my dry-cleaning. Even though they are only interns, they are still considered to be "fourth in command".


Since a great deal of what we do at the Office is reported via Events, my interns are expected to use the event system to report any changes just like the rest of us.

For efficiency's sake, my five interns have their desks very close to my cubicle, so whenever they dispatch an event (by standing up and shouting for example "I was hovered!") I hear it immediately.

Now, there are two types of Events. Events that Bubble, and Events that do not Bubble.


Non-Bubbling Events
Some Events are only important to the person which it actually happened to. For instance, one day one of my interns, Chris, stands up and yells "Hey everyone, I got a new car!"
dispatchEvent(new Event("new_car"));

A few of my other interns reacted. However, I honestly did not care. My Boss sure as hell doesn't care. And as nice of guy Steve Stage is, he really doesn't care either.

I'm not saying that Chris's Event wasn't important, in fact, it was quite important since it allows him to do his job better and will definitely affect his work. However, there is no need to tell as many people about it as possible. The only people who need to know about the event are people who specifically asked Chris to let them know whenever he got a new car.
chris.addEventListener("new_car", talkToChrisAboutTheCar);

Those Events do not Bubble up the corporate ladder.


Events that Bubble
Now, clicks are VERY important in my line of work (in fact, that's how we get paid).

We want to let as many people as possible who want to know about the clicks to know about the clicks, but if every single person just stood up and yelled "Someone was clicked!" whenever they found out about it, it would be one disorganized mess and you would hear about the same gossip from 8 different people. Instead, we have an organized system for letting everyone  in charge know about it.


Bubbling Events up the Ladder
One day Chris stands up and yells out to everyone "I was clicked!" (dispatching the event to everyone that may be listening to him. Not many people are usually listening to Chris (in fact, most people at the office don't even know any of my interns). So, Chris tells everyone listening to him about the click event.

Then Chris walks over to me and says "Andreas. I was clicked. All the information on the click is available in this file folder."

Now it's my turn. I stand up and yell "I was clicked!" (I could tell them "someone in my department was clicked", but since my interns work for me so closely, their work is considered to be part of my work) A few people are listening to me for the "clicked" event, (including Nico and Bob) and walk up to me asking for more information. I give them both the file so they have all the information on the event that they need.

Then, I barge into the office of my Boss, telling him all about the event, and handing him a copy of the information. He in turn switches on his fancy intercom system (since he is second in command, he gets certain perks, and is paid too much to have to yell across the hallway) and announces to everyone in the office "Attention anyone who is listening to me. I was just clicked." A few people are listening to him, and respond.

Finally, my Boss knocks on the door of Steve Stage and tells him all about the click event. Now, at last, Mr. Stage announces the click event for the last time, telling everyone who is listening to him about the click.

After that it is done. Everyone who needs to know about the event knows about it.


Now why is Bubbling so important?
Let's take the example of Betty, who works in accounting. In order to do her job property, she needs to know about every single time a client "clicked" an employee.

She could listen to every single employee for the "click" event, but this is a VERY inefficient system. And every time there is a new employee she would need to start listening to them, and when an employee leaves, she needs to remember to stop listening to them.

Instead, because of our nifty little bubbling system, Betty ONLY needs to listen Stage for the "click" event. Since those events bubble up to Steve, she will be notified of every single click event directly from Steve Stage.


EXTRA NOTE: Events only bubble upwards
Let's say one day I'm working at my desk, when a client clicks me directly instead of clicking one of my interns. I stand up and yell to everyone who is listening to me that "I was clicked", but I do not need to directly tell any of my interns about the click. Unless my interns are specifically listening to me, they will not know about the click and will keep carrying on their work undisturbed. The interns will NOT dispatch any "click" event either.

The only one who needs to know is My Boss. The events only bubble "up" the corporate ladder, not down.


So who was clicked first?
In order to file the proper paperwork (and hand out promotions or raises where needed) Betty needs to know exactly which person it was who was "clicked" first. Luckily, all this information is perfectly filled out in the Event object (the folder containing all the information).

There are two names in the Event object, "target" and "currentTarget". Flash assigns these two names automatically when the Event is dispatched.

These two properties tend to cause a lot of confusion among beginners. Sometimes they refer to the same person, sometimes they do not. To explain the difference, let's take another example.


Nico is listening to me for the "clicked" event.
andreas.addEventListener("clicked", onClick);

Chris, my intern, is clicked, and stands up and tells everyone about it. Nico doesn't even know Chris and therefore doesn't even know about the event. Chris tells me about the event and hands me all the information.

Now, I stand up and tell everyone "I was clicked". Nico is listening for the event, and walks over to me to gather all the information.

Then the event continues to bubble upwards to My Boss and finally Stan Stage.


target refers to the person who first dispatched the event. In this case, Chris would be the target.
currentTarget refers to the person you were listening to who told you about the event.

Think about "currentTarget" for a second. For Nico, currentTarget would refer to me, Andreas. However, since Betty is listening to Stan Stage for the Event, the currentTarget property in her event file would refer to Mr. Stage.


Using currentTarget to your advantage
Why does the "currentTarget" property even exist? I mean if you added the event listener to an object, of course you know what that object is, and therefore the property is pretty much worthless.

However, if used properly, it can save you a lot of code! For instance, perhaps you have several buttons on the stage "homeButton", "aboutButton", "contactButton", "newsButton", etc. You want the button to scale up when it is clicked. You could add the event listeners like this:

homeButton.addEventListener(MouseEvent.CLICK, homeButtonClicked);
aboutButton.addEventListener(MouseEvent.CLICK, aboutButtonClicked);
contactButton.addEventListener(MouseEvent.CLICK, contactButtonClicked);
newsButton.addEventListener(MouseEvent.CLICK, newsButtonClicked);

function homeButtonClicked(mev:MouseEvent):void
{
   homeButton.scaleX = 1.2;
   homeButton.scaleY = 1.2;
}
//etc...


That means, creating a different handler function for each button, which works, but creates a lot of extra code. Then if you want to change details of what happens when a button is clicked, you would need to update every single function.


Instead, you can create one single function which handles the clicks of all buttons. You can calculate which button needs to be pressed by using the "currentTarget" property.

homeButton.addEventListener(MouseEvent.CLICK, navigationButtonClicked);
aboutButton.addEventListener(MouseEvent.CLICK, navigationButtonClicked);
contactButton.addEventListener(MouseEvent.CLICK, navigationButtonClicked);
newsButton.addEventListener(MouseEvent.CLICK, navigationButtonClicked);

function navigationButtonClicked(mev:MouseEvent):void
{
   var pressedButton:DisplayObject = mev.currentTarget as DisplayObject;
   pressedButton.scaleX = 1.2;
   pressedButton.scaleY = 1.2;
}


Which uses only a single function! Now, if you need to change the scaling to 1.3, you only have to update it in one single place!


If you want to attach additional properties to the buttons, (such as setting some custom scale value for each button) you can use the Dictionary object. Look in the FAQ under the appropriate category for links to explanations and example code:
http://iqandreas.blogspot.com/2009/09/most-common-flash-questions-as3-faq.html



This is how Flash bubbles it's events. Next step, how to make your own events bubble.

Tuesday, October 12, 2010

Understanding the AS3 Event System #2 - Custom Events

This post can be found on the new blog at Understanding the AS3 Event System #2 - Custom Events
This thread is part 2 in a "Understanding the AS3 Event System" series. It continues on the "office" illustration used in part 1. If you have not read part 1, it is recommended that you do so:
http://iqandreas.blogspot.com/2010/10/understanding-as3-event-system-1-basics.html


I originally wrote this thread as a response to a Kirupa forum thread:
http://www.kirupa.com/forum/showthread.php?t=355040


This is my first draft, so any opinions or thoughts are deeply appreciated, especially if there is anything you still don't fully understand or would like me to clarify further.



Listen, don't tell my boss, but those days when work gets slow, I fire up some StarCraft! StarCraft is no fun alone, so Nico, Bob, Larry, and I all play against eachother. The problem is that we all need to be logged on at the same time in order to play together. I'm the one who plays the most, so I am the "Game Master" - the one who starts up the server, chooses a map, and waits for everyone else to join in.

We need some way to alert eachother when I start up a StarCraft game, AND keep it a secret from my boss (he reads all our emails, so I can't tell them via email). So, we use the Event system!


Custom Event Strings
We have planned that whenever I am about to start up a new game, I stand up and yell out to everyone "I am about to call Yamato!" (who our boss assumes is one of my Japanese clients)

Everyone knows that the custom event string (or event type) for when everyone listening should play starcraft is "Yamato". So, ahead of time, Nico, Bob, and Larry listen for my "Yamato" event:

Code:
homeButton.addEventListener("Yamato", startPlayingStarScraft);
Now, we may start playing dozens of different games, and I have chosen a different "code name" as the event string for each type of game:
Code:
homeButton.addEventListener("MarcoPolo", startPlayingAOE);
homeButton.addEventListener("Gelinor", startPlayingRuneScape);
homeButton.addEventListener("Germany", startPlayingCOD);
homeButton.addEventListener("Orcish", startPlayingWOW);

Custom Events
Now, I could create a different type of Event Folder for each type of game, such as StarCraftEvent, RuneScapeEvent, AOEEvent etc.

Each type of event file would have information inside of it, for instance, the "StarCraftEvent Folder" may have the following properties:
> the target - Me, since I'm the one "dispatching" the event
> the type - the custom event string, in this case "Yamato"
> map - the StarCraft map we will be playing in
> players - a list of all players
> settings - the game settings

And our class would look something like this (note that "target" and "type" are automatically inherited by the Event since you "extend" it)
Code:
public class StarCraftEvent extends Event
{
    public function StarCraftEvent(the_type:String, the_map:SCMap, the_players:Array, the_settings:GameSettings)
    {
        //Since you extend the Event, let the super class know a few more additional details
        super(the_type);
        
        map = the_map;
        players = the_players;
        settings = the_settings;
    }
    
    public var map:SCMap;
    public var players:Array;
    public var settings:GameSettings
}
This would be my totally custom made event class! Perfectly customized for whenever we want to start a StarCraft game, allowing everyone to get the information they need!


Dispatching the Custom Event
This is exactly as simple as it was dispatching the "clicked" event:
Code:
//Create the event
var players:Array = [Andreas, Nico, Bob, Larry];
var scEvent:StarCraftEvent = new StarCraftEvent("Yamato", lostTemple, players, defaultSettings);

//Dispatch the event (and it's folder containing all the info)
dispatchEvent(scEvent);
That dispatches an event which alerts everyone who is listening that I am about to start up a StarCraft game.

So, Nico, Bob, and Larry run up to my cubicle and I hand them all the StarCraftEvent Folder containing ALL the information they need to join in the game.


Do you really need to create Custom Events?
Now I can create a new Custom Event for each and every game we play and that would alright.

But I noticed, no one really reads the information in the Event Folder! I spent good money putting together and printing out all the information for those folders, and no one reads them! They get the file from me, then they run back to their own cubicles, fire up the game, and throw the Event Folder directly into the trash.

When you think about it, do they really NEED all that extra information such as maps or players? They will find all that information out anyway when they start up StarCraft. There really is no use going into all the hassle of creating custom events!

Instead, what if I print out a plain old Event Folder? All it says is the "target" and the "type", but if they want more information (which one one does) they can ask me for it directly.

FORGET about the hassle with the StarCraftEvent class, and just do this:
Code:
var eventFolder:Event = new Event("Yamato");
dispatchEvent(eventFolder);
99% of the time. That is all you will ever need. You save a lot of unnecessary work.


You don't always need to create custom Events, usually it is enough just using custom Event Strings.


That is Custom Events 101


Monday, October 11, 2010

Understanding the AS3 Event System #1 - The Basics

This post can be found on the new blog at Understanding the AS3 Event System #1 - the Basics
I originally wrote this thread as a response to a Kirupa forum thread:
http://www.kirupa.com/forum/showthread.php?t=355040

This is my first draft, so any opinions or thoughts are deeply appreciated, especially if there is anything you still don't fully understand or would like me to clarify further.


Imagine your code as one big office room. That office has about 100 or so cubicles, with each cubicle representing a different object. For instance, if you have 5 Buttons on the stage, it's not one "Button" cubicle, but instead 5 different cubicles, one for each button instance.


The Event String/Event Type
Now, I'm sitting in the "homeButton" cubicle. One day, I get an email from my boss who tells me I have been "clicked". So immediately I stand up, and yell out into the hallway so loudly that everyone can hear "I HAVE BEEN CLICKED!"

Now, the boss may have A LOT more information, such as where I was clicked, how many times, if any of my children were clicked, and a lot more information. However, I won't stand up and yell out to everyone in the building all that information. That is quite wasteful, and if I got several of those emails a day, I would soon get tired of spouting out all that information.

Instead, to save energy, I only tell everyone "I have been clicked". That is me telling everybody the event type, also known as the event string.


Listening for Events
Back up a few hours (before the event string). I have a friend named Nico sitting in the art department (his cubicle is labeled "currentImage" though that's not really that relevant). His boss told him "Whenever Andreas in the homeButton cubicle is clicked I want you to draw an image of a house and send it right to me."

Now, Nico could get up out of his seat every five minutes, walk over to me, and ask "Hey, Andreas. Were you clicked yet?" I say no, so he walks back to his cubicle and sits down. This would happen again and again, and neither of us would get any work done. This is VERY inefficient. Nico could reduce this and only check with me once per hour, but he wants to know immediately when I am clicked. So that is NOT an option either.

Instead, Nico sits in his cubicle continuing his regular work, and in the meantime, listens out in the hallway for my voice. Now, at around noon I yell out "I was keypressed!" He hears my voice, but he really doesn't care about the keypresses. So, he ignores what I say, and continues working. Then another guy in the cubicle (Larry, a really annoying guy) yells out "I was clicked!" Since Larry is not as good looking as Andreas, and The Boss didn't tell Nico to listen to Larry, Nico ignores him completely.

Because, Nico is only listening to Andreas (in the homeButton cubicle) for the "clicked" event. When he hears the event, he needs to start drawing the house (which looks something like this in AS3):

Code:
homeButton.addEventListener("clicked", drawHouse);
The Event is dispatched
Now, fast forward back to where we were. Me (Andreas) gets the call from my boss telling me I was clicked. So I stand up and yell out to everyone. "I was clicked!"

Two people were listening for my "clicked", Nico and Bob (the guy from 'contentManagement', a very talkative fellow) Nico rushes up to me excited "Hey Andreas. I heard about the click. That is awesome! Congratulations! But tell me more about the event! Why were you clicked? Where were you clicked? Who clicked you? Why did they click you?"

I could spend the next 5 minutes explaining all the juicy details to Nico, but then I would have to repeat all this information to Bob (which is very inefficient, and Bob is a busy man and doesn't want to wait). So instead, I print out all the information on the "clicked event" and put it into a Folder which I give to Nico. I give the folder to both Nico and Bob so they can use the information in it and look at it as they please. This folder is the Event object (more details on that later)

Immediatly Nico rushes to his art studio in his cubicle and gets to work at "drawHouse()", however, now he has the Folder (the Event) he can use that information while drawing the house, and therefore passes it into the function as a parameter:
Code:
function drawHouse(event:Event)
{ /*Draw stuff in here...*/ }
The Event
To make sure that everyone gets the information they need, there are VERY strict protocols to what the Event Folder needs to contain.

The following pages with information are required for standard Event Folders
>the target - the person dispatching the event, which in this case is me, Andreas (or actually the homeButton cubicle).
>event type - the type of event (aka event string), in this case "clicked".
(there are a few more pages in the file, but that's mostly the small legal mumbo-jumbo fine print that no one reads anyway. You will be fine ignoring them for now.)

This is a standard Event file. But hold on, there was A LOT more information which is missing here! If I hand Nico a file with only those two pages of information in it, he will still wonder "Where were you clicked?" among MANY other important questions. Luckily, the company already has a neat system figured out!


The MouseEvent
Now, the company I work for has a second type of file, a "MouseEvent File". This file extends the standard Event File. That means that the MouseEvent file has all the information contained in the plus a lot more information, perfect for when a "clicked" event happened.

It has the standard two fields (target and type) PLUS these additional pages with information:
>localX
>localY
>stageX
>stageY
>altKey
>ctrlKey
And a whole lot more!

Note that this MouseEvent file ONLY is allowed to be used when dealing with events that had to do with the mouse, such as "clicked", "hovered" etc. The file should NOT be used for events that had to do with the keyboard, "keypressed" or "keyreleased". Those events should instead use a specialized KeyboardEvent File with it's own special properties.


So I print out all the relevant information and hand both Nico and Bob a "MouseEvent" folder. Using that information, they draw the houses, or display text, or whatever they want to do with the information.

(Extra note: Maybe Bob didn't even need to see the file. Maybe he just needed to know that I was clicked, so when I hand him the file, he may not even open it or look at the details of the click using the information inside. That's fine by me, but I still need to create the file in case there is someone out there who actually needs the information.)


Creating the MouseEvent
Bob and Nico don't want to wait for me to print out and collect all the papers needed in the MouseEvent file. They want the information to be ready the second they step up to my cubicle. So, BEFORE I stand up and tell everyone I was clicked, I create the folder ahead of time for quick and easy access. THEN, I dispatch it to all who are listening.

This is how it looks in ActionScript:
Code:
//create the folder with all the information in it
var eventFolder:MouseEvent = new MouseEvent("clicked", bla, bla, localX, localY, bla, bla, bla, bla, more bla);

//Now stand up and tell everyone I was clicked
//The "eventFolder" already says the event type is "clicked",
// so I don't need to repeat myself when dispatching it.
//All I need to do is dispatch the folder and Flash will do all the dirty work
dispatchEvent(eventFolder);
Now Nico and Bob (and whoever else is listening) can react to it and get to see the folder I sent when dispatching:
Code:
function drawHouse( andreasEventFolder:MouseEvent )
{ /*Draw stuff in here...*/ }
That is Events 101.


Monday, June 7, 2010

[K2Fave] Joomla K2Fave - Frequently Asked Questions

This article relates to the Joomla K2 modification "K2Fave"
http://iqandreas.blogspot.com/2010/06/joomla-k2-favorite-item-manager.html


To my surprise and amazement, a lot of responses already and so very quickly. Here are a few questions that have arisen so far. I will keep adding to this list over time, so check back if you run into any issues.


How can I view all my favorites?

There are three ways. Sadly, you are going to need access to the raw PHP code in all instances. If anyone is better with the Joomla framework, perhaps they can help bridge this in a way so you can put in a "favorites" table in any page from inside the "page editor".

Just plain import
You can just plain and simple import a basic page which already has all the imports and everything you need.
include(JPATH_BASE.DS.'components'.DS.'com_k2'.DS.'k2fave'.DS.'viewfaves.html.php');

I noticed one small flaw on that page you might have to fix unless you downloaded the release fixed a few minutes ago. Inside of "viewfaves.html.php"
//Replace the following line
ForetagFave::listUserFavorites($user);

//With this
K2Fave::listUserFavorites($user);

Access the "K2Fave" class directly
Wherever you want the table of favorites to appear, place the following code:
//Get current user - you can do this any way you please
$user =& JFactory::getUser();
K2Fave::listUserFavorites($user);
Access raw data from the database
This might take some PHP experience to get done, but if you want the actual array filled with all favorites, try this code:
include(JPATH_BASE.DS.'components'.DS.'com_k2'.DS.'k2fave'.DS.'k2fave.db.php');
$user =& JFactory::getUser();
$favoritesArray = K2FaveDatabase::getFaves($user->);
The returned array is a list of objects, all with integers named "user_id" and "item_id". See the "K2Fave::listUserFavorites()" function (located in k2fave.php) for an example of how to parse the array into a usable table.

The K2Fave class has a few more functions which may assist in creating a good table; such as makeRemoveURL() and makeK2ItemLink(). See the class definition for more details.


How can I format the favorites table?

The table is formatted as a plain, old <table>, so wrap whatever code you are using to make the table show up in CSS span or div tags, and set whatever formatting you need either in side of those, or in a separate CSS file.

For free tutorials on CSS and how to use it properly, I would recommend W3Schools, along with a good old fashioned Google search.
http://www.w3schools.com/css/default.asp
http://www.google.com/#q=css+tutorial

Otherwise, the table should take on the default formatting for tables set in your global style sheet.


The favorites are able to be added more than once, causing duplicates

This means that the rows were not both set to "PRIMARY_KEY". This can be a bit tricky, and not really common in most cases, but the following guide should help with both creating the table, or modifying the table in case it was already created.

IN PROGRESS: I'm working on a post which describes how to set up the database properly. Should be done tomorrow morning.


I'm getting an error message!

Great! Tell me about it! See the answer to the question below for contact details.

It would be easier if you copy and paste the EXACT error message, which makes it a lot easier for me to track down the bugs.

If a completely blank page is showing up rather than an error, try turning on global error reporting in the Joomla! settings.


But that's not enough! I want my favorites manager to also do this and that, and then do si and so...

Great! I would be happy to implement any ideas you may have into future versions of K2Fave.

If you want very specific modifications made to K2Fave for any part of Joomla or K2, (such as playing a Fanfare when they add an item to favorites, and Taps when they remove the item from favorites - anything really) send me a message using the contact details below.


All this PHP and MySQL is quite confusing. I just want the favorites thing to work; I don't want to worry about it.

I would be more than happy to implement those changes for you, as well as any other reasonable modifications you may want to the existing system for a flat rate of $30 USD. This includes not only installation, but also any text, customization, styling, and custom implementation.

If you have low income or a low traffic site, we might be able to work out special arrangements, so don't give up even if you may be 15 and trying to make it on a $10 per week allowance. ;)


This is fantastic! Your modifications saved me hundreds of dollars! Thank you!

First of all, I would love to hear about your experiences, as well as any live examples of the modification in use. Please leave a comment. :)

Second, I am releasing these modifications for for free, and although it's not required, if you do make money from the project, or have saved money thanks to this project, I would really appreciate a donation so I can keep my programming work alive and keep these modifications and extensions coming for free.
I might even name my firstborn after you out of joy and appreciation.


How can I get ahold of you?

In the README.txt file there is an email address. I would prefer you not release it publicly for fear that it gets picked up by spambots. I hate having to switch to a new email address due to too much spam.

That email address is also used as my MSN Messenger account, in case you prefer instant replies to questions. I'm usually logged in most of the time.

I also have a contact form which will always forward all your messages to the newest email address
http://iqandreas.isbetterthanyou.org/contact.htm

[K2Fave] Joomla! K2 favorites plugin translated and finished

I spent the weekend translating and fixing up the K2Fave modification, so now it should be completely understandable, as well as adjustable to anyone's needs.

For more details, see the original blog post
http://iqandreas.blogspot.com/2010/06/joomla-k2-favorite-item-manager.html


Easily changeable text and user messages

Any major text or language changes can be done in "messages.php", which contains several lines similar to this:
define('T_ADD_TO_FAVES', "Add item to favorites");

Any form of HTML tags, including images, are allowed in that field, so rather than modifying the source directly, all you need to do is modify the text in the messages file. This is also convenient if you want multilingual support for a site, and can easily be achieved with a few slight modifications.


Database changes

If anyone has already implemented the previous release, the database needs to be renamed to "jos_k2_favorites" with the following fields:
user_id int(11) PRIMARY_KEY
item_id int(11) PRIMARY_KEY
NOTE: This is in addition to updating the PHP files!


Documentation

The most relevant information can be found in the README.txt file inside the ZIP, or on the original blog post.

Most everything is self explanatory, but if anyone needs any better documentation or clarification for anything, leave a comment or send an email to the address listed in the readme file.


Installation

The installation steps are the same as before, and the ZIP file can be found in the same location as before.
http://iqandreas.isbetterthanyou.org/files/joomla/k2fave/k2fave.zip


Cheers,
Andreas
http://iqandreas.blogspot.com/
http://iqandreas.isbetterthanyou.org/

Sunday, June 6, 2010

[K2Fave] Joomla! K2 Favorite item manager

NOTE! This modification has been updated to release version 1.0, if you still have the old version (without proper translations), please update. More information is available in this post

Greetings Joomlaers!

As there was a need for a "favorites" option in the Joomla! plugin k2, I have released these modifications. Note that this is not an installable extension. Instead, these are files added to the server, and slight modifications to already existing k2 pages.

I am releasing these modifications for for free, and although it's not required, if you do make money from the project, I would appreciate a donation so I can keep my programming work alive and keep these modifications and extensions coming for free.
These files are released as-is with no guarantee to be free from flaws or completely secure. If you are worried about the code containing security holes, look over the code yourself and make the necessary changes. If you find any vulnerabilities let me know and I will be sure to fix them in the next release.


This is the first release of the project, so any suggestions or tips are VERY welcome.

If you would rather not do all the work of adding the plugin yourself, for $30 USD I will upload and make all changes directly to the server, so you don't have to worry about anything, including any wanted customization such as speical text, CSS formatting, etc. If you have any other "wants" for the project, I can implement those as well.

For further details, leave a comment in the section below, or on my in progress website, or send me an email via the address provided in the README.txt file.


Instuctions for use/installation

Download the ZIP file and extract it temporary location
http://iqandreas.isbetterthanyou.org/files/joomla/k2fave/k2fave.zip

Save the "items.php" file as:
components/com_k2/templates/default/item.php
Note that if you are using an updated version of K2 with a different "item.php" page, copy lines 27-33 into the new "item.php" page, and place them right before the line containing "<!-- K2 Plugins: K2BeforeDisplay -->"

Save the entire folder "k2fave" inside of the folder
components/com_k2/

Finally, create a new table named "jos_k2_favorites", using whatever prefix your Joomla installation currently uses. Your table should be formatted like this:
user_id int(11) PRIMARY_KEY
item_id int(11) PRIMARY_KEY

The easiest way it to open up PHPMyAdmin and add this table manually, however, it is possible to do so via SQL statements instead.


If you have any questions or would like me to do any other Joomla modifications, send me a message.


Cheers,
Andreas
http://iqandreas.blogspot.com/
http://iqandreas.isbetterthanyou.org/

Thursday, June 3, 2010

What is the point of this Blog?

I recently had to write a summary of the blog, and thought it might be a good opportunity to repost this information here and make it clear to all my thoughts and purposes of this Blog.

This blog is a collection of information focused mainly on ActionScript and Flash, with emphasis on game development, plus a little bit extra thrown in. It is aimed to be readable by beginners and not only experienced developers.

Articles are typically in one of the following categories:


The posts also strive to be unique. "If you can find it from 100 different sources on Google, there is no use in reposting what is already out there." Though, I may link to good articles, but I try to avoid writing repetitious information, clogging up the already very filled internet.


If there is any part of ActionScript you want more information on, or have an idea for a good blog post, leave a comment in the section below. A blog isn't much use if the information is irrelevant to it's readers.

Cheers,
Andreas J. Renberg
http://iqandreas.blogspot.com/


And now on to SWF Protection! :)

Monday, May 24, 2010

Calvin and Jobs

It seems like these comics have been around for a while, but considering the circumstances, I believe it to be appropriate to "rebump" them.
http://gizmodo.com/5033627/calvin-and-jobs-kick-steves-nuts

These were not made by the original Calvin and Hobbes writer Bill Watterson, but instead by MAD Magazine.

I do not hold any sort of copyright for these images at all. I wasn't satisfied with the original qualities, so I made a few quick touch ups in Gimp. Enjoy...

Calvin and Jobs - 64 Million

Calvin and Jobs - Ads

Calvin and Jobs - Bullies

Calvin and Jobs - New Clothes

Calvin and Jobs - Virtues

Calvin and Jobs - Court Practice

Calvin and Jobs - Trash

Calvin and Jobs - Pixar

June is SWF Protection and Encryption month!

Time for a themed blog month!

This June (only one week left-gasp) I will be gathering and sharing information on all things regarding SWF Protection and Encryption.


As we all know, SWFs are able to be decompiled (quite easily as well), and if you spent two months fine tuning and working on this FWA worthy site, or a really neat, new template, or perhaps a great new game, you don't want your work ripped right out from under you and replicated without your permission, control, or royalty.


If anyone has any experience with, links on, or articles written about protecting your treasured Flash work, leave a comment or send me a private message directly on this form. I'd be glad to either link to (or host if you don't have a site of your own) any information on this topic. Even information on SWF Decompiling is welcome!

Steve Jobs responds regarding Flash

"We also know first hand that Flash is the number one reason Macs crash." [...] "Perhaps Adobe should focus more on creating great HTML5 tools for the future, and less on criticizing Apple for leaving the past behind." — Steve Jobs

Finally, someone from Apple responded to war on Flash in an official statement — Mr. Steve Jobs himself! That letter can be found at http://www.apple.com/hotnews/thoughts-on-flash/

In the letter, Steve Jobs points out six main points why Flash is the enemy that has infested the Internet, and must be weeded out and slaughtered before it kills us all. Here I list the "abbreviated" version of his letter without any personal opinions or replies; I'm saving those for later.

First, there’s “Open” Adobe's products are 100% closed and proprietary. Adobe updates when THEY want to, and sets whatever prices they like. Although Apple has closed products, standards like HTML5, CSS, and JavaScript are entirely open and available to all, and therefore all work with Apple's products.

Second, there’s the “full web”. Almost all popular video on the Internet can be viewed in a newer, more modern format, H.264. Even though users cannot play flash games, there are over 50,000 applications in the App Store, and many of them are free.

Third, there’s reliability, security and performance. Symantec recently highlighted Flash for having one of the worst security records in 2009. We also know first hand that Flash is the number one reason Macs crash. We don’t want to reduce the reliability and security of our iPhones, iPods and iPads by adding Flash. In addition, Flash has not performed well on mobile devices.

Fourth, there’s battery life. Most Flash video is saved in formats which need to be decoded first; this takes up valuable battery life. On an iPhone, H.264 video can play for 10 hours until the battery dies, while most other formats only last the battery 5 hours.

Fifth, there’s Touch. Flash was designed for PCs using mice, not for touch screens using fingers. Apple’s multi-touch interface doesn’t use a mouse, and there is no concept of a rollover. Most Flash websites will need to be rewritten to support touch-based devices.

Sixth, the most important reason. Apple doesn't want any third party standing in between the developer and Apple. If Apple releases new updates, the users have to wait until the third party has updated their software to match, and are at the mercy of the third party. Although Flash is intended to be "cross-platform", Apple is very much against this thinking. Apple wants all their apps MADE FOR the iPhone or iPad, optimized with all the features available to "iProduct" developers, not available to iProducts as a "side feature".


Some of Steve Jobs arguments are a little shaky, and a lot of the time, he is pointing out a flaw in Adobe, while four fingers are pointing right back at Apple. But I'll post counter arguments and opinions on the matter another time.

This article is part 2 of 3 in the series "The Apple vs. Flash Wars"
  1. "Go screw yourself Apple" — Lee Brimelow
  2. Steve Jobs responds regarding Flash
  3. Thoughts on the Steve Jobs reply [in progress]

Sunday, May 16, 2010

The Humble Indie Bundle closed [Plus free Portal!]

See also http://iqandreas.blogspot.com/2010/05/pay-what-you-want-for-five-edit-six.html

Sadly, the Humble Indie Bundle didn't last forever, and eventually (or rather abruptly) came to a close. I wish I had found out about it sooner, and I would have been able to tell more people about it.

Tuesday, May 11, 2010

[CLOSED] Pay what you want for five [edit: six] awesome games!

The Humble Indie Bundle is now closed.
For further information, see the Wolfire Games Website, or the follow up post

The Humble Indie Bundle


When World of Goo was released on the Wii (via WiiWare) I bought it nearly immediately, and it is definitely one of my favorite games of all time (still doesn't beat Portal, sorry, but it comes close)


I found this out a bit late, but luckily, not too late.

For a limited time, you can buy the following games:

Normally it would cost $80 if you bought them directly, but now you can choose what price you want to pay for these games, weather it be one penny or the full $80. All money received will be split between the developers, and in addition, two charity organizations, Electronic Frontier Foundation and Child's Play Charity.


All games are available for all three major platforms, Windows, MAC, and Linux (yeay!)

Not only that, but since the total number of donations exceeded $1,000,000 (that's one million US Dollars) Aquaria, Gish, Lugaru, and Penumbra will be releasing the sources of their games with the GNU Public license!

But hurry, if I understand correctly, the entire deal ends in 3 days and 19 hours from the time of this writing (there's a timer on their site if you don't feel like doing the math)

For more information, see their site, or this "rap informational video"


So go out and spread the word!