Yoan Blanc’s weblog

Another lost swiss guy

December 2007

Feed Flex with your HTML

Yoan BlancSun 09 December 2007, , , ,

Flash is still used for all the nice things an artist may want. A web developer must try to manage a progressive enhancement all the work he has to do. This implies that the semantic HTML comes first and the design arrives at the end., then add the JavaScript. Always test your page without JS, without CSS and without both of them.

What to do with a Flash movie? Couldn’t we do the same? HTML then Flash. I did that on the PhotoViewer you may find in the Flex2 SDK samples directory and it’s easy. The PhotoViewer is using a XML file to build the gallery.

<?xml version="1.0" ?>
<galleries>
 <gallery id="">
  <description></description>
  <photo>
   <description></description>
   <name></name>
   <source></source>
  </photo>
  <!-- more -->
 </gallery>
</galleries>

From my point of view, it’s like if a photo carousel module was doing a XHR call to get the picture, we have the HTML already, let’s (re)use it:

<div id="galleries">
 <div class="gallery" id="">
  <h2></h2>
  <div class="photo">
   <h3></h3>
   <img src="" alt="" />
  </div>
  <!-- more -->
 </div>
</div>

Instead of having the PhotoViewer doing another HTTP call to get the XML file above, the idea is to build a JSON object from the HTML and passing it to the Flash movie. The goal of that manipulation is to have a better referencement of our slideshow (SEO rules), an usable version for people without JavaScript (I bet you’re already using JavaScript to include the Flash movie in your page).

The next exemple will use jQuery for it’s readability (a native code is easy too but is more consequent) to extract the data out of the HTML:

var data = [];
jQuery("#galleries .gallery").each(function() {
 gal = {
  id: this.id,
  description: $("h2").get(0).value,
  photo: []
 };
 $(".photo").each(function() {
  var img = $("img", this).get(0);

  gal.photo.push({
   name: $("h3", this).get(0).value,
   source: img.getAttribute("src"),
   description: img.getAttribute("alt")
  })
 });
 data.push(gal);
 this.parentNode.removeChild(this)
});

Using json2.js (courtesy of Master of us Douglas Crockford), this data array can be given to the Flash Movie via the flashvars parameter.

var flashvars = "json="
 + encodeURIComponent(
  JSON.stringifiy(data)
 );

Now, let’s dive into the ActionScript 3 (Flex) source code to see how to use this, JSON comes with as3 corelib.

// PhotoViewer.mxml
var json:String = Application.application.parameters.json;

// samples.photoviewer.JSONPhotoService
var data:Array = JSON.decode(json);
var temp:ArrayCollection = new ArrayCollection();

for(var i:int=0; i<data.length; i++) {
 temp.addItem(new Gallery(data[i]));
}
galleries = temp;

And what is absolutely brilliant about that is the fact that the XML interface for values, arrays, etc… is the same that the object generated by the ActionScript JSON decoder. You can reuse your existing code that is reading the XML file. Email me to get the PhotoViewer that is using the JSON code, the end user license doesn’t authorize me to publish it here unfortunately.

The benefits of that approach I can see are many:

  • Maintenance, always painful and annoying, the only file you have to modify here is the HTML gallery;
  • SEO, no more invisible pages from the search engine robots point of view, every informations is be available for them;
  • Reusability, maybe putting the most of the informations out of the Flash movie will improve the reusability of it for sure.

And the biggest one, is that you can replace the Flash movie by a JavaScript only module if you want. I don’t like those big blinky modules that offer most a the time a painful user experience.

Flash est toujours utilisé pour réaliser des jeux ou de jolis modules offrant une interaction et un look que les designers chérissent. En tant que développeur, développeur web, je déteste refaire de l’existant et suis sensible à offrir le contenu au plus grand nombre (les moteurs de recherche venant en tête de liste). Un autre principe, d’amélioration progressive, veut qu’une page se construit de sa sémantique à son apparence afin d’être sûr que le plus important prime: le contenu. Ce qui se teste assez simplement en désactivant le JavaScript, les feuilles de styles (CSS) ou les deux par la suite.

Il y a différents moyens d’offrir un contenu alternatif à une animation Flash, le plus simple étant purement HTML d'ailleurs. Mais vu que la majorité des animations sont inclues dans la page via un bout de JavaScript (pour éviter le “cliquez ici pour activer”) comme SWFObject ou autre, autant se servir du même contenu alternatif pour nourrir l’animation Flash, non? Une autre remarque, étant qu’un comportement à la mode va faire qu’une animation Flash télécharge un fichier XML comprenant le contenu à afficher. Ce contenu présent dans le fichier XML doit être lié au contenu alternatif. Une méthode naïve est que ce contenu alternatif soit fabriqué à partir du fichier XML lui-même, ça inclu une phase de compilation de l’HTML. Pourquoi ne pas prendre le chemin inverse ne nécessitant pas de fichier tier faisant doublon, en nourrissant l’animation Flash avec le contenu HTML directement.

Pour nos amis anglophones, le développement dans la partie qui vous être consacrée. Le principe étant de contruire un objet JSON passé comme argument lors de l’affichage de l’animation Flash (ici un slideshow photographique: PhotoViewer). Apparemment, l’interface pour naviguer au sein d’un document XML est la même que celle pour des objets natifs, ceux obtenus à la lecture du JSON. Donc, je n’ai pas eu à réécrire la classe Gallery du PhotoViewer (dans les exemples du Flex2 SDK) pour qu’il n’utilise plus le noeud XML mais les données JSON.

Les avantages de ceci outre le fait que dès à présent votre animation Flash sera plus gentille pour vos visiteurs n’ayant pas JavaScript et/ou Flash activés (comme un moteur de recherche) sont une maintenance plus facile n’ayant plus qu’un document ayant le contenu et une meilleure réutilisation possible de cette animation Flash (qui contenait auparavant pour l’exemple de Flex, l’adresse du fichier XML à lire).

Il y a certainement mieux à faire dans ce domaine, mais si une animation Flash comme un module JavaScript peuvent venir dans une logique d’amélioration progressive, l’environnement web tel que nous le connaissons sera meilleur pour tout un chacun.

2007 back in the mirror

Yoan BlancMon 31 December 2007, , , , ,

Dear God, this year went so fast, I still can feel the coldness of past January that I already have to look at the promising next year. At the beginning of this year, I’ve said “Past, present and future” and really think I can say that again because I’m at the same place, not in the same location thought. I like to do that kind of retrospective because I believe that what I am it more and more related to what I’ve done.

One year ago, I was living with Batiste and Eve in Lausanne (Switzerland) in a very lovely flat-sharing. And because the three girls next door weren’t very friendly (this is a private joke), I was already in the mood of moving from there to somewhere else (nice or not). Then I’ve met someone very keen who show me that I was deserving that change so I got the strength to search actively. By the way, I owe him a hot chocolate (and the interests).

From this point, everything went pretty fast, Eve left and Louisa took her place and cooked many very delicious deserts (nothing compared to Eve’s strange dishes). I saw this on my blogmarks’ friends page, blogmarked by a future Yahoos and now colleague, applied, got one phone call, one little homework, a very interesting interview in Paris and left Electron Libre. One funny thing was that I’ve had to achieve the homework the weekend of the carnival of Romont and as you may know a carnival meant usually a lot of beer, white wine and very few and definitively not quite sleep. So to be able to do in on the Sunday afternoon in good conditions I didn’t drink a single drop of alcohol. The other members of the Guggenmusik (the name of the band that are playing for Carnival in Switzerland and Germany, usually out of loud, Los Clodos the most famous one in Valais) were astonished to see me like that because I used to drink way too much. And I don’t drink to the next carnival as well and don’t drink anymore even if we celebrate various things with some champaign in those weeks.

Then, I moved to Paris in a two days road trip with my grand father and started on the Eurosport project that the Yahoo! office there in April. It wasn’t easy because the whole team was working all their best to get the new version out as soon as possible and we made it. It was hard because everything was new from a professionnal point of view: the language (Perl), the system (OSX), the text editor (Vi(m) in the early days and now combined with TextMate when I’m lazy), a great and distributed team, a working agile methodology (FTW) and nobody was understanding my swiss french accent. But I worked my best to get into what they expected me to. Victor learned me some nice bits of Perl, Mark to love JavaScript even more, Mike that you cannot care enough about accessibility, Pierre what being pragmatic really means, Jon to not forget to be nice with your workmates and many other guys more slang words in both french and english.

I’m since then living alone, in my own studio in the 10th arrondissement of Paris (capitale de l’Amour isn’t it?) and it wasn’t easy because you have to be in a good mood with yourself to cook dinner, wash the dishes, iron the clothes, clean the place and so on. No one else will help you on any of these tasks or tell you to do them. It’s a real pleasure to live this way even if some day you really want to watch someone else cooking you something for the dinner while you’re promising to do the washing up afterwards. And cooking for one is sometimes a non sense and a lot of wasted energy. At the beginning I was missing to be with someone else so I wrote a lot about that and bumped (it’s not how it happened but I like this expression) into her at a Lense. It didn’t happen in the early days but this little romance was enjoyable somehow. It had the taste of the South of the France: the sun, ice-creams, backeries. We are in different realities and I still like to talk with her on that field.

Paris is full of personalities you have to meet, to chat with, to discover. I’ve had the opportunity to do that with some of them, bloggers, photographs, artists. You have also here many places to eat yummy dishes, to listen to great artists, to rest in the grass in sunny Sunday afternoon and so many streets I don’t know the name but I will remember for their shops, buildings and graffitis (or as I like to call that street art).

This year I also made a lonely and kind of crazy trip to Peja (Kosovo) for a friend of mine’s wedding. Only because I still have to understand what a wedding is or can be, because that word have some many facets. During the few days I spent in Switzerland since I’m living here, I heart to spend time with people I care about and they are over there: mother, brother, grand father, close friends. But you don’t have to abuse of the good things, right?

Now, what I want for 2008, the same in better. More cool experiences, more places to discover, more people to meet, more love to the one I want to give some. In a professional manner, I want to build websites back. If I have skills, I want my ideas to become useful as well. At this moment I don’t where all this will drive me but I hope that it’s a lovely road to there.

Et voilà une année de passée, à une vitesse incroyable me donnant l’impression d’avoir écrit ce petit bilan de l’année 2006 il y a 3 mois seulement. J’avais choisi le titre: « présent, passé et futur » et je pense que je pourrais à nouveau m’en servir car si je ne suis pas au même endroit, je me sens dans une situation identique ou du moins semblable.

Chiche!

Il y a un an, je vivais à Lausanne en colocation avec Eve et Batiste, travaillais pour Electron Libre à Lausanne bien que m’étant baladé entre Lausanne et Prilly sac au dos. Mon envie initiale de prendre le large revenant de plus en plus fortement, j’ai commencé à tâtonner, jusqu’à qu’on me confirme que c’était ce qu’il me fallait. (Je te dois un chocolat chaud plus les intérêts d’ailleurs.)

Puis les choses sont allées assez vite, Eve est partie laissant la place à Louisa et ses desserts minutieusement préparés, Robin et Gaël sont venus dans le quartier, j’ai drastiquement réduit ma consommation d’alcool initialement pour le devoir qui m’a permis de me retrouver ici aujourd’hui; puis durablement.

Faire l’aller-retour en un week-end avec comme co-pilote son grand-père pour venir installer ses affaires dans le grand Paris était d’une certainement manière magique. Ensuite le départ réel un peu particulier, un mélange d’excitation et de peur. Ensuite, il n’a pas été tout simple de se faire à la vie en solitaire dès le début, c’est parfois bien d’avoir un poteau sur lequel se repose pour exprimer ce qu’on vit ou s’occuper d’une tâche qu’on aurait pas envie de se coltiner. Je crois m’être raccrocher à ce que j’ai pu dans les premiers mois, le temps pour la machine de se mettre en place.

Côté boulot, il m’a fallut plonger dans un projet en cours, proche d’être suffisamment abouti pour partir en production, dans une équipe existante, se trouvant sur différents sites, et de taille conséquente. Et pour corser les choses, un nouveau langage de programmation (pour moi), un nouveau CMS, une framework JavaScript que j’avais effleuré du doigt, et tout un tas de nouveaux mots d’argot tant francophone qu’anglophone. Même si la plus grande chose que j’ai pu apprendre étant de travailler à plus de 3, selon une (tant attendue) méthodologie agile, avec des deadlines et des specifications. Dieu que c’est bon même si l’industrialisation de tout ce processus “créatif” me laisse un peu dubitatif finalement.

Sinon Paris est rempli de joli coin où l’on peut manger, se balancer sur un riff de guitare, se détendre sur un gazon tendre, manger une glace à s’en mettre sur le nez. Il y a également tout ces gens qu’on ne regrette pas d’avoir croisé, pour une rire, un rictus, une discussion, un regard, un baiser ou l’envie d’un baiser (car au fond de ce grand dadet, un timide se terre). J’ai adoré pagayé évitant les pirates de mauvaises augures, danser jusqu’au petit matin prenant types aux gars un peu trop amicaux, marcher dans la nuit retrouvant finalement le chemin du lit.

Et voilà, mes pieds sont ici, à Paris, ma tête est ailleurs ou à la recherche de cet ailleurs et mon cœur, ceux qui comptent fortement pour moi sont dans ces lieux où j’ai vécu, grandit, appris, aimé. Partir (même si j’ai pu employer le verbe fuir) n’est pas une forme de rejet de tout ce qui fait ce que je suis aujourd’hui, mais une forte prise de recul qui permet d’y voir clair, de se consacrer pleinement à ce qui compte pour le peu de temps que je passe là-bas (même si je manque un peu d’organisation encore­…). Je n’ai pas terminé le chemin qui me permettra d’être bien avec moi-même, avec ce que je fais au quotidien comme avec quelqu’un d’ailleurs. Donc je me souhaite plein de belles rencontres, retrouvailles, expériences, d’endroits à découvrir, apprivoiser et d’un point de vue professionnel, un environnement où non seulement mes compétences sont reconnues, mais où mes idées peuvent grandir, intéragir, vivre.

2008, je te souhaite la bienvenue.

About

meYoan Blanc is a web developer that lives in Norway (Markveien 24, 0554 Oslo) works for Opera and comes from La Chaux-de-Fonds. This web site is for this weblog, a playground for random stuffs and can help keeping me connected with some friends out there.

Get my vCard or contact me by phone (skype:yoan.blanc) or email ().

Misc

RSS, list.blogug.ch

This site reflects only my opinion and is not affiliated with anyone else.

copyright 2006-2009 — doSimple.ch