Extending(Subclassing) UIButton in Objective-C

After playing around with UIButton class for a while I found Apple have been very sneaky with some  of their UI classes.

What it appears they have done is use the UIButton class as a sort of wrapper for a number of private button classes. “UIRoundedRectButton” is one of those classes.

“UIRoundedRectButton” is a private class so it can not be extended(subclassed). The initilizers normaly return an instance of self and if that self is not the class type trying to hold it there will be trouble. The problem is if you initialise UIButton with buttonWithType the class it returns is a private class. If you try and extended the UIButton once your custom class is initialized it returns a “UIRoundedRectButton” object which is private so you can not contain it.

If you try the code below which uses the description you can see the object description is not UIButton.

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
NSLog(@"myButton type: %@", [myButton description]);

In short you can not extend UIButton and initialize it with buttonWithType  in Objective C. On the other hand you can extened UIButton for a button in interface builder. If  you use interface builder you need to use initWithCoder as the initialiser. While interface builder does the private stuff.

Kodu the Visual Programming Language

Here is an interesting product on XBox Live. Its a games Programing tool with out the coding. If this is a sign of things to come all use Developers will all be out of jobs ;) Check out the Video!

Get here if you want it:
http://marketplace.xbox.com/en-GB/games/media/66acd000-77fe-1000-9115-d8025855024c/

Stackoverflow Inspiration and Learning Event

The popular code question and answer site http://stackoverflow.com/ are having a few inspiration and learning events this year. I am keen to see what android and objective-c stuff will be on offer you can get tickets from: http://stackoverflow.carsonified.com/

Finding Page URL using ActionScript

How can I find the url of the page my flash is embedded in? This may seem really simple but I cant count how often I find js functions which pass this value into the flash. ExternalInterface allows access to a wide variety of js and should not be over looked. The below line of code will call the javascript “window.location.href.toString” and return the url as a string.

var currentURL:String = ExternalInterface.call("window.location.href.toString");

SWF to SIS Online

Mobile development is something I have always wanted to spend some time on. Recently I have been looking at mobile application development. I have found there are a lot applications or tutorials on how to convert your Flash Lite files to sis installers which allow you present your swf files like an application on the main menu of your Symbian based phone.

http://www.swfpack.com/

SWFPack is a on-line service which will package up your swf into sis file with little to no effort. Mind you its still in beta but it does what it promises on the tin. Hell it even lets you add a custom icon which is used on the menu.

Evolution of Games

Being the gamer that I am I feel a post on the direction of games might be worth a look. Without a doubt online gaming is where it’s at. You have two easy to see growth industries. Multiplayer which is no longer just for 1 on 1 or the elite geek MMORPGers.
Xbox Live is releasing a premium channel with online game shows which any one can watch or participate in. Is this a possible direction TV might take in the future?

Then we have user generated content like the ever popular Little Big Planet on the PS3. The levels being made by the community are quickly out doing the original levels. Now Microsoft will be stepping in with one of their community games Kodu. A game building game where you build your own world and create your own type of games. Check out what a 12 year old can do with it.

Flash Player 10 (FP10) Beta Release

Adobe have added a lot of new features to the player. I am just gonna highlight what stood out to me.

3D Support & Effects

There is now support for 2D surface in a 3D environment. This mean you can animate a 2D object in 3D space natively in flash with out the need for a 3d party engine. If you would like to use 3D object like a cube, sphere or teapot with out have to construct the basic objects your self a 3rd party engine is still needed. The effects in 3D are like the filters only applied in 3D and seem to have a more robust support which incorporates the hardware acceleration.

Graphics Card Support

Finally, hardware rendering that does not require full screen mode. It needs to be enabled in the html though. It also seems that adobe have limited support to cards with Open GL 2.0 with GLSL capabilities. You will get a green square in the top left corner if there is any acceleration.

Text Engine Rebuild

Support for right to left and top to bottom languages. Maybe the engine will render a bit more like adobe photoshop which will mean matching flash to photoshop design will become a bit easier.

Vector Data Type

Basicly a typed Array. Should run a bit faster and take less memory.

Relevant  links:

Release notes :

http://labs.adobe.com/technologies/flashplayer10/releasenotes.html

Install instructions(found in the release notes) : http://labs.adobe.com/technologies/flashplayer10/releasenotes.html#install

Testing for FlashVars in AS2

Quick bit of code stick it on the first frame of new flash file and it will list all the FlashVars passed into the flash.

//creates the text feild on the stage

this.createTextField("vars_txt",3,100,100,Stage.width-100, Stage.height-100)

//sets the basic properties

vars_txt.multiline = true;

vars_txt.selectable = true;

//adds the title

vars_txt.text += "FlashVar : Contant of FlashVar\n";

for(var z in _root)

{

 //$version: version is on the root by default so it is excluded

 //vars_txt: is the name of the text field so it is also excluded from the list

 if(z !=  "$version" && z != "vars_txt")

 vars_txt.text += z + " : " + _root[z]+"\n";

}

navigateToURL and popup blockers

AS3 has brought a lot of new functionality and complexity to flash development. It has also brought some new problems.

Pop up blocking is simple principle where only user initiated events can open a new window. In the case of AS2 when creating a link it had to be triggered from an onRelease/Click event. Other wise in AS2 “getURL” was adequate in any browser. Unfortunately “navigateToURL” in AS3 does not seem to be useful across all browsers as even on Click it can still be pop up blocked.

In my mission to get a flash only solution for opening URLs that don’t get pop up blocked, I found ExternalInterface call to “window.open” works as long as its available in the browser. The basics of the code I used is below.

        //set the desired URL here
        var url_str:String = "http://www.yoururl.com"

        //checks to see if the browser has JS on and
        //if ExternalInterface is compatible with the browser
	if (ExternalInterface.available)
	{
                //calls the JS function "window.open" in a new window
		ExternalInterface.call( "window.open", url_str, "_blank" );
	}
	else
	{
                //the fall back call is "navigateToURL"
                var urlRequest:URLRequest = new URLRequest(url_str);
		navigateToURL(urlRequest,"_blank");
	}

Silverlight 2.0

Its finally going to happen Silverlight 2.0 which is the C# flavour of Silverlight is going to be out in non-beta and non-alpha. This means its an official release. With all the bells and whistles it looks like Rich internet apps have a new friend. This year is looking to be a pretty full on with the new Visual Studio(code named ORCAS) out end of 2007 and Silverlight 2.0 to arrive in the next couple of months. Microsoft is looking to have a good 2008.

http://blogs.msdn.com/tims/archive/2007/11/29/silverlight-1-1-is-now-silverlight-2-0.aspx

http://blogs.msdn.com/bobfamiliar/archive/2007/11/29/silverlight-2-0-roadmap.aspx