The iPad and me

I don’t really like to do opinion pieces. On the subject of technology, like religion, sometimes it doesn’t really matter what you say; both sides never really listen to each other. I don’t want to add another pointless my side is better than yours article. But I think it is sad when people say that such and such is bad and should die. Like it is currently the case with Flash and the whole iPad brouhaha. What I think these people don’t consider is the human impact behind this.

If Flash was to go away tomorrow, I’d find myself without a job. Well, I’d need time to learn another language and then I’d find another job but it wouldn’t be the same thing. I am really glad I found Flash and ActionScript 3. This is what I want to do for at least the next 5-10 years. What I like about it is that it speaks to both my programmer and creative side. It is also fast-paced; in the web agency world, you move from projects to projects really fast and you have to keep up with technology at the same time. It might seems weird but I really like that; no time to get bored. If it wasn’t for Flash, I don’t think think I would love my job as much as I do.

After the iPad announcement I found myself a bit confused and stressed about my future. The future of Flash seemed uncertain so my future seemed uncertain to. Not uncertain because of the evolution of technology (like HTML5) but because a company decided what the outcome should be. If all Apple products stop supporting Flash, this is not good news to me. What possibilities I had would lessen. Some would say that I shouldn’t tie myself to a technology, I know, and if I have too I will learn something knew, but as I said before I really like Flash. That made me think that it’s not only companies that can choose who gets to live or to fade (technology wise). Us, as developers, can put our weight in the balance too. As long as there will be people producing get content for the Flash platform, it will continue to thrive. If I like Flash that much, I must not be alone and from reading all those article that take Flash’s defense, I think I am right. So I feel more at ease now. The future is still uncertain but certainly less gloomy.

One last thing about the iPad. Zeldman in his post states that the computer of tomorrow is a computer that is dead simple but that in return doesn’t give all powers over it for the sake of usability, like the iPhone and the iPad do. I think that a portion of the population in fact wants that. Right now this portion might be big, but I think it will shrink because it doesn’t consider that the children that are raised right now have never seen the time when there was no computers. These will be way more computer literate than my parents lets say. For that I think a device like the iPad is closer to a toy than to a tool. If it wanted to dominate the netbook market, than it will fail. We don’t really know what is the role the netbook is going to take, but by making one that is limited in its usage, you also reduce your chance of getting it right.

Well that’s all I had to say.

, , ,

2 Comments


More on preloaders: passing the loaderInfo

I previously made 2 posts on the topic of preloaders (The right way to do a preloader in AS3, External Preloader; more complex cases), well this post will be a continuation of those. And one that I believe not everyone will agree with me. I know that because I didn’t agree with it at first but the more I thought about it the more it felt right.

When it comes to code I’m a bit of a fascist, I have trouble accepting habits of other coders if they are not the same as mine. So when I see something different my first reaction is to frown upon it (I am talking just about code; I am a very open minded person). When I first saw this mean of passing variables from the preloader to the main application that a coworker was doing I didn’t quite like it.

In the post about the more complex preloaders, I showed how to use an interface to pass data from the preloader to the loaded (main) movie. Now this part of the code is still the same. What changes is that instead of passing the flashVars (variables that are passed to the flash from the html embed code or javascript) individually inside fo the init method of the Main class (also in the interface), we pass them all together by giving the root.loaderInfo instead.

I already know what you are going to say: this is not strictly typed so it is bad. I know, I know, but if you think about it a bit you see that at some point the flashVars are not typed anyway; when they transition from html to flash. So what is the harm of perpetuating this just one level more? In the init method inside the Main class, the first thing I do is that I type the parameters passed, so I do end up typing my variables.

Now, you’re going to ask what do you gain from this? Well, since the preloader is an external file, every time you are going to pass more variables to the Flash from the HTML, you will have to modify 3 files : the preloader.fla, the IMain.as and the Main.as. Now if you pass the loaderInfo instead of the individual flashVars, you will only need to modify the Main.as since it is there that you type the variables. You completely bypass the preloader, which in a way make sense since your preloader doesn’t need to know about your application, all it does is to load it. once your preloader is completed you don’t ever have to touch it again.

Here is some code to illustrate this. In the preloader :

var mainContent:IMain;
function onLoadComplete(event:Event):void{ // this would be the function that the loader would call when the loading is completed
  mainContent = IMain(loader.content);
  addChild(Sprite(mainContent) );
  mainContent.init( root.loaderInfo);
}

And in the Main class :

package{
  import com.zedia.interfaces.IMain;
  import com.display.Sprite;
  import com.display.LoaderInfo;
 
  public class Main extends Sprite implements IMain{
    public function init(loaderInfo:LoaderInfo):void{      
      var flashVar1:String = String(loaderInfo.parameters.flashVar1);
      var flashVar2:Number = Number(loaderInfo.parameters.flashVar2);
      //do something with the FlashVars
    }
  }
}

, , ,

2 Comments


Fonts are my bane; not anymore!

I hate managing fonts in Flash, I truly hate it. I don’t understand why it is not easier than this after all that time. How about underline; why can’t we still underline in the Flash IDE? That shouldn’t be voodoo magic, even Notepad has underline, ok, Notepad doesn’t have the underlining functionality, but Wordpad does.

Anyway, my biggest problem with fonts and Flash is not the underlining problem, but when you start using static and dynamic textfields with the same font family but with different font style. When you do that, your dynamic textfields will just not show and that is really annoying. A solution that works is if you put all textfields dynamic, but that’s even more annoying.

Now a really cool feature is that you can now embed fonts using the embed tag just like this:

[Embed(source="assets/fonts/GNL_____.PFB", fontName ="zedia GillSansLight", unicodeRange='U+0020-U+007A, U+00C0-U+00F6, U+2019', mimeType="application/x-font-truetype")]
private var GillSansLight2:Class;

Not sure that this will work when you compile using the Flash IDE, but when doing ActionScript projects or Flex projects this works just fine. This way you can embed ttf, otf and pfb fonts. I am not quite sure how to embed fonts on a Mac system, it will still work with those formats, but I know Macintosh has other formats. The thing that makes this work is that you can specify the font name. Be sure to specify a name that you know Flash wouldn’t specify. My coworker gave me the trick to add the name of the project in the font name that way it’s always going to be different than Flash. If you don’t make it different you will still run in the problem of your dynamic textfields not showing up.

Once you have embedded the font you need to register it in your application like this:

Font.registerFont(GillSansLight2);

This will make the font available anywhere in your application. All you need to do is create a TextFormat with that font and assign that TextFormat to your textfield:

var tf:TextFormat = new TextFormat("zedia GillSansLight");//this is what you put into fontName in the embed tag
myTextfield.embedFonts = true; //this line is also important
myTextfield.defaultTextFormat = tf; //always assign the default textformat before modifying the text property
myTextfiled.text = "lorem ipsum";

Now, using this technique you can choose exactly what character from the font you want to embed. In the previous example the unicodeRange represented those characters:

U+0020-U+007A = SPACE!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz
U+00C0-U+00F6 = ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö
U+2019 = ’

This is a pretty safe set, but you can always change it and optimize it.

Here is a good resource to do Unicode conversion:
http://rishida.net/scripts/uniview/conversion.php

, , , , , , , ,

8 Comments


The post of the year

It is that time of the year where I look back and ponder. As I had foreseen, 2009 was really a great year (at least professionally but that’s another story). If my skills improved a lot in 2008 they continued to do so in 2009. I got to play a great deal with Papervision3D (roar4milk, Holiday Humanoes) and I got to modify my project workflow a lot too (I plan to make a presentation on that this year).

In numbers, I got to write 62 posts ( a bit less than once a week) and got 478 comments since September 2008. As for traffic, I am now getting 25 000 visitors a month, this is 10k less than the goal I set myself a year ago, but I don’t think it is so bad; my traffic is still growing steadily month after month. I did not write another article for InsideRIA like I wanted to, but I wrote 2  that got printed in FFDMag ( one of those I intended for InsideRIA but someone wrote on Google Analytics for Flash before me). What I am really proud of is that I got to give 2 presentations; one online and one in person at the Montreal Flash User Group. This is something I want to do more in 2010, 3 or 4 speaking engagements would be really nice. I already got an article nearly done so if I could get 1 or 2 more I would be happy. Lastly, I my traffic could increase to 35k visitors a month I think that would be enough for me. While we are at this, if I could be part of writing a book on ActionScript, that would just be the craziest.

Anyway, what I wish for the coming year is that I keep doing what I am doing. If I keep up the good work, good things will come my way, as simple as that, it worked fine in the past and I am pretty sure it will stay that way, naïvely.  Blogging is all about keeping doing it.

May 2010 be as good for all of us as 2009  was good for me. Happy new year!

, , ,

2 Comments


Dominoes for all for the holidays : Twist Image Holiday Humanoes

Want to see more than 2400 dominoes in 3D ?(why would you not?) Head over the Twist Image holiday card, see the Holiday Humanoes and make some with your friends’ faces on them.

I know that for every project I say that it was the most complicated one that I did, but this one really was the most complicated I ever did. There even was a night where I didn’t sleep because I wasn’t sure I could make it happen.

My big challenge was to create an experience that was close to what the design team was imagining but that wasn’t too CPU intensive (like all my other projects). I think I did manage to do that. It runs pretty smoothly even on some bad computers. I let Papervision3D do all the heavy lifting but I kinda trick the user into think that there are a huge load of dominoes while at any time there is only 300 of them max (you could consider this object pooling). A second challenge was to position those 2400 dominoes so the they make the final path. The design was done in Illustrator so what we did was that we exported the .AI file as a .SVG file. SVG is just an XML so I made another program that would read the SVG and output (trace to the console) ActionScript code that I would paste into the main application. Finally, the last challenge was to show a zoom out with all the dominoes fallen revealing the message. As I said earlier, if I had 2000+ dominoes at the same time that would be too hard for the computer and run really slow. So I replaced the scene with a bitmap. To get that final bitmap I had to make yet another program that would render me the final path with all dominoes fall and that a screenshot of it.

So I ended up doing 2 more ActionScript projects to end up with the finished product: The Holiday Humanoes.

Oh yeah, just a little trick to finish up, when you deal with COLLADA models, make sure your 3D guy exports the model without the textures if you don’t want the Flash Player to query the server each time you create a DAE. That is what was happening at first and it really scared me.

Holiday Humanoes

Holiday Humanoes

, , , , , ,

2 Comments


My verdict on FDT

I said I would try FDT for a month and I am sad to say that I did not find it superior to FlashDevelop. FDT has some good sides and even stuff that it does better than FlashDevelop, here are some:

  • compile errors while editing
  • debugger
  • ant support

But it has two major problems, first it is built on Eclipse which makes it much more complicated than it should be. Secondly it is very expensive (well I had more problems with it than just that, but these are the game changers). I don’t even understand why it cost so much… It even cost more than Flash Builder. Anyway that seems weird to me, but maybe it’s just me. Anyway in comparison to FlashDevelop which is free, it doesn’t stand a chance.

While venturing in the FDT world we came across templates, snippets and short keys. Those are very useful things when you use them. Templates are also time savers when you are using PureMVC because when you want to create a Mediator, all you have to provide it is the mediator name, and it’s view  name and type and it will generate the rest; no more copy paste from other mediator. Also project template are very cool. Snippets are mini templates, for example to generate getters and setters. Short cuts are combination of keys you press to do an action instead of going trough a menu to do the same action. Well, it just happens that FlashDevelop has all those things, but I just wasn’t using them… So out of all this I came out with increased efficiency.

FDT might still be a very good tool, mostly if you are already familiar with Eclipse, but for me FlashDevelop is still the way to go. If  FlashDevelop gets a Debugger than I won’t even ask myself the question.

, , , ,

8 Comments


Loading a COLLADA model without loading a file

You know what is funny? It’s when every project your doing what was cool 2 years ago. Yeah I have been doing a lot of Papervision3D lately, but you know what, I’m fine with it, I actually like it. Anyway, I think Augmented Reality is retarded (ok not that much, but fun to say). So I’m doing all that 3D and usually it’s easier to just load COLLADA models, mostly because you get more complex shapes and the texturing is also easier, all done by the 3D artist. That also help with the workflow, 3D guy does his thing Flash guys does his and they can work at the same time, which is great.

Normally I would just load the DAE file externally, it’s just an xml file but some times it can get quite big. For the project I am currently working on, (stay posted this one is going to be great) I have a lot of very small models, like a lot (omg I sound like the 10 years old daughter I don’t have). So I can’t load all of them externally because this would make too many server call which would in return slow my application greatly. It is not well know (maybe Flex developer knew this more) but you can embed the DAE file inside your SWF by using the Flex embed tag, now available in Flash CS4. I found this info on the pv3d.org site. Here is the code:

[Embed(source="../../../../../assets/domino.dae", mimeType = "application/octet-stream")]
private var daeAsset:Class;
 
var byteArray:ByteArray = new daeAsset() as ByteArray;
var _dae:DAE = new DAE();
_dae.load(byteArray);

Well that is pretty cool and it saves you some loading time and server calls. What I don’t like with the embed tag is that the path to your asset is relative to the class file path not to the project, so sometime it is very tedious to find the right path.

Now let say you were generating textures at runtime (you guessed right, that is what I am doing) you still need to put a listener on the DAE to know when the load is completed, because even though it’s faster than loading an external file it’s still not instantaneous. Here is the full code:

[Embed(source="../../../../../assets/domino.dae", mimeType = "application/octet-stream")]
private var daeAsset:Class;
 
var byteArray:ByteArray = new daeAsset() as ByteArray;
var _dae:DAE = new DAE();
_dae.addEventListener(FileLoadEvent.LOAD_COMPLETE , _daeLoadComplete, false, 0, true);
_dae.load(byteArray);
 
function _daeLoadComplete(event:FileLoadEvent):void {
  event.target.removeEventListener(FileLoadEvent.LOAD_COMPLETE, _daeLoadComplete);
  var child:DisplayObject3D = _dae.getChildByName("modelName", true) //modelName is the name of the shape the was outputted from your 3D program, you can see that name in the trace from Papervision3D
 
  var bitmapMaterial:BitmapMaterial = new BitmapMaterial(_texture, true);//_texture is you runtime generated bitmapData
  child.material = bitmapMaterial;
}

Ok, only 4 more articles to write to remove the annoying roar4milk widget from my homepage (the reason for the sudden music).

, , , , , ,

3 Comments


I am now Google Analytics Qualified

Well since last week and I got a whooping score. You might ask why I spent time to do this certification (Google Analytics Individual Qualification test), well, I think it is better to have more than one tool in your pocket and it also shows that you think of the big picture and not just about code. Analytics is also a very in demand skill along with Flash and SEO so it could not hurt. I didn’t know if I truly used GA correctly, now I guess this says I’m not so bad at it.

gaCertificate

Here are a couple of tips to help yourself on the test: first I hope you have played a bit with Google Analytics that will help a great deal! Secondly whatch all the videos in the conversion university. Not only do they help a great deal for the test, but they are very instructive and well done. Having knowledge of Adwords will also help a lot since a third of the questions will be on the topic of integration of Adwords and Google Analytics (some plainly on Adwords!!).

Go get certified now while I look for synonyms for the word “also”.

, , , , ,

2 Comments


Trying FDT for a month

Ya I will be leaving my beloved Flash Develop to try out FDT for a month. I have been hearing a lot of good things about it and the programing department has been pushing to get everybody on Eclipse. I have tried Flex Builder before (ok, it was version 2) but I was not very impressed. Every thing seemed complicated for nothing. What I really like about Flash Develop is that it is so simple. To get you going it take 10 minutes and it is more user friendly than Eclipse (it takes less step to do something simple like start a project).  Also it is easier to get Animators who are more designer in spirit to use it.

But I at least want to give it a try, so that is what I will be using (almost) exclusively for the next month. The month after I will try Flash Builder 4 and compare it. That way I will be able to make a good decision about wich editor to use.

I have started using FDT today and I have already bumped into two problems: first a simple trace doesn’t trace in the console even in debug mode (in the FCHS console and the FDB console whatever these are). Secondly the SWFViewer doesn’t seem to be the Debug player so I don’t see the runtime errors. These might be related problems and should be easy enough to fix, but it should be more obvious than it is right now.

If you know any tutorial about FDT, send them my way, I want to know everything I can about it during that month; I will read everything!

, , , , ,

5 Comments


How to load a YouTube movie into Flash using TubeLoc

I have written this article a while back for FFDMag, but I thought I would put it here also. It lost a bit of relevance because YouTube now has an AS3 API for its player, but if you work on a project that uses TubeLoc, I think this article can be useful.

What you should know:
- Basic knowledge of ActionScript
- Basic knowledge of YouTube

What you will learn:
- How to load YouTube videos into Flash
- How to use the TubeLoc library to control those videos

Embedding a YouTube movie in an HTML page is an easy task, but we can’t say the same about embedding a YouTube clip in a Flash/Flex website. TubeLoc, an opensource library, is there to make that easier.

Before TubeLoc, you could always go and try to find the address of the FLV the YouTube player is loading and load that FLV directly into your Flash application, but YouTube changes the address almost every night, so it wasn’t a very long term solution. Another problem that TubeLoc solves is the fact that the YouTube player is made in ActionScript 2 and most projects now are using ActionScript 3, so it was hard interfacing with the player. TubeLoc is a wrapper around the the AS2 player and show us an AS3 API, but behind the scene it handles the YouTube player using local connection.

To get started with TubeLoc you will first need to download the library at this address:

http://code.google.com/p/tubeloc/

There you will also find a great demo showing you what you can do with the library. You can pause, stop, play, mute, seek, change the volume, change the the size of the video and even load the video without the YouTube player chrome (so you won’t see the play button from YouTube the only thing that will be there is the YouTube logo at the bottom right of the video).

In the zip file that you download from the previous url, copy the “com” folder located in the “as3/src” folder in the same directory where your FLA will be. Also copy there the file as2_tubeloc.swf from the folder “as3/lib”. Now we can get coding. Here is all that is needed to load a YouTube movie into Flash:

import com.enefekt.tubeloc.MovieSprite;
import com.enefekt.tubeloc.event.*;
 
var youtubeMovie:MovieSprite = new MovieSprite(null, true);
youtubeMovie.addEventListener(PlayerReadyEvent.PLAYER_READY, onPlayerReady);
addChild(youtubeMovie);
 
function onPlayerReady(event_p:PlayerReadyEvent):void {
//it's just cleaner to remove listener that won't be used again
youtubeMovie.removeEventListener(PlayerReadyEvent.PLAYER_READY, onPlayerReady);
 
//you can set the size of the movie this way
youtubeMovie.width = 370;
youtubeMovie.height = 276;
 
youtubeMovie.loadVideoById("tprMEs-zfQA");
}

The first lines import the library from the “com” folder we copied. After that it creates the MovieSprite. The first parameter is the id of the YouTube movie, since I will set that later I can just pass null to it. The second parameter is if I want to use the chromeless player, in this case I set it to true. The chromeless player is usefull when you want the video player to have control that are similar to the rest of your application. It is also usefull when you want to put your video under a mask to escape the traditonnal square look of videos. If we continue with the code, after we created the MovieSprite, we have to wait for the player to be initialized to go on that’s why we put an event listener on the MovieSprite(youtubeMovie). Once the listener function is called, all that is left to do is call the loadVideoById method. Finding a video id from YouTube is really easy; if the url of the video you want to load looks like this:

http://www.youtube.com/watch?v=tprMEs-zfQA

Than your id is only the last part : “tprMEs-zfQA”.

Now if you want to control your video all you have to do is :

//this will pause the video
youtubeMovie.pauseVideo()
 
//this will make it play again
youtubeMovie.playVideo()
 
//to mute the video
youtubeMovie.mute()
 
//to set the volume to half of maximum
youtubeMovie.setVolume(50)
 
//to seek in the video to 20 seconds
youtubeMovie.seekTo(20)

Well that is all it take to load a YouTube movie into Flash. I should warn you of some pitfalls; by reading the issues on the google code page, there seems to be problems with loading multiple videos at the same time. Also, destroying an instance of a MovieSprite seems to inhibit you from creating another one after so you should always keep an instance of you MovieSprite alive. Aside from that TubeLoc is an awesome library and I hope to see the proliferation of YouTube videos inside of Flash!

, , , , ,

8 Comments