3 entries in ActionScript

Ideal default Flash IDE setup for Developers

Instructions on how to set up the Flash IDE for hassle-free AS3 development

Wednesday, October 6th, 2010

Flash has a few places where you can set preferences, some of which are saved globally, some of which are saved per file. The per-file settings are a pain as they are forgotten for new files.

This post describes how to:

  • Disable file-specific global warnings, such as migration warnings for onMouseDown
  • Use File > New File > Templates to specify default settings, such as turning off Always declare stage instance

Disabling warnings

I tried the adobe-recommended handler names for about 6 months before reverting back to onMouseDown etc which isĀ  far more readable in both the code and project outline in FlashDevelop. The thing is, Adobe by default in ActionScript 3.0 you get a migration warning on every publish. Annoying!

I’ve finally found out that you can toggle these warnings using the EnabledWarnings.xml file, by simply setting the enabled attribute to false for the desired warning.

The file can be found in the following location:

Win: C:/<Install Path>/<Version>/en/Configuration/ActionScript 3.0/EnabledWarnings.xml
Mac: HD|Applications|<Version>|Configuration|ActionScript 3.0|EnabledWarnings.xml

There are about 30 warnings in all, covering possible mistakes, coding style, and AS2 to AS3 code migration.

Setting default file / file preference settings

Did you know that it’s possible to create your own file templates, complete with settings found in:

File > Publish Settings... > Flash > ActionScript 3.0 Settings...

This covers:

  • Export classes in frame n
  • Strict mode
  • Warnings mode
  • Automatically declare stage instances

If you simply create a folder called Templates in your user Configuration folder, then a named subfolder, and save an .fla file in there, it appears in the File > New > Templates list.

Not only this, but:

  • The template group shows on the Flash startup screen
  • File > New remembers your choice, so automatically pre-selects the last-used template
  • The File > New > Templates tab, Category and Template choice is remembered between sessions

I now have a folder called Templates/Development, and a few different .fla files in there, all with the settings I mentioned above.

You could easily add some files with default timeline testing code, a few symbols, fonts, etc, as well.

Comment Headings

Enable easy navigation of code using GIANT comments made up of block characters

Friday, November 14th, 2008

When navigating through large classes, it can be a real pain to find certain bits of code if you don’t have a good IDE. As I often work in Flash IDE and DreamWeaver IDE, I have to rely on comment blocks here and there, with lots of – - – - – - – - – - delimiters, etc. which is an OK start.

However, I saw the PaperVision 3D classes had moved on a step from this, and had rather nice blocks at the top of each script with their logo, made out of characters. Why not extend this idea and actually build a small Flash application to let me build dirty-great big words that I can use in my scripts for navigation purposes?

Comment Headings

Edit the text in the left-hand text box to update the text in the right, then click Copy Text to copy the headings directly to the clipboard so you can paste to your IDE.

Note:Comment Headings works only with mono-spaced fonts! Mac users – you might have to experiment to find the best one.

Firefox 3 users: due to FF3’s mono-spaced font tracking, the characters below may not display correctly, but rest-assured that in the final downloadable utility, and your IDE, the headings will appear just fine.

Demonstration

To demonstrate the differences between a comment-headered file and a normal file, compare the following two files, and see how much easier it is to skim through the one with larger comment headings.

Options

The following options are available to customize your headings:

  • Font – Choose from 12 available fonts of varying sizes and styles
  • Block – Various characters to create the block comments themselves
  • Comment – Various leading-comment styles to suit different languages
  • Delimiter – Various delimiter characters for the

Presets

If you change programming languages / tasks regularly, you can save time by storing oft-used combinations as presets. For example:

  • Input presets – Your most common heading text combinations
  • Output presets – Your most common settings for each language / editor / etc

Presets can be quickly called up by selecting them from the dropdown lists, which automatically updates related dropdowns as well as the output text.

Both Input Templates and Output Settings are stored in an editable text file, presets.xml, which is well-commented, allowing you to add or delete settings to suit your workflow.

To have the utility start with your chosen presets, for example having the MaxScript headings always open, just ensure its entry is first in the input list.

Customization

Once tinkering in the presets file, the following elements are configurable:

  • Comments – Choose the leading comments (//, –, etc) according to programming language
  • Blocks – Choose which characters you want to physically build the words from
  • Delimiters – Choose which characters you want to use to delineate each comment block
  • Fonts – Choose from any of 12 fonts to be available

3dsmax users

In order to display the full-block style of comments, you will need to set up the SCiTE editor to use the extended Unicode character set, and display code by default in a fixed width font. To do so, you will need to add the following lines to your User Preferences file:

code.page = 65001
character.set = 204
font.base = font:Courier New,size:10
font.comment = font:Courier New,size:9

Obviously this is only applicable if you are using 3dsmax 2008 or above.

Download

Flash “PHPLoadVars” class

Natively send complex / multidimensional variables from Flash to PHP with this extended LoadVars class

Thursday, February 28th, 2008

I was pitching in on a forum thread Send an object to a php script the other day and some chap wanted to send complex objects to PHP using LoadVars. “Can’t be done!” was the reply.

Oh yeah? Well if PHP can deserialize array variables from HTML forms, I don’t see why we can’t do the same with Flash.

Well it took about 15 minutes to work up a rough proof-of-concept that worked for GETs only, but it got me thinking to do something nice with:

  • a proper class
  • that works with POST (so you can send BIG objects!)
  • and has a recursive serialization routine (so you just give it any nested data-structure, and it chews through all of it)

PHPLoadVars (also works with Ruby)

Well it couldn’t be simpler, really. Just create a new PHPLoadVars object, ask it to serialize your data, and send:

var data :Object      = {data:[1,2,{sub_object:{name:'Dave',age:33,gender:'male'}},3,4,5]}
var lv	 :LoadVars    = new PHPLoadVars();
lv.serialize(data)
lv.send('process.php')

Then PHP receives the complex variables natively like so (a quick print_r($_POST); shows the results):

Array
(
    [data] => Array
        (
            [0] => 1
            [1] => 2
            [2] => Array
                (
                    [sub_object] => Array
                        (
                            [gender] => male
                            [age] => 33
                            [name] => Dave
                        )

                )

            [3] => 3
            [4] => 4
            [5] => 5
        )

)

Just to be absolutely clear – this result isn’t manually de-serialized, or run through any processing routines – PHP automatically reads in data serialized using square brackets (which is how things were serialized in Flash) as numeric or associative arrays, so your data is literally ready to go as soon as the headers have been processed!

And you can make your data-structure as deep as you like…

Could it be any easier!? No. It couldn’t! Not even XML is this easy!

Download

Download the class file, sample .fla, and a basic PHP file to echo the variables to screen.

LoadPHPVars.zip