Flash

From BarikWiki
Jump to: navigation, search

Introduction

This is a page about Adobe Flash, as related to games. Pedantically, there's really two parts to this: Flash, and ActionScript. One of the problems I've found with Flash, much like VB, is that the surrounding community is terrible.

Books

Tutorials

Flex SDK

The free Adobe Flex 4.6 SDK will let you compile ActionScript applications from third-party tools such as IntelliJ or FlashDevelop (just what is needed, yet another IDE).

Mostly what you'll need is the Adobe Flex Compiler, mxmlc, found in:

 C:\Program Files (x86)\Flex SDK 4.6\bin

It uses JAVA_HOME to find the appropriate JDK, which needs to be 32-bit.

The name of the compiler is a bit misleading since it can compile both MXML (.mxml) and ActionScript 3 (.as).

A Design Pattern

All DisplayObject classes have a public property stage. This comes from a poorly worded StackOverflow post and could be promoted to a blog entry.

package 
{
    import flash.display.Sprite;
    import flash.events.Event;

    public class Main extends Sprite 
    {

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
        }

    }

}

Some notes on understanding the understanding the ADDED_TO_STAGE event. Flash reference addedToStage event.

It's mainly necessary if your main Document Class is nested within another SWF, in which case the stage may not yet exist.

Flixel

  • Flixel is an open source game-making library. It's written entirely in ActionScript 3. I couldn't figure out how to make other genre's of games with this though. Flixel on GitHub.
  • Kongregate Developers.
  • For Psychology, I'm interested in a game called Multitask by IcyLime.

Embed SWF

 [Embed(source="assets.swf", symbol="HelloFlash")]
 private var HelloFlash:Class;

amfPHP

AMF is Adobe's Adobe's Action Message Format. Normally, we are referring to AMF3.

  • amfPHP is free and open source software, and an essential brick for the development of Web Applications. For a while, it appeared that this project had died, but amfPHP 2.1 was released on June 6, 2012.
  • amfPHP has a tendency to throw NetConnection.Call.BadVersion on the Flash end for just about any error. Check Troubleshooting and Debugging your Project for the most common cases. For me, it was missing a trailing "/" at the end of the URL: http://localhost/Amfphp instead of http://localhost/Amfphp/.
  • A more officially supported alternative may be Zend AMF, but I can't seem to find a good comparison of the two. It is, however, blessed by Adobe. It does not require the full Zend Framework.

I ended up using amfPHP because it's the first thing that I found. It also didn't require me to figure out the Zend Framework first. Regardless, moving to AMF at all is a good choice to simplify the Flash client code.

If even amfPHP is too much, you can go back to the classic use of URLVariables with URLLoader.

Random Numbers

Full Screen

At first glance, this appears to be deceptively simple:

stage.displayState = StageDisplayState.FULL_SCREEN;
  • The Adobe Developer Connection has some documentation on exploring full-screen mode in Flash Player.
  • Full screen requires Adobe Flash Player 9 and later.
  • Make it an Adobe Air application.
  • Compile the Flash application to an executable using Win Projector or Mac Projector. Then you'll be able to run it in the Flash Standalone Player.

Other Tidbits