PROBLEM:

Unloading content (ie external swfs) in AS3 is difficult, if not impossible.

SOLUTION:

My pal Martin Sieg at marblemedia threw me to an article by Grant Skinner - Failure to Unload: Flash Player 9’s Dirty Secret - where the author discusses a player bug that prevents content unloading. The problem impacts gallery-style projects, and sites that use embedded advertising.

Apparently there is no real solution, but Skinner is campaigning for a sandbox mode in Flash Player 10 where you can rope off your embedded content, and prevent it from getting its hooks into your main movie.

A noble effort, Grant. In other news, aid group World Vision announced today that rising food prices have created a shortfall that will prevent them from feeding millions of people.

AS3 and the Scoop on OOP

April 22nd, 2008

i was only trying to promote Flex Camp 2 when i launched into a long lament over Macromedia/Adobe’s chosen design path for their Flash software. Industry pal Jim McGinley (of TOJam 3 fame) shared his insights:

Visual Basic programmers had an inferiority complex. Despite the fact VB programmers were building business applications in record speed, VB programmers knew in their hearts they weren’t working with a ‘real’ programming language. Microsoft responded to this, and kept adding C++ features to the VB language, eventually releasing VB.Net. VB.Net is a REAL programming language with ALL of the features and capabilities found in C#. It takes twice as long to build business applications, and programmers love it!

Flash is following this classic pattern. Flex proves that Flash is becoming a real programming language. Eventually, Flash will wind up being C++ (Threads, OpenGL, ADO database layer), forgetting what made Flash great to begin with. Animations produced in the Flash design environment will be replaced by Actionscript code that does the same thing. It will take twice as long to build things in flash, and programmers will love it!

The Primordial Days of Flash

If you’re a college student who’s just been saddled with a Flash course, or you’re keen on creating a little interactive piece for your website, you may now be quaking in your boots at the prospect of wrapping your brain tentacles around Actionscript 3. It may surprise you to learn that Flash (née Futuresplash) was once a great little vector animation tool for artists. It developed a scripting language to help with starting and stopping animations, and supported the occasional button - a button to start and stop an animations, most likely.

i got into the game at Flash version 4, where all the scripts were in a tidy little box. You couldn’t actually type any code. You could only drag and drop the script you wanted into your scripting window, and fill in the blanks. For example, you could drag the playhead control script “gotoAndPlay();” to the scripting window, and fill in a frame number or a frame label to make it read “gotoAndPlay(”act4″);

i loved everything that Flash had to offer except its script controls. Although i never had any success all through my life with programming, i didn’t like coding in Flash 4. i could actually make a whole game by myself, which was great, but it felt like throwing pottery with boxing gloves on.

The upgrade to Flash 5 blew my mind, and marked the first step in my path toward the Dark Side. For the first time, i was able to type my own code. No training wheels, no boxing gloves - all i got was a big blank window. “The power,” i cackled - “the ABSOLUTE POWAHH!!!”

But with great power comes great responsibility (Luke said that long before Uncle Ben, by the bye), and with the freedom to type your own code came the burden of learning the Actionscript language and syntax inside and out - otherwise you’d get a famously cryptic compile-time error. To quote a certain colony of ants released into zero-gravity, “Freedom! Horrible freedom!”

New Designer Features Are Coming, Right?

With each version of Flash that the Macromedia team released, those of us from the design end of the gene pool (AKA the shallow end) anxiously awaited the newest art and animation features.

Would Flash be able to handle text along a path, like Illustrator and Photoshop?

What about curved gradients?

How about a swirl tool? Or the ability to freeform/perspective distort a movieclip?

What about inverse kinematics in Flash? Hell - what about forward kinematics?

Could you make it so that we can select a bunch of movieclips at the same time and swap them out all at once, instead of swapping every symbol instance one by one?

What about range-selecting a bunch of instances across your timeline and giving them all the same instance name with one click, instead of having to individually name all your instances in case you forgot to name that first instance before you went ahead and animated it across 300 frames?

How about time stretching? Can Flash time-stretch our animations in case we have to change the frame rate in the middle of a project?

Text Along a Path in Illustrator

Illustrator flagrantly mocks me.

No? So what do we designers get, then? Photoshop-style filters? Ok … alright. So after eight years of waiting, you’re giving us Photoshop-style filters like blur and drop shadow?

Hey uh … hey Adobe: 1997 called. THEY WANT THEIR CUTTING-EDGE DESIGN FEATURES BACK.

Toon Boom

Back when i was working at Corus Entertainment, a media conglomorate with several national stations boasting millions of viewers, i was trying to make a case for building the entire YTV.com site in Flash. We got pretty close, but the idea was eventually tossed when a new concept called “Search Engine Optimization” reminded everyone of Flash content’s depressing opacity. Still, i contacted Macromedia many times asking for support and advice, sharing site links with them to show off our department’s work and generally trying to bring on the love, but they weren’t having it.

Corus animation studio Nelvana seemed to have a similar problem. They animated a few different shows entirely in Flash, including Jacob Two-Two, which must have been a nightmare without any sort of linkage feature to sew characters’ limbs together. Plucky young upstart Toon Boom Studio listened to them and began building the features they requested, which included parallax background scrolling and a Maya-style hierarchy for all the kibbles n’ bits within a scene. Nelvana phased out Flash after a couple of years, and even bought Toon Boom to ensure that the software would continue to develop with animation production in mind.

In the end, the squeaky wheel gets the grease. And in the case of Flash, the nerds bemoaning improper coding practices won out; its scripting language was developed and refined until today’s Actionscript resembles many C-based languages out there. And aside from the occasional blur effect, the art and animation tools remain almost identical to the version i started using eight years ago in 2000.

Quick - Code this in Ten Minutes!

The fallout that i’m faced with is this: AS3 is not fast. Sure, it may be fast to the user, but that’s because the Flash virtual machine has offloaded the burden of figuring out a lot of junk onto the programmer. The result is that projects that i could quickly bang out in a week now take at least twice as long to build.

It’s not because i don’t know Actionscript 3 like i know Actionscript 2. i spent two months, eight hours a day, retraining myself to use AS3, and here’s my verdict: it’s simply slower. The fact that it forces an OOP (Object Oriented Programming) methodology on me means that instead of this:

var myWidget:Object = {};

i have to type this:

namespace ohGod.makeItStop.whattaPainInTheAss
{
import flash.whoCares.thisTakesTooLong.SomeNonsense;

public class Widget extends SomeNonsense
{
public function Widget()
{

}//constructor
}//class
}//namespace

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*//

// Meanwhile, back at the ranch:
var myWidget:Widget = new Widget();

Count up those keystrokes. That’s a whole lot more typing.

Beyond that, there’s a whole lot more thinking and planning involved. You should no longer say this:

var myNum:Number;

… because the Flash Player wants to know what kind of number you need. Is it going to be signed or unsigned? With a decimal or no decimal? What’s the highest amount that number will ever reach?

You know what? Sometimes i have no idea. i don’t know, Flash. You tell me. i don’t want to have to go traipsing through additional manuals looking up the limits of your number datatypes because i don’t have time.

Many of the projects that we build at Untold Entertainment have a programming element of one to two weeks, max. It’s actually a competetive edge that we’re able to code so rapidly. So while OOP and strong-typing and proper class architecture are all nice things to have, so is a finished project.

Enemy Mine

Programmers just LOVE OOP because, theoretically, you can create modular, portable code that you can reuse in project after project. This is all true in the application world, where buttons all act in similar ways and windows all do the same nonsense from app to app. In fact, one could argue that applications are better when they adhere to a shared sense of design. i want to know in every app that when i click that the little underscore button on a window will minimize the window, instead of adjusting the application’s volume and installing a new graphics card driver for example.

Casual web games are a different story altogether. Some elements are handy to reuse - particularly a high score module, a timer, a Button class, a Sound Effects controller, and an on-screen Prompt or Dialogue routine. But OTHER elements, like the fire-breating fish who revolves around the central pivot point of the planet graphic shooting fireballs at a 37 degree angle and reacting to the player’s crossbow shots by randomly jumping or rolling - THAT kind of thing is a different story altogether.

Yes, you can build the fire-breathing fish using OOP methodology. You’d probably start really generally, maybe with a Character class. “Enemy” extends “Character” and inherits, maybe, a hitPoints member, and perhaps it has its own fire() and dodge() methods. That all sounds great - straight out of an OOP text book.

But then your next game has an evil squirrel enemy that walks orthogonally through an isometric environment, picking up any atomic acorns he finds and intermittently firing up a deadly force field.

Again, you can revisit your enemy class and tweak it so that your new enemy works, but those two Enemy cases are so different. There’s no way your original Enemy class is going to suit this new enemy character, because you simply can’t see into the future. You can’t foresee all your Enemy needs. And when “the future” is only two weeks away and you have to slam together the code for your current project, you’re not likely to futz around building the perfect reusable Enemy class all week.

Screw OOP

So screw OOP. Yeah - i said it. Object Oriented Programming is fine for organizing code, and certain things can be reused. But by and large, if you’re the type of user who doesn’t have a nine-month Flash project mapped out on a Gantt chart and hung on a wall so that you can interface with the twenty other people on the project and negotiate dependencies, then Adobe and Macromedia have totally screwed you - first by requiring you to adopt a methodology that’s only going to slow you down, and second by failing to deliver design features that actually would speed up production, such as those i mentioned earlier.

But hey - at least we’ve got blur. Perhaps in eight more years, the Adobe Flash gods will smile on us and give us lens flare.

Lens Flare

PROBLEM:

When i test my movie, it doesn’t respond to all of the keyboard key presses. Only some keys register.

OR

Certain text characters do not show up in my Input text field when i type them, even though my font outlines are embedded.

SOLUTION:

In the Test Movie window (NOT the Flash IDE window), click on Control>Disable Keyboard Shortcuts.

This problem is not an AS3 problem. It’s a Flash thing, and it gets me every single time i upgrade to a new version of the software. Since i only upgrade every few years, i always forget about this and i have to scour the Internetz like a dope looking for the solution. Perhaps you can relate? :)

It would be wiser for Adobe to disable keyboard shortcuts by default. If you have the time and energy to do it, and if this problem wasted enough of your time, consider firing them an email or putting the suggestion on their Wishlist.

PROBLEM:

MovieClip._xscale (or MovieClip.xscale) does not light up as a recognized property in AS3. It’s not even listed as a property of the MovieClip class in the documentation. What gives?

SOLUTION:

_xscale and _yscale properties have been replaced by scaleX and scaleY, which are both properties of the DisplayObject class. MovieClip (eventually) extends DisplayObject and inherits these properties.

The second snag is that scaleX and scaleY percentages are now divided by 100. Whereas before, MovieClip._xscale = 100 displayed the clip at its native width, MovieClip.scaleX = 1.0 is the new hotness.

MovieClip._xscale = 100; // Displays an object at its full width in Actionscript 2
MovieClip.scaleX = 1.0; // Displays an object at its full width in Actionscript 3

Take care when porting AS2 files to AS3.

AS3 Pitfalls - Error #1009

March 18th, 2008

PROBLEM:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

SOLUTION:

i don’t know.

Error #1009 seems to be catch-all error that Flash throws whenever you reference something that doesn’t “exist”, or hasn’t been loaded into memory. A quick Google search shows that the error spans both Flash and Flex, and can crop up in a number of hair-pulling situations. Here’s the recipe i followed to produce my very own Error #1009 while building a multi-user chat application with ElectroServer 4:

1. i create a document class called Main.as and linked to it from the Flash IDE.

2. i set up my Flash swf with two frames. Frame 1 has a Login widget.

ElectroServer Simplechat Frame 1

Frame 1. Nothing fancy.

3. Frame 2 has a Chat window, a Send button, and a List component labelled “Users”. The List component’s instance name was userListClip.

ElectroServer Simplechat Frame 2

Frame 2. Note the “Users” List component on the right.

4. Once the player logs in, i tell the swf to gotoAndStop(2);

5. Now i try to populate my List component, userListClip, with the user names of the people in the chat. No good - dreaded Error #1009 rears its ugly head.

After a bit of research, i read somewhere that my code cannot manipulate objects that i’ve placed on the stage further along the timeline, because those objects have to “exist” at the moment my code is compiled. Huh. Really?

CRUMMY SOLUTION #1 - Alpha/Siberia

One solution is to have that troublesome userListClip instance exist on Frame 1, but drag it off the stage or set it to alpha 0%. This is a very clunky workaround and i don’t like it.

CRUMMY SOLUTION #2 - Clunky Listener

Someone in a Flash user group suggested i register a listener with Event.ADDED. Here’s how that goes:

addListnener(Event.ADDED, onAdded);
private function onAdded(e:Event):void
{
     var clipName:String = e.target.name;
     switch (clipName)
     {
           case "userListClip":
                    populateUserList();
                    break;
           default:
                    break;
     }
}//onAdded()

No WAY. That can’t possibly be a respectable solution. Let’s just say it’s “inelegant” and leave it at that. And for some strange reason, my userListClip instance doesn’t ever show up in this function. What gives? Do components not trigger Event.ADDED?

CRUMMY SOLUTION #3 - The Hands-Off Approach

Another solution, obviously, is to build the userListClip List component out of code. i’m resistant to that because i’m one of these hands-on designer types who likes to see what he’s building. i don’t like the fact that my whole design exists in this ethereal, unimaginable codespace that exists only in my darkest desires until compile time.

Not only that, but pure code solutions become a pain to troubleshoot months down the road. i’d much rather see something on the stage and click on it to see its instance name, than to pour through pages and pages of code trying to learn the programmer’s naming convention (even if the programmer is me. i have a lousy memory).

THE BEST SOLUTION

If you’ve generated Error #1009 and have lived to tell about it, please post your solution!

We’ve been linked to by a fellow agency called Airtight Interactive on the subject of altering cross-domain bitmap data in Flash. They mention the server-side proxy work-around that i’ve used, calling it “prohibitive” for large-scale apps. That was the concern i raised when a casual games publisher approached me to ditribute Jigsaw! across its extremely high-traffic game portals.

Untold Entertainment’s advantage is that we do not bear the bandwidth costs that the jigsaw game’s Custom image feature may bring down like so much Biblical wrath. There are ways to mitigate the cost, which i’ll discuss after posting the solution.

(Click to read about Adobe’s rationale for preventing cross-domain image manipulation in Flash.)

PROBLEM:

Images loaded into a Flash swf from another domain (ie www.notMyOwnSite.com), won’t respond to BitmapData methods like draw().

SOLUTION:

Flash needs to see that the image comes from your own domain. To pull this off, you set up a server-side script and pass the image url to it. The script loads the image to your domain, and returns that image to Flash. Since the image comes from your domain now, you can mess around with it all you like.

The script i use is written in PHP. Here it is, at its most basic:

<?php
 
$mimetype = $_GET['mimetype'];
$file = $_GET['file'];
 
header("Content-Type: $mimetype");
readfile($file);
?>

There are some clear problems with this approach:

1. Since your server has to load the image, you carry the bandwidth cost for trafficking that image. i consider this the cost of doing business. If you want to offer a cool feature like custom player-created jigsaw puzzles, you have to pony up the cash.

And then, logically:

2. Some malicious user could set up a script to repeatedly pass enormous images through your server every second of every day, putting you in the poorhouse, or forcing your provider to shut your site down. This is best handled by adding limits to the script. Prevent users from loading images above a certain filesize, and limit the number of script calls per user.

Sheet Happened!

January 21st, 2008

Sheet Happened!

i’m not above profiling the mistakes i make as i bring my new business to its feet. It’s possible some of you are budding entrepreneurs planning to follow the same path. So here’s my hot entrepreneurial tip of the day: DO YOUR RESEARCH.

Two months ago, i hunkered down to learn Actionscript 3, and i needed a project to practice on. i chose Sheet Happens!, a hobbyist sheet music app that allows you to transpose the chords in a Notepad-like environment. A good long while into production, i thought “Hey … i wonder if there’s anything like this on the market?”

As it turns out, there is one teensy tiny product out there called iChords. It doesn’t do exactly the same thing as Sheet Happens!. You can actually feed it an MP3, and iChords will dynamically “listen” to the song and display the chords as the song plays.

iChords

iChords: 8000% better than Sheet Happens!

If Sheet Happens! is a car, iChords is a spaceship that transforms into a robot that eats cars for a mid-day snack.

To add insult to injury, iChords ships with D’Accord Chords Notepad, which looks exactly like Windows Notepad, with two extra menu additions: Transpose Up, and Transpose Down. That’s right - not only does iChords have a far better feature set than Sheet Happens!, it actually replicates the entire Sheet Happens! feature set as a footnote.

Sheet Happens! was also an excuse to launch an Adobe Integrated Runtime (AIR) app, which integrates Flash with the user’s desktop. This brings up a second, equally excellent tip for small business owners: start with what you know. Untold Entertainment Inc.’s bread and butter is making Flash games, deployed to the browser. i haven’t heard a lot of demand for AIR apps, but i thought we could be on the bleeding edge. The trouble with that is after two months, Untold Entertainment’s games library stays the same size, and we have this music software anomaly that probably won’t interest our core clients.

All told, developing Sheet Happens! wasn’t a complete waste of time. i have a much better handle on AS3 now, and will be periodically posting SNAFUs and programming tricks to help anyone else transitioning from AS2 to AS3.

i recently had to step back into old Actionscript 2 code, and it was like sliding my foot into a well-worn, mildewy sports sock where the sweat dried and mummified the sock into the shape of my foot. i was amazed at how quickly and easily i could program in AS2. i almost closed my eyes as i typed, and the code just flowed out of me. Contrast that with AS3, where i have to pay careful consideration to each line, and every time i compile i get a truckload of errors.

i worry that delving into my old code will undo all of the AS3 training i’ve done. i need to limit my exposure, like an 8-year old sneaking tiny glimpses at the sun, wondering how long it’ll be before he goes blind.

iChords can be purchased for an amazingly low price at finer download sites everywhere. Sheet Happens! can not.

PROBLEM:

TextField.setSelection doesn’t select any text!

SOLUTION:

Set the stage.focus property to your TextField object.

// Selects all the text in myTextField:
myTextField.selectable = true;
myTextField.stage.focus = myTextField;
myTextField.setSelection(0, myTextField.text.length);

Other search terms:
setSelection not working
setSelection not responding
setSelection broken
setSelection bug
setSelection buggy
DOUBLE_CLICK problem

PROBLEM:

MouseEvent.DOUBLE_CLICK doesn’t work!

SOLUTION:

Set the object’s doubleClickEnabled flag to true

myBtn.doubleClickEnabled = true;
myBtn.addEventListener(MouseEvent.DOUBLE_CLICK, double_click);

Other search terms:
DOUBLE_CLICK not working
DOUBLE_CLICK not responding
DOUBLE_CLICK broken
DOUBLE_CLICK bug
DOUBLE_CLICK buggy
DOUBLE_CLICK problem

Proudly powered by WordPress. Theme developed with WordPress Theme Generator by Party Industries & Hogwarts Digital.
Copyright © untoldentertainment.com. All rights reserved.