VerifyError: Error #1024: Stack underflow occurred

Wow – I’d never seen this one before. So I’m putting up here to remind me what to look for if I ever see it again!

Basically I had a SWF that ran fine in debug build mode in FlashDevelop but if I set it to compile as a release version this error soon appeared.
On closer inspection it turns out that in the line that was crashing (which was hard to find in itself) I was using a variable named “h” in a loop. The clue was that this var h:DisplayObject was coloured green by the compiler and therfore most likely an internal variable in a parent class. All I did was change it for something a bit more descriptive and unique and it all compiled. So lessons learnt – listen to the code highlighting hints and don’t be lazy and use short variable names!

Phew.

A bit of searching also suggested that it may be a Flex 4.1 SDK related bug as I would have assumed that the compiler would give you a warning even when compiling a debug version. If anyone can shine any more light on this one please post.

William Hill Careers Papervision

Baldscone was involved in coding the 3D Flash component of this website. Making extensive use of Papervision 3D and XML to create a custom coded navigate-able panorama, it allows the user to navigate the 3D betting room. Content is all provided dynamically along with jobs ticker. Video, images and text are used in textures and are updated via XML. Hotspots are created using an authoring tool for generating 3D areas and coordinates.

Visit it at: http://careers.williamhillplc.com/

Using Property Lists

A simple way to get values or settings into a project without having to mess around too much! Just create a property list in xcode called Settings.plist for example and add any key values you need. Then when you instantiate your model load it in as an NSDictionary in and voila!

//Load in Settings
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *plistPath = [path stringByAppendingPathComponent:@"Settings.plist"];
NSDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:plistPath] retain];

//Now get out a value using the key name that we have entered in our pList in xcode
NSString *jsonStringURL =  [plistDictionary objectForKey:@"JSON_URL"];

//Show an alert with the value
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"pList Settings" message: jsonStringURL delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
[alert show];
[alert release];

Setting background transparent on UI objects

You can just use [UIColor clearColor] whenever you want to set something with a fill transparent inObjective C.

You can also do this in Interface builder by selecting the object and opening the colors window. Then adjust the alpha value with the slider at the bottom.
This works for all sorts of UI elements – buttons, textfields etc.

[label setBackgroundColor:[UIColor clearColor]];

Defining project constants

Just a quick tip for creating a globally accessible bunch of constants for your iOS project. In AS3 I would use a class with a public static variable but in Objective C you can use constants or definitions and there are probably several other ways to do it.

To use constants globally:

  1. Define a new Objective C class which extends NSObject for example called ProjectConstants
  2. Above the implementation line in its header (ProjectConstants.h) file add this:
    extern NSString * const PAGE_TITLE;
  3. In the implementation (ProjectConstants.m) file add:
    NSString * const PAGE_TITLE = @"My Page Title";
  4. Access it globally by importing the ProjectConstants.h and then you can use PAGE_TITLE anywhere in the project:
    NSString *pgTitle = PAGE_TITLE;
    myLabel.text = pgTitle;

Another quicker way is to use definitions in your implementation of your .m file such as: #define PAGE_TITLE @"Title"
The disadvantage of that is you can’t compare strings using pointer comparison i.e. (myString == MyConstant) but you can still use [myString isEqualToString:MyConstant] but its not as easy to read, and apparently not that fast either.

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;

Sorted!

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.

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!?