FlashDevelop – Fixing getDefinitionByName ReferenceError: Error #1065

This is a pretty common error to come across when you first start using FD but I thought it might help someone. Basically when you try to use a class that you have included in your SWC (such as a Bitmap or Sound with a linkage tag) using getDefinitionByName(“MyClassName”) as Class, the compiler throws an error message saying it can’t find them – variable not defined etc. Even though you think that those classes are in your SWC and therefore in your project, the compiler still doesn’t know about them so you need to tell it to include them when compiling.

There are several ways to achieve this. The most basic way is just to reference them in your code. Even a trace(MyClass) message will work or defining a dummy variable like var foo:MyClass; . The problem with this method is that you have to write a lot of dummy code to include a bunch of classes.

The correct way to do it is to actually add the SWC that the class is in to the project via Project Properties > Compiler Options > SWC Include Libraries list. This way all classes in the swc you specify are compiled. However there problem with this method is that this it includes ALL the classes in that SWC you define.

If like me you are using different classes as you develop and you don’t want to include a whole bunch of massive images the best way I have found is to include a static array with a list of the classes you want to include. So for example if I want to include a bunch of images in my SWC and call them using a string via getDefinitionByName(“MyClassName”) as Class I can force them to be included using:

private const includeClasses:Array = [MoonBMP, LavaBMP, CracksBMP];

and then later I can grab them using a string:

var ImageClass:Class = getDefinitionByName("MoonBMP") as Class;
var img:Bitmap = new ImageClass() as Bitmap;


TouchOSC & Logic Pro (without Osculator)

I recently downloaded TouchOSC for my iPhone and set it up to control Logic Pro. As of the latest version of Logic Pro 9.1.2 you can use TouchOSC without even needing to install Osculator. Apparently you just install and it works out of the box. BUT – if it doesn’t work for you as smoothly as suggested (like I experienced) then it is a bit hard to work out what to fix when going through the myriad of online tutorials on setting it up as most of them are out of date and tell you to install Osculator and then configure CC numbers etc. Boring.

So for a far easier setup:

  1. Purchase and install TouchOSC on your iPhone.
  2. Make sure your computer and iPhone are on the same network.
  3. Launch TouchOSC on your iPhone and go to the network tab. Find your computer. TouchOSC should set up the IP Address and Host name. For now enter 7000 for Port (outgoing) and 9000 for Port (incoming).
  4. Now launch Logic Pro. It should say something like: “Logic Pro has detected a new OSC device named “Your iPhone”, which is supported but the control surface plug-in “TouchOSC”.
  5. Click Add. Logic will automatically setup your iPhone as a controller along with an icon in the Controller Setup dialog. If not open it and check by going Preferences > Control Surfaces > Setup. You should see it there as per the image in this post.
  6. NOW FOR THE IMPORTANT BIT: Take note of the Output Port and Input port. These should be the same as those you setup in TouchOSC on your iPhone but in reverse – this is the key. So if on your phone in TouchOSC you had Port (outgoing) as 7000 then in Logic the Input Port needs to be set to 7000 also. The same for the Port (incoming) and Output port number.
  7. Now in TouchOSC on your phone go to Layout and select LogicTouch.
  8. Have a fiddle with the controls and voila – you should see some action!

Brilliant app but sadly only one default layout (LogicTouch) that works with Logic as far as I can tell. With 3 different panes to control Logic though – its pretty damn good for $4.99 US. One day I will make some custom layouts but for now Im happy having a handy transport controller.

I hope this helps someone out one day as the tutorials on the web are all pretty advanced if you just want to get up and running quickly.

As a follow up I found this article from the author of TouchOSC that goes into a bit of detail about this.

iPhone simulator launches but only shows black

I was working on upgrading a clients app today to use Apple’s retina display when I ran into this problem that had me stumped for a couple of hours. The application compiled OK but when it installed and launched in the simulator after showing the default.png splash image it went completely black. Huh? The app apparently had worked fine on the original developers computer and after fixing a few compiler warnings that I thought may be the problem I stumbled upon this thread and thankfully the solution.

Apparently this can happen after installing some iOS 3.0 and 4.0 updates. Some of these major updates seem to change the MainWindow.xib file in your project so that the checkbox in Interface Builder > Attributes marked “Visible at launch” is de-selected. Heaven knows why, but I turned it back on and voila it all worked. I thought posting this may help someone else someday a few hours of pain chasing your tail. If anyone knows whether Apple did this for a good reason please post a reply – I would love to know why!?

Tinting the colour of a MovieClip

Here’s an old snippet that I use quite often to set the tint of a MovieClip. It’s useful if you put all of these sorts of utilities in a class and access them via public static methods. So in a utility class called MovieClipUtils.as you could call:
MovieClipUtils.tint(myMovieClip, 0xff0000, 0.5);

//Color an MC with option amount  (0-1)
public static function tint(target:MovieClip, color:Number, amount:Number = 1):void
//create a new Color object
var c:Color=new Color();
//set the color of the tint and set the multiplier
c.setTint(color, amount);
//apply the tint to the colorTransform property of the desired MovieClip/DisplayObject
target.transform.colorTransform = c; //mc is a MovieClip

WordPress iPhone app – incorrect username or password

After trying to setup the WordPress iPhone app and running into “incorrect username or password” errors, I finally sorted it out. It looks like there are quite a few other people with the same problem so I thought I would post it up. For the record I have a self-host setup.

Firstly – go online on your computer (not your iPhone!) and make sure in your wordpress dashboard you have XML-RPC turned on. It’s located in Settings>Writing>Remote Publishing. Turn it off and on again if its already on (I tried that and it seemed to work!)

Then back on your iPhone – try entering your username and password again. You might as I experienced then get past the login screen but now be met with a “Communication Error – Bad user name or password” error! No fear – patience is needed here!

Now try deleting the blank blog that has been created by clicking on the top right edit button. Then restart the app and try entering all your login details again. It should now work. (fingers crossed)

No guarantees as it worked for me after a few attempts but that’s not to say it will for you!

Opening Safari from your iPhone app

A very simple task I know but when you are starting out its nice to find it on a blog!
Somewhat similar to using URLRequest in AS3 really.
NSString *urlString = @”http://www.mywebsite.com”;
NSURL *url = [[NSURL alloc] initWithString: urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

[webView loadRequest:request];//UIWebView instance named webView declared earlier
[request release];
[url release];

Common XML character codes

Sometime when using XML data in Flash/FLex you need to use special characters to save your XML breaking and I always forget what they are! So to save me a google search or two here they are again:

//XML character codes

& Ampersand &
> greater-than >
< less-than &lt;
‘ apostrophe &apos;
“ quote &quot;

Compiling multiple SWFs from FlashDevelop

I use FlashDevelop for Actionscripting and sometimes I need to export multiple SWFs from a single project. You just need to use the mxmlc compiler tags in your AS class file (make sure the class extends a displayObject) and use Flash Tools > Build Current File.

Here is an example of the mxmlc with a bunch of settings that are fairly self-explanatory. For multiple SWC files just define the -l lib tag again. To see a list of all the tags use the @mxmlc -help tag.

* @mxmlc -help
* @mxmlc -o bin/create_banner.swf -debug=true -default-size 1024 768 -default-background-color 0x000000 -use-network=false -l lib/login_all.swc -l lib/customFont.swc -l lib/CreateABannerAssets.swc -l lib/aether.swc -source-path=Z:\AS3_classes\