Ubacoda.com is an independant developer of mobile applications. Welcome to the ubacoda.com blog!

Graphics Optimization for the Adobe iPhone Packager

Fri Dec 24 05:33:13 2010

I have been doing some looking around and to be honest there isn't much that I have found useful in regard to graphics optimization for the iPhone Packager. To be quite frank, I may even be as bold as to say that it appears quite useless compared to a lot of other solutions available. That of course does not go for Adobe's efforts for Android. I'm sure that with the increase in great mobile devices that offer Android OS, the performance will just keep getting better. However, what do we do in the meantime for ActionScript on the iPhone? Well, here's something that may not be very practical but I have found that it boost performance of graphics on the device.

Most will know by now that using cacheAsBitmap = true; and cacheAsBitmapMatrix = new Matrix() along with setting the renderingMode to gpu helps performance considerably and I can vouch for that.

However, I have been hearing a lot of talk about how using Bitmaps also helps performance. This I have found not to be so true, as when I compile an .ipa file using -renderingdiagnostics, every bitmap that I have every tested lights up a bright red (not good). All vector graphics, including FXG graphics display in a nice green. The frame rate is always much higher for vector graphics and FXG too, provided that nothing too strenuous is being done to them.

Now this is what I find interesting about all this. When I create an FXG file containing one of the .png files that display in red under -renderingdiagnostics, and then import said FXG file and use cacheAsBitmap = true; and cacheAsBitmapMatrix = new Matrix() with gpu set as the renderingMode, I get much better performance than just using a Bitmap by itself.

I don't really know why this occurs and I nothing I have read gives any indication of this, but through my own experiments, that is what I found. Please let me know if anyone finds a way to use bitmaps that display in green under -renderingdiagnostics. Or have I got it all wrong, and there is no way to cache an actual Bitmap? If so, then that is just silly!

Come on Adobe, I know you are working hard but throw us a bone!

Dynamic Classes in ActionScript 3

Mon Nov 29 23:45:29 2010

Dynamic classes in AS3 are a cool feature of the language. They allow you to add properties to the dynamic class at run time, which is something that is not possible with other types of class. It is important to note however that dynamic class are a little more memory intensive, due to the fact that they create what is called a 'hash table' to store the properties/methods added at runtime.

The Dynamic Class - MyDynamicClass


package{	
   import flash.display.*;
	
   public dynamic class MyDynamicClass extends MovieClip{
      public var firstName:String = "Ben";
      private var age:String = "28";

      public function MyDynamicClass(){
			
      }
   }
}

Public Class Main (instantiates MyDynamicClass)


package{	
   import flash.display.*;
   import MyDynamicClass;
	
   public class Main extends MovieClip{
      private var d:MyDynamicClass = new MyDynamicClass();

      public function Main(){
         trace(d.firstName); // outputs "Ben";	
         trace(d.age); //outputs undefined

         d.gender = "Male";
         trace(d.gender); //outputs Male
         delete d.gender;
         trace(d.gender) //outputs undefined
      } 
   }
}

Looking at MyDynamicClass, you will notice that it contains 2 variables - firstName and age. The property firstname is accessible by Main because it is public, whereas age is not accessible because it is private. Nothing new there! But inside the Main class we then add the dynamic property gender, which traces out just fine. Using the keyword delete allows the removal of dynamic properties, which in turn, puts them up for garbage collection. In the Main class example, g.gender is deleted on line 14 and when a trace is performed on that property on line 15 you will see that it now outputs undefined as it is no longer available to the class.

I'm not entirely sure how practical a technique this is and I would suggest that properties and functions should always be defined inside the classes they are meant for, as it makes it slightly more difficult to see exactly what a program/class is doing. However, I think that if you don't plan on passing your code on to anyone else, it may be the quick 'escape' you need if you're too lazy to back into an imported class a defined the property. Just be warned though that classes that extend a dynamic class are not dynamic in themselves, so be prepared for some irritating error messages from time to time! :)

Interview with Ansca about Tumble Bee

Sat Oct 30 04:05:11 2010

Just wanted to post a quick link here and say thank you to the guys at Ansca for giving me the opportunity to be interviewed about my iPhone application - Tumble Bee.

Tumble Bee interview:

Diary of an ‘ActionScript 3 Madman’ Tumble Bee creator Ben Walker

Build iPhone applications using the Adobe iPhone Packager

Mon Sep 20 05:45:09 2010

For the longest time now, many ActionScript developers have dreamt of using their skills to build iPhone applications, without having to mess around with learning yet another programming language. Adobe released the iPhone packager along with Flash CS5, but a few days prior to that release, Apple and it's lawyers rinsed any possibility of ActionScript running on the iPhone/iPod/iPad etc with bold changes to it's Developer's Agreement, thus leaving the iPhone packager useless. With that, Adobe pledged to discontinue efforts on the iPhone and concentrate on development for Android Devices. As exciting as this was for Android, it left a lot of developers angry, to the extent that some began boycotting Apple products and iPhone Developer get-togethers.

Recent events, however, (and I won't even try to understand the reasons why) have seen a kind of reverse to Apple Developer's Agreement, in that Apple are basically saying that you can now Develop for the iPhone using the iPhone packager (as well as other packagers for various languages) as long as the applications built do not download code. Great news, right?

I was one of the one's who had given up any hope of seeing ActionScript on the iPhone, and I had gone out and found other means of building my first app: Tumble Bee, and to be quite honest, I don't regret it. I learnt a lot from my ordeals and I came out much the wiser.

On the other hand, I am really excited to see what is in store for ActionScript on mobile devices in general and I think that the recent changes really open up the market for developers to build better than ever.

So without any further ado, I would like to post here what I have found out about compiling ActionScript for use on the iPhone.

What you will need

  • Flex SDK including air 2.0+
  • Adobe's iPhone packager
  • Apple provisioning profile (You have to sign up for the Apple Developers license [$99] )
  • p12 certificate (info can be found here)
  • application.xml (I have created an example in the downloadable zip file below)
  • ...patients!

Next download the zip file from the link below. It contains example files that will get you on your way.

iPhone App Example Files Upzip it and inside you should see:
  • Main.as
  • application.as
  • icons (folder with icon29.png and icon57.png inside)
  • Default.png

First thing to do is to place the .mobileprovision file that you got from the iOS Dev Center and the .p12 file you should have created inside the unzipped TestCase folder containing the items listed above.

Next, open up Terminal and navigate to amxmlc inside the bin folder inside the Flex SDK you downloaded. (Note* There's more than one way to skin a cat, but this the way I prefer). I have my SDK in my Developer folder so I would type /Developer/SDKs/flex_sdk_4/bin/amxmlc followed by the path the file Main.as file inside the zip file you should have downloaded. For example, if the TestCase folder is on your desktop, it will look like this:

/Developer/SDKs/flex_sdk_4/bin/amxmlc /Users/{Username}/Desktop/TestCase/Main.as

That will compile the Main file inside the file. You could add -o="location+name.swf" to create a file using a different name.

As you may already know, I like Textmate's ability to run commands very efficiently. If you're like me, you'll probably make a command out of this so you don't have to type all of that every time you want to compile.

Now that you have your .swf, it's time to make the .ipa that will run on your iPhone. You will need to compile using the iPhone packager. I placed mine in a folder called iphone in /Developer/SDKs/. You can place it anywhere you like, but just remember the location. Next make sure you have the .mobileprovision and .p12 in the TestCase folder, cd (change directory) into the TestCase folder and run the following command in Terminal (altering where necessary):

/Developer/SDKs/iphone/bin/pfi -package -target ipa-test -provisioning-profile my_cert.mobileprovision -storetype pkcs12 -keystore my_cert.p12 -storepass {your password} TestCase.ipa application.xml Main.swf Default.png icons

Once that has finished compiling, you should be left with the TestCase.ipa file, which you can then add to iTunes and sync to your device. The actual app in question is a simple program that will show you an example of the ActionScript TouchEvents available - TOUCH_BEGIN, TOUCH_MOVE and TOUCH_END. Just tap and move your finger around the screen and you will see what it does.

Anyway, that's about it. It has a little bit of a learning curve but I'm sure you'll pick it up in no time.

Tumble Bee - my first iPhone app!

Fri Sep 3 12:59:08 2010

'Tumble Bee' has been on the iTunes store for a few weeks now, but I'm am only just now getting round to posting about it here.

Not that I'm advertising or anything (although I suppose a few sales wouldn't hurt), but I have to admit that it's quite addictive. My top score is 263 jumps. If anyone gets higher, please let me know.

But even more importantly, there is nothing better to a programmer than feedback. Please please please feel free to let me know what you think of the game and how it can be improved. I'm all ears towards unbiased, useful comments.

Please visit the TumbleBee iTunes page to check out more about the app as well as the few screen shots that I've put up.

Download Tumble Bee

Most recent posts

  1. Flashcards Maker - the app the helps you learn in a flash
  2. Convert Font Suitcase to TTF in 3 Easy Steps
  3. Rain or Shine - Weather Forecast Available Now!
  4. Getting around Apple's silly rules for iOS 10
  5. Localising App Names for iOS and Android

Search site:

Apps by Ubacoda.com

Click the app icons to see more info


Archives

Categories