Serious multiplayer 3D games using Unity, Flash and Red5 - Presentation video

The video registration of the Adobe Usergroup Meeting #12 about games is made available on the website of the Dutch Adobe Usergroup. This is including my presentation about serious multiplayer 3D games using Unity, Flash and Red5.

I've receive quite some feedback, including some international feedback of people who are disappointed the presentation is in Dutch and they can't understand it. I'd love to get invited and do this presentation for an international audience, so ping me a message when you have an opportunity (hint: I'll probably travel to California in September :-) ).

Regarding the presentation, also make sure you'll watch the following presentations:

Kudos to the Adobe Usergroup for making these videos available!

Serious multiplayer 3D games using Unity, Flash and Red5 - Presentation slides

Today's meetup of the Dutch Adobe Usergroup has been a very successful day. Not only because I did one of the presentations. The other presentations where very interesting as well. It was very interesting to hear experiences from other people that are involved with game development. The line-up was top of the notch, with speakers like Senne de Jong from Little Chicken Game Company, Tim Hudson and Sander Wichers from Virtual FairGround, Quinten Beek from MediaMonks Games, Daniël van Gils from Kamerblauwlicht and more. Check out the Adobe Usergroup website for more details.

Couldn't make it to this meeting? Don't worry, all sessions will be available on the Adobe Usergroup website soon (I'll dedicate a new post on this once it is available).

I've been asked to do a presentation about what I'm doing with Unity, Flash and Red5. Hopefully it gave some new insights to at least a few of the 250 attendees. I really liked talking about my recent passions and want to thank the Adobe Usergroup for inviting!

I've just posted my presentation slides to SlideShare, while waiting for the session videos that will become available soon:

AS3 clickTag case and popup blocker fix

Last week we've been struggling to get our AS3 banners ready for publication.
One of the more common problems anyway, is that some ad management systems requiress clickTag (lowercase "ag") and others requires clickTAG (uppercase "AG") in order to load the right URL. This is very annoying, especially when you have to make 2 versions for different publishers and you need to do a text change... When you have a big capaign with let's say 5 banner formats, and 3 banner variants, you already have to make 15 different banners. In case you need to deliver banners with a clickTag and a clickTAG, you'll end up with 30 banners. In case you've ever build banners yourself, you see my point. It's soo easy to lose the overview when you have so many files looking almost identical to each other.

A new problem with banner build using AS3, is that some browsers will block the navigateToURL requests. A trick for this is let javascript open the URL instead of actionscript.

Both of these things have been recently an issue, so that's why I decided this weekend to wrap this all up in a clickTag class, which is universal for all different case combinations of the word clickTag. Beside that, it will open URL's correctly without a browser which is blocking it. (at least, as far a I know).

Instead of adding a button on the stage, set up all the event listeners etc, you can now use:

 
var clickTag:ClickTag = new ClickTag(300,250);
clickTag.enableClickTag();
addChildAt(clickTag,0);

It's just as simple as that. In case you want a custom shaped button, you need to assign it to clickTag by using "clickTag.setButton(btn);".

In order to open the links correctly, you need to make sure that the parameter AllowScriptAccess is set to "always":

<param name="AllowScriptAccess" value="always">

Download this class and it's examples in Flash and Flex here!

Unity3D communication with browser and Flash

I've been using Unity3D for a while now and I would like to share some of my discoveries starting by this post. In case you don't know unity3D yet, you should check out their website: unity3d.com and make sure you'll see the tropical paradise and shadows demo. Unity3D is a very promising 3D engine with the possibility to publish for the web by using a browser plugin (just around 3MB) with extreme good results. Personally I'm not a big fan of using browser plugins which aren't as adopted as Flash is. Flash projects like Papervision3D/Away3D/Alternativa/etc are very impressive and I love to use them. But in case you want to go more advanced, this is all to limited and you have to look at a browser plugin. Unity3D is then the best option.

Okay, enough introduction. As a web oriented developer I want Unity3D elements on my page to completely integrate with other elements in an easy way. Basically, I want to be able to have cross communication between Unity3D, Flash and javascript on a page. Building GUI's using Unity3D is very limited when you compare it with Flash. So why not using best of both worlds together on a page?

While starting with this I found a chat demo build by FlashBangStudios which does cross communication between Unity3D, Flash and a browser. Unfortunately it isn't open sourced, so we can't see everything about what's going on under the hood. So I've build a Unity3D chat myself based on communication within the browser. (Source files are included in the download at the end of this article)

To achieve this I used something similar like SWFObject, called UnityObject, to embed unity files in a clean way on my page. The coded posted there seems to a bit out dated and showed some problems in Internet Explorer 7. So I've tweaked their version a little bit and it now should be working perfectly (Tested with Firefox 3.0.3, Internet Explorer 7, Safari 3.1.2 and Chrome).
With unityobject, embedding is very easy:

var uniObj = new UnityObject("UnityObject.unity3d", "Unity3D", "640", "480");
uniObj.setAttribute("altHTML", "Alternative content when player is not installed");
uniObj.write();

To call a function on a gameObject in unity we can use the following code:

uniObj.msg( "GameObjectName", "FunctionInGameObject", "ParameterToSendToUnity" );

All this does is calling a special function on the unityObject within your page called SendMessage(...); and delegates your call to the object and function which you described in the call. In case from above we will trigger FunctionInGameObject in GameObjectName. We can only pass 1 parameter to the triggered Unity function. The most advanced parameter you can use in this case is an array. Using an object isn't supported. So when you want to pass an object as a parameter you need to serialize and deserialize your object. This is however not supported by default in Unity. When you want to do this, you could use JSON for example, which is offcourse supported in javascript, but there are good C# libraries as well. Maybe I'll dedicate a future blog post to this.

Now we have successfully called a function in Unity, it's time to send something back to the browser. This is very simple as well:

//Unity3D js code:
Application.ExternalCall("javascriptFunction", "Parameter1");

//Javascript code in browser:
function javascriptFunction( param ){
 alert( param );
}

Instead of alerting the function call, we can send this parameter to Flash and show the value in a Flash text field for example. This requires just a 1 line more code compared to calling a Unity3D function. First we need to define in Flash which function are allowed to be called by the browser.

ExternalInterface.addCallback("functionNameInBrowser", functionNameInFlash );

Now we can call functionNameInBrowser by the browser on a Flash object, which calls functionNameInFlash in Flash. To achieve this I use the following code in javascript:

//Cross browser function to get a movie on a page.
function getFlashMovie(movieName) {
 var isIE = navigator.appName.indexOf("Microsoft") != -1;
 return (isIE) ? window[movieName] : document[movieName];
}

//Call function in flash
function javascriptFunction( param ){
 getFlashMovie('flashMovieIdOnPage').functionNameInBrowser( param );
}

By executing the code from above, the function functionNameInFlash will be called like a regular function call. A sample function might look like the following code:

function functionNameInFlash( param:String ):void{
 message.text = param;
}

This is all you need to communicate between a browser, Unity3D and Flash. Once you know this trick you can for example:

All examples are bundled in one download, which includes all the Unity3D, Flash, Flex, Actionscript and Javascript files.

I hope this will help anybody. Please let me know your feedback!