

Falcon - Simple Connection to Server Scripts with Adobe Flash

http://falconflash.wordpress.com


BACKGROUND

Adobe has rightly split functionality into many smaller classes.  For instance the classes to connect to a server and receive data include: URLVariables, URLRequest, URLRequestMethod, URLLoader and URLLoaderDataFormat.  This allows these classes to be used in a number of different ways.  But it also means more steps for common functionality.  Falcon wraps these classes up into one simple class for server access.

FALCON

Falcon can be used to load variables, text, binary and XML data from files external to Flash.  An example would be an XML file to configure the look of a feature or specify which pictures to show.  This example would be handy for designers who want to give their clients some personalization but do not want to make server scripts, etc.

Probably the most common usage for Falcon is accessing a server script such as PHP to get variables that usually would come from a Database like MySQL.  Falcon allows you to send variables to the server script as well. Please see the example files for how to make all this happen.

A second class called FalconProvider works just like Falcon but also provides a DataProvider property that will save you a little time when it comes to sending sequential data to Flash to go in Lists or DataGrids for instance. FalconProvider requires that you have a component in the FLA that uses a DataProvider such as a DataGrid, ComboBox, List, etc.

--------------
For more specific aspects of Falcon please see the included examples
The section below is for those who have not used classes or not used classes often
--------------

CLASSES IN GENERAL

A class is a block of code that lets you do something like make an alert window show up or make monsters appear.  All the components like CheckBox, Button, etc. are classes and indeed everything in Flash is broken up into classes.  Usually, you can make things over and over again and these things are called Objects.  ActionScript is said to be Object Oriented - like most other current programming languages.

Class files end with a .as extension and are often collected in folders.  When a folder holds classes it is called a package.  You should also note that when you publish the FLA file, the classes automatically get included in the swf.

DOCUMENT CLASS

Each FLA has what is called a document class.  You can specify the document class in the properties panel when you click on the stage.  The document class should NOT be Falcon.  But your feature may have a document class.  See the provided FLA's for examples.  The document class gets run automatically when the swf starts.  Note that in each case the document class is kept in the falcon folder (package) and it gets called with that package at the start for instance falcon.FalconText.  You do not have to put the document class in a package but often projects have many supporting classes and it is tidy to keep them in a folder.

Please see http://www.flickr.com/photos/danzen/1382459629/ at full size for visual reference.

USING A CLASS - IN ONE PROJECT

To use a class, Flash has to know where it is.  You can put the class in the same directory as the FLA such as the Falcon.as class provided.  In which case the package designation in the first line of the class code is package {.  Then you can use the code without having to import the class.  This is not optimal if you want to use the class in more than one feature because you would have to copy the class into the next feature's folder, etc.  But it is the simplest way and is okay for one time usage.

There is an FLA called FalconTimeLine.fla that does not have a specified document class.  This file calls Falcon from a timeline script.  Because Falcon.as is in the same folder we do not have to import the class, we can just use it.  This represents the simplest way but most developers these days do not code on the timeline anymore.

The other FLA examples all have a document class that is stored in the falcon folder (package).  If you store your document class in a package and you are using Falcon once then you could put Falcon in the same folder as your document class.  In which case, you do not need to import Falcon into your document class.  We have put a Falcon.as in the falcon package and note that its package designation is package falcon {.  Also note that Flash will check the folder the FLA is in first for a matching class so the Falcon.as in the falcon folder is not used. It would be used if the Falcon.as in the directory of the FLA is deleted.

USING A CLASS - OVER MULTIPLE PROJECTS

A long-term solution is to store your custom classes in a folder - perhaps called classes in some folder not specific to any project.  Your classes folder could include subfolders like interfaces, utilities, effects, etc. and then various classes could be stored in there.  So you could make a classes/utilities/ folder and put the Falcon.as in that folder.  (Often classes are distributed in folders (packages) that match the reverse order of the distributers domain name.  com.danzen.falcon, etc. and it is up to you if you want to keep that order.)

If you establish a classes folder then you will have to import the class from that folder into your current FLA.  You will want to add your classes folder to what is called the classpath so that you do not have to specify all the folders to your classes folder everytime you import the class.

The classpath can be set in Flash.  Open an FLA and select from the top menu Edit > Preferences > ActionScript > ActionScript 3 Settings and you will see a window with the classpaths listed.  Just add c:/myfolders/myotherfolders/classes/ to your classpaths.

If you put Falcon.as in your classes/utilities/ folder and you have added c:/myfolders/myotherfolders/classes/ to your class path then you will want to change the package designation on the first line of the Falcon.as code to be package utilites {.  And you would import the class at the top of your document class using:

import utilities.Falcon;

You would be able to do that from any of your files so it is usually worth the effort and it will make you feel much more organized.  It becomes simple once you get the hang of it!



























Falcon.as is the class that we are providing and that does the work.  You will note that Falcon is provided in two places.  In the same folder as this readme.txt and in the falcon folder.  When classes are held in a folder, the folder is called a package.  You will see that there are a number of classes

For designers, there is often a hurdle when it comes to knowing how get the class working and in this section we will hope to help.

in the falcon package (folder) and is The other classes are examples of how to use the Falcon class.  The code in the examples will be what you put into your feature.  You will need to understand the code in the examples - you do not really need to know what is going on inside the Falcon class.  

For you to be able to use the code, Flash has to know where it is with respect to your feature.  This is a little tricky because there are a few arrangements.  There is a short term easy solution and a long term more flexible solution.

A. Short Term Solution:
























