iPhone newbie lessons

March 20th, 2009 § 0

It’s been a long time since I messed around with Objective-C, even a little bit.

A couple of things that have bitten me lately:

  • @selector(apply:) is different than @selector(apply)! Note the lack of a colon in the second one. The colon means that there is one parameter to be passed with the message. No colon, no parameter. This makes a big difference when passing a selector as an argument to something like NSArray makeObjectsPerformSelector:.
  • I keep forgetting to pass nil as the terminating argument to methods like NSArray initWithObjects:. Forgetting the terminating nil will cause the iPhone to crash with a Bad Access exception as it runs off the end of the stack into the weeds.

And one very valuable debugging tip I found here:
how to find out what exception was thrown in the Xcode debugger. When an uncaught exception kills your iPhone app, Xcode doesn’t really have much information at that point. To remedy that, go to Run -> Show -> Breakpoints and in the Breakpoints window double-click on the entry that says “Double-Click for Symbol.” Enter “objc_exception_throw” and press Return. Now, when you run your app in the debugger, any exception will stop there and let you see the exception type.

Beginning iPhone development

March 13th, 2009 § 0

I’ve just started to develop for the iPhone. I have the SDK and have joined the developer program. The last time I did any Objective-C was about 8 years ago, and that was just dabbling, too.

I will probably try to port one or two of my pets over to the iPhone, although the audience for iPhone apps is probably a lot different than the audience for MySpace Flash widgets (then again, with the prevalence of Fart apps on the iPhone app store, who knows?). Regardless, I’m hoping it will still be a good exercise.

Rename an element across all frames of a timeline

February 27th, 2009 § 0

I use a combination of timeline animation and scripting-based movement. All too often, I will create a timeline animation and only later realize that I need to give a MovieClip (or MovieClips) a name so I can refer to it from a script. Of course, this only happens after I’ve already created a zillion keyframes, and going through the entire animation to make sure that each MovieClip has its proper name in each keyframe is a real pain.

I finally got around to creating a simple JSFL script to automate this. It’s nothing special and it doesn’t do much error-checking or anything, but I thought I’d share it regardless in case it helps someone else :)

Copy and paste the following code into a file with the extension “.jsfl” (for example, “Multiframe renamer.jsfl”). Save the file in the appropriate folder, based on your platform:

  • Windows Vista™:
    boot drive\Users\username\Local Settings\Application Data\Adobe\Flash CS3\language\Configuration\Commands\
  • Windows® XP:
    boot drive\Documents and Settings\username\Local Settings\Application Data\Adobe\Flash CS3\language\Configuration\Commands\
  • Mac OS® X:
    Macintosh HD/Users/username/Library/Application Support/Adobe/Flash CS3/language/Configuration/Commands/

and restart Flash.

Then, in your document, select the element you want to be renamed across all frames. The go to the “Commands” menu and choose “Multiframe renamer”. You will be prompted to enter a name for the element (press “Cancel” to abort), and it will go and rename that element across all keyframes in that layer.

No warranty, use at your own risk, etc., but feel free to share and improve on it :)

/* multiframe renamer */
 
go();
 
 
function go()
{
    if ( ! fl.getDocumentDOM() || fl.getDocumentDOM().selection.length == 0) {
        alert("Please select an element");
        return false;
    }
    var element = fl.getDocumentDOM().selection[0];
    //  use the element's current name as the default
    var name = prompt("New name for elements on this layer?", element.name);
    if (name == null) {
        alert("Cancelled by user");
        return false;
    }
 
    var timeline = fl.getDocumentDOM().getTimeline();
 
    //  find the layer from the selection
    var layer = element.layer;
 
    //  all frames in this layer... rename first element to the name
    for (var i = 0; i < layer.frames.length; i++) {
        if (layer.frames[i].startFrame == i) {
            if (layer.frames[i].elements && layer.frames[i].elements.length > 0) {
                layer.frames[i].elements[0].name = name;
            }
        }
    }
 
    alert("Done!")
    return true;
}

Flash CS3 top-left redux

February 11th, 2009 § 0

Last May, I complained about the change in the “Info” panel from Flash MX 2004 to Flash CS3. Since I needed the functionality, I whipped up a very simple (and crude) panel to let me see and edit the top-left of an element.

Download the compiled panel and the source code.

topLeft

As you can see, it’s very primitive. Select the element you want to operate on, and click “Get topLeft” to read the values of its top and left bounds. Click “Set topLeft” to move the selected element.

This comes in handy for changing a MovieClip’s registration point while leaving its visual position intact. Select a MovieClip instance, click “Get topLeft,” then edit the MovieClip and slide its contents around so that the registration point is where you want. Exit MovieClip editing, then click “Set topLeft” (without changing the values in the edit fields). The instance will go back to its original visual position.

Flash CS4: styling device fonts in the IDE?

February 8th, 2009 § 0

In Flash CS3, I could use the IDE to create a text field whose font was “bold _sans” (_sans, of course, being the “generic” sans-serif device font).

However, in Flash CS4, it seems I cannot do this, as the style menu is empty and disabled when any of the generic fonts are selected (or if “Use device fonts” is chosen). I can make a _sans text field, but not a bold or italic one.

It is still possible to apply the styling at runtime, but I shouldn’t have to do that.

Is there something I am missing?

The 4 things about UserVoice that drive me @#$%! insane

January 26th, 2009 § 3

I don’t normally blog about sites that I find frustrating–it’s generally not worth the effort. But since both TweetDeck and Twhirl use UserVoice for customer feedback, I end up using it far more than I want to, and thus the frustrations build. I must vent!
» Read the rest of this entry «

The magic of TinEye

January 13th, 2009 § 0

[This post is a bit off-topic compared to the rest of the blog but I didn't think it made sense to start a whole new blog just for one entry ;) ]

TinEye is an image search engine. But it’s not like Google Image Search: rather than searching for images by keyword, it searches for images based on an image you provide. It’s smart enough that it will find cropped, resized and otherwise modified versions of the original image.

I have gotten into the habit of using TinEye whenever someone passes along an interesting image without any source information. Here’s an example:

Just today I saw this photo album posted in my Facebook newsfeed (link requires Facebook login to view). Such a beautiful and powerful image, but it lacked a photo credit.

arm in arm

I fed the image into TinEye. Out popped a couple of pages of results, mostly blogs and forums in various forms (some were cropped differently, others had text overlaid on it like “We can coexist…”). One result in particular caught my eye: an Amazon.com link. The image was used on the cover of the book Christians And a Land Called Holy by Charles P. Lutz and Robert O. Smith.

Following the link, I noticed the “LOOK INSIDE” button. A couple of clicks took me to the copyright page, which said “Cover photo © Ricki Rosen/Corbis“. Bingo!

After that it was quick to determine via Google searches that Ricki Rosen is a renowned photojournalist, and a search on Corbis located the original image, available for licensing.

iPhone VR: Viewing 3D panoramas in Safari using JavaScript and -webkit-transform

October 13th, 2008 § 7

Apple’s 2.0 iPhone update brought some interesting enhancements to Mobile Safari, including 3-D perspective and access to multitouch events. Armed with the documentation (of varying quality) from Apple’s Web Apps Dev Centre, and invaluable information from blog articles such as Idean’s “Spin the Bottle”, SitePen’s “Touching and Gesturing on the iPhone” and Paul Bakaus’s “3D CSS Transforms on the iPhone”, I put together a simple web app that displays a cubic panorama in Mobile Safari. Look left, right, up and down by dragging your finger across the display. No zoom, currently, though. It was pretty straightforward, but I did learn a few things while creating it.

Go ahead, take a look :D Visit http://tinyurl.com/iphonevr on your iPhone or iPod Touch.

The images used for the panorama are taken from one of the QuickTime VR movies in Apple’s Cubic VR gallery. I extracted the images from the movie using the procedure explained here (in French, but it’s easy to follow).

I may write a full tutorial on this eventually, but for now I will just share a few notes (and the source code):

  • It’s a lot easier to get the 3-d transforms right if the elements you want to transform start out centred in their containing block (so that they start at (0, 0, 0), essentially). I did this with regular CSS, but I suppose this could also be done as part of the transform.
  • The above also applies (especially) to any DIV that contains nothing but other DIVs. At first my cube was spinning around its top edge, instead of its centre, because its children (the cube faces) were absolute-positioned, and thus the “cube” DIV itself had no height! Giving it an explicit width and height solved this.
  • Touch events on 3-D transformed elements seemed to be little bit unreliable. I worked around this by putting a normal transparent DIV on top of the whole thing and listened to events on that instead.

Download the source code (MIT Licence).

JSFL feature request

July 17th, 2008 § 2

Automating Flash with JSFL is very useful, but I sure wish there was a way to specify “save as Flash 8″ in fl.documentSave(). I guess I could run the script in Flash 8 instead… kind of a hassle though.

Firebug icons

June 24th, 2008 § 6

Since I recently upgraded Firefox to version 3, I updated my Firebug install to version 1.2 Beta. One of the first things I noticed was that the little icon in the status bar had changed from a checkmark (or a grey slash when disabled) to the little insect icon (it’s grey when disabled, and colour when enabled).
new firebug statusbar icon, disabled

I don’t mind seeing the Firebug icon occasionally (like when the Firebug panel is open), but I find it a bit distracting and, yes, disturbing to have that little bug always onscreen. Oddly, I never found Safari’s “report bug” button distracting in the same way—perhaps it’s because the Safari bug icon is more abstract than the more finely detailed Firebug icon. (Although I admit that looking at these two screenshots side by side, there doesn’t seem to be much of an obvious difference!)
safari\'s report bug button

In any case, I decided to create my own status bar icon for the new Firebug. As you can see, my icons are very abstract, to get away from the creepy-crawliness of it all. The six legs are represented by six stubby horizontal lines, and the body has become a sphere.

my firebug icon (disabled) and my firebug icon (enabled)
» Read the rest of this entry «