<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
	<title>Flux RSS des 10 dernières soumissions</title>
	<link><![CDATA[http://forums.mediabox.fr/index.php?app=downloads&module=search&section=search&do=last_ten]]></link>
	<pubDate>Wed, 22 Feb 2012 19:47:56 +0000</pubDate>
	<ttl>1800</ttl>
	<description>Ceci est le flux RSS des dix derniers fichiers soumis acceptés dans notre base de données. Ce flux RSS est automatiquement mis à jour.</description>
	<item>
		<title>ImportSVG</title>
		<link>http://forums.mediabox.fr/files/file/5-importsvg/</link>
		<description><![CDATA[Bonjour,<br />
<br />
Cette bibliothèque AS3 permets d'importer des fichiers au format SVG et SVGZ en provenance du logiciel Inkscape (Testé avec la version 0.48)<br />
<br />
Elle possède les caractéristiques et fonctionnalités suivante :<br />
<br />
- Gestion des chemins<br />
- Gestion des rectangles<br />
- Gestion des cercles<br />
- Gestion des bitmap<br />
- Gestion des contours et remplissage<br />
- Gestion des types de terminaisons<br />
- Gestion des types d'intersections<br />
- Gestion des dégradés linéaires et radiales<br />
- Gestion les flou x et y liés et non liés<br />
- Respect de la structure des calques/sous-calques/groupe<br />
- Gestion des noms des calques<br />
- Renvoi un signal indiquant la progression du traitement par l'api Flash<br />
- Benchmark intégré<br />
- Possibilité de modifier l'ordre des calques<br />
- Conversion en bitmap<br />
- Renvoi un MovieClip encapsulant d'autres MovieClip correspondant chacun à un des calques du SVG<br />
<br />
------------------------------------------------------------------------------------------------------------------------------------<br />
Avant propos.<br />
Pour fonctionner pleinement ImportSVG utilise deux autres bibliothèques :<br />
<br />
	  //Permets de décompresser le format svgz<br />
	  gzip (<a href='http://probertson.com/projects/gzipencoder/' class='bbc_url' title='Lien externe' rel='nofollow external'>http://probertson.co...ts/gzipencoder/</a>)<br />
<br />
	  //Permets la lecture des images bitmap intégrées dans inkcape<br />
	  B64 (<a href='http://jpauclair.net/' class='bbc_url' title='Lien externe' rel='nofollow external'>http://jpauclair.net/</a>)<br />
<br />
J'ajoute à cette bibliothèque un fichier de test nommé Lama.svg<br />
<br />
<br />
<strong class='bbc'>Préparer un fichier SVG ou SVGZ :</strong><br />
<br />
Lors de l'enregistrement de votre dessin dans Inkscape choissisez l'une des deux options suivantes :<br />
<br />
<em class='bbc'>// Il s'agit d'un format classique</em><br />
- SVG Inkscape(*.svg)<br />
<br />
<em class='bbc'>// Il s'agit d'un format compressé</em><br />
- SVG Inkscape compressé(*.svgz)<br />
<br />
------------------------------------------------------------------------------------------------------------------------------------<br />
<br />
<strong class='bbc'>Utilisation :</strong><br />
<br />
<strong class='bbc'>1/</strong> Pour importer un fichier voici les étapes nécéssaires.<br />
<br />
- créer une classe nommé "Main" qui étend la classe MovieClip<br />
- importer la classe ImportSVG<br />
- instancier la classe ImportSVG<br />
- charger notre fichier (ici dans le répertoire svg/Lama.svg)<br />
- ajouter la classe dans la liste d'affichage<br />
<br />
En code cela donne :<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
package <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> importSVG.<span style="color: #006600;">ImportSVG</span>;<br />
<br />
&nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _Svg:ImportSVG;<br />
&nbsp; &nbsp;<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//Création de l'object<br /></span>
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> _Svg:ImportSVG = <span style="color: #000000; font-weight: bold;">new</span> ImportSVG<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//On Charge le fichier<br /></span>
&nbsp; &nbsp;_Svg.<span style="color: #006600;">Chargement</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"svg/Lama.svg"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//svg et svgz acceptés<br /></span>
&nbsp; <br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//Affichage<br /></span>
&nbsp; &nbsp;addChild<span style="color: #66cc66;">&#40;</span>_Svg<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div></div></div><br />
<br />
<span rel='lightbox'><img src='http://www.screenart-graphiste.com/MediaBox/Lama.jpg' alt='Image IPB' class='bbc_img' /></span><br />
<br />
<br />
De la même manière, pour traiter un fichier svgz il vous suffit de le spécifier dans l'extension.<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//On Charge le fichier<br /></span>
&nbsp; &nbsp;_Svg.<span style="color: #006600;">Chargement</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"svg/Lama.svgz"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//svg et svgz acceptés<br /></span>
&nbsp;</div></div></div><br />
<br />
<br />
<strong class='bbc'>2/ </strong>Différentes options sont disponibles.<br />
<br />
<strong class='bbc'>a/</strong> Benchmark<br />
<br />
Cet appel de fonction renvoie dans un "trace()" le temps de traitement. Le code doit se placer entre l'instanciation de la classe et le chargement du fichier tel que l'exemple suivant :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<br />
<span style="color: #808080; font-style: italic;">//Création de l'objet<br /></span>
<span style="color: #000000; font-weight: bold;">var</span> _Svg:ImportSVG = <span style="color: #000000; font-weight: bold;">new</span> ImportSVG<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//Benchmark intégré<br /></span>
_Svg.<span style="color: #006600;">Bench</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Affichage en ms dans un trace<br /></span>
<br />
<span style="color: #808080; font-style: italic;">//On importe -- (inclus le traitement des données)<br /></span>
_Svg.<span style="color: #006600;">Chargement</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"svg/Lama.svg"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//svg et svgz acceptés<br /></span>
<br />
<span style="color: #808080; font-style: italic;">//Affichage<br /></span>
addChild<span style="color: #66cc66;">&#40;</span>_Svg<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div></div></div><br />
<br />
<em class='bbc'>En fonction des capacité de calcul de l'ordinateur client le temps sera plus ou moins rapide. Chez moi cela affiche : </em><br />
<em class='bbc'>Temps de traitement : 1806.ms</em><br />
<br />
<br />
<strong class='bbc'>b/</strong> Traitement partiel<br />
<br />
Il convient de différencier 3 étapes :<br />
- le chargement<br />
- le traitement<br />
- l'affichage<br />
<br />
A savoir que le fichier sera obligatoirement chargé dans sa totalité. Cependant une première fonction consiste à n'en traiter qu'une partie pour des raison d'optimisation. Pour cela nous utiliserons le nom des calques principaux. En effet, un calque peut posséder des sous-calques mais les noms de ces derniers seront ignorés.<br />
<br />
Ci-dessous la liste des calques du lama :<br />
<br />
<span rel='lightbox'><img src='http://www.screenart-graphiste.com/MediaBox/Lama_Calque.jpg' alt='Image IPB' class='bbc_img' /></span><br />
<br />
<br />
Nous avons accès à 4 calques principaux : Lama_Tete, Pierres, Boule, Lama Corps.<br />
<br />
Pour n'afficher que la tête et le corps nous écrirons le code suivant :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<br />
<span style="color: #808080; font-style: italic;">//Création de l'object<br /></span>
<span style="color: #000000; font-weight: bold;">var</span> _Svg:ImportSVG = <span style="color: #000000; font-weight: bold;">new</span> ImportSVG<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//1-Traite et affiche une partie des calques (noms des calques définis dans inkscape)<br /></span>
_Svg.<span style="color: #006600;">TraitementCalque</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Lama Tete"</span>, <span style="color: #ff0000;">"Lama Corps"</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//On importe<br /></span>
_Svg.<span style="color: #006600;">Chargement</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"svg/Lama.svg"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//svg et svgz acceptés<br /></span>
<br />
<span style="color: #808080; font-style: italic;">//On affiche<br /></span>
addChild<span style="color: #66cc66;">&#40;</span>_Svg<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div></div></div><br />
<br />
<span rel='lightbox'><img src='http://www.screenart-graphiste.com/MediaBox/Lama_Partiel_0.1.jpg' alt='Image IPB' class='bbc_img' /></span><br />
<br />
<em class='bbc'>! Bien entendu les sous-calques correspondants aux calques principaux sont affichés.</em><br />
<br />
Pour mesurer l'efficacité de cette option nous pouvons ajouter le Benchmark de l'étape <strong class='bbc'>a</strong>.<br />
Chez moi le résultat est :<br />
Temps de traitement : 661.ms. Nous avons donc gagné environs 1 seconde grace au traitement partiel.<br />
<br />
<strong class='bbc'>c/</strong> Affichage partiel<br />
<br />
L'affichage est une option qui intervient après le traitement. Par défaut nous aurons donc un traitement de l'ensemble du graphisme. Ce n'est donc pas une option d'optimisation.<br />
L'interêt de cette option est de n'afficher qu'une partie du graphisme mais en conservant l'ensemble du graphisme dans le MovieClip. Par le suite nous verrons qu'il est possible de réafficher les parties ainsi caché. Cela peut se révéler utile pour l'animation.<br />
<br />
Cette option se place comme les autres entre l'instanciation de la classe et le chargement. On utilise le nom des calques principaux d'Inkscape. (plus d'explication dans le "<strong class='bbc'>b</strong>/ Traitement partiel")<br />
<br />
Le code est le suivant :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<br />
<span style="color: #808080; font-style: italic;">//Création de l'object<br /></span>
<span style="color: #000000; font-weight: bold;">var</span> _Svg:ImportSVG = <span style="color: #000000; font-weight: bold;">new</span> ImportSVG<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//Affiche une partie des calques (noms des calques définis dans inkscape)<br /></span>
_Svg.<span style="color: #006600;">AffichageCalque</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Lama Tete"</span>, <span style="color: #ff0000;">"Lama Corps"</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//On importe<br /></span>
_Svg.<span style="color: #006600;">Chargement</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"svg/Lama.svg"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//svg et svgz acceptés<br /></span>
<br />
<span style="color: #808080; font-style: italic;">//On affiche<br /></span>
addChild<span style="color: #66cc66;">&#40;</span>_Svg<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div></div></div><br />
<br />
Enfin, vous pouvez tester l'option <strong class='bbc'>a</strong>/ Benchmark pour vous rendre comptes que le temps de traitement correspond au traitement total.<br />
<br />
<strong class='bbc'>d/</strong> Respect de l'ordre d'origine<br />
<br />
Voici une option qui permets de redéfinir l'ordre d'affichage des calques.<br />
Pour l'activer il faut ajouter le code suivant :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
_Svg.<span style="color: #006600;">OrdreOrigine</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Defaut = true;<br /></span>
&nbsp;</div></div></div><br />
<br />
Cette option fonctionne en binome avec l'affichage partiel.<br />
Imaginons que l'on souhaite placer le calque "Pierres" devant le calque "Lama Tete", nous devrons utilisez l'affichage partiel en modifiant l'ordre des noms déclarés.<br />
<br />
Voici ce que vous devrez alors écrire :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">//Affiche une partie des calques (noms des calques définis dans inkscape)<br /></span>
_Svg.<span style="color: #006600;">AffichageCalque</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Lama Corps"</span>, <span style="color: #ff0000;">"Lama Tete"</span>, <span style="color: #ff0000;">"Pierres"</span>, <span style="color: #ff0000;">"Boule"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;</div></div></div><br />
<br />
avec l'option "_Svg.OrdreOrigine(true)", l'affichage aurai été le même, mais avec l'option à "_Svg.OrdreOrigine(false)" voici le résultat :<br />
<br />
<span rel='lightbox'><img src='http://www.screenart-graphiste.com/MediaBox/Lama_OrdreOrigine.jpg' alt='Image IPB' class='bbc_img' /></span><br />
<br />
Les oreilles du lama sont bien derrière la structure en pierre.<br />
<br />
<br />
<strong class='bbc'>e/</strong> Conversion Bitmap<br />
<br />
Deux options sont permises.<br />
<br />
1- Nous allons commencer par la copie de l'image affiché en bitmap. Ce dernier sera encapsulé dans un MovieClip comme précédement mais nous perdrons la structure par calque expliqué dans le chapitre des <strong class='bbc'>f</strong>/ Les Evènements.<br />
<em class='bbc'>Pour rappel un affichage Bitmap demande moins de ressources processeur qu'un affichage vectoriel en contrepartie de l'utilisation de plus mémoires.</em><br />
<br />
Voici la manière de déclarer la copie en Bitmap entre l'instanciation de la classe et le chargement :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<br />
<span style="color: #808080; font-style: italic;">// Conversion en bitmap<br /></span>
_Svg.<span style="color: #006600;">ToBitmap</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Créer une copie bitmap à la taille originale du svg<br /></span>
&nbsp;</div></div></div><br />
<br />
2- Il est possible de demander à flash de placer en mémoire une image bitmap temporaire correspondant au vecteur. On gagne ainsi en performance à l'affichage tout en conservant son image vectoriel. Cette option particulière est documenté ici : <a href='http://help.adobe.com/fr_FR/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#cacheAsBitmap' class='bbc_url' title='Lien externe' rel='nofollow external'>http://help.adobe.co...l#cacheAsBitmap</a><br />
<br />
Pour l'activer vous devrez ajouter le code suivant :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">// Conversion en bitmap<br /></span>
_Svg.<span style="color: #006600;">ToBitmapCache</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Créer une copie bitmap en cache qui se réadapte lorsque le clip subit une transformation<br /></span>
&nbsp;</div></div></div><br />
<br />
<strong class='bbc'>f/</strong> Les Evènements<br />
<br />
Jusque là nous avons affiché notre fichier SVG/SVGZ sans avoir le moyen de savoir à quel moment l'affichage du vecteur aurait lieu.<br />
Voici de quoi palier à cela.<br />
<br />
1/ onSvgComplete<br />
Cette fonction va nous permettre d'avoir un signal pour dire à quel moment le MovieClip contenant le SVG est prêt à être affiché.<br />
Nous devons ajouter un écouteur à notre classe ImportSVG pour entendre le signal, voici le code à ajouter entre l'instanciation de la classe et le chargement du fichier :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
_Svg.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"SVGComplete"</span>, onSvgComplete<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Ensemble des opérations terminées<br /></span>
&nbsp;</div></div></div><br />
<br />
Si vous n'êtes pas familier avec les écouteurs, je vous invite à vous documenter.<br />
Pour les autres vous aurez compris que nous appelons la fonction onSvgComplete une fois le MovieClip prêt.<br />
! Attention nous devrons procéder à quelques modifications sur le code précédent<br />
- Dabord nous ajoutons les classes nécessaire à l'utilation des évènements :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">ProgressEvent</span>;<br />
&nbsp;</div></div></div><br />
<br />
- Puis nous allons rendre accessible l'instance de classe ImportSVG par l'ensemble des fonctions de la classe Main et ainsi accéder à ses méthodes dans la fonction "onSvgComplete" :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _Svg:ImportSVG;<br />
&nbsp;</div></div></div><br />
<br />
- Ensuite nous enlèverons la ligne qui nous permettais auparavant d'afficher le MovieClip :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">//On affiche<br /></span>
addChild<span style="color: #66cc66;">&#40;</span>_Svg<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;</div></div></div><br />
<br />
- Puis nous ajoutons la nouvelle fonction. Seulement pour afficher le MovieClip nous n'afficherons plus directement la classe mais nous utiliserons une nouvelle méthode "GetClip();" :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">//Ensemble des opérations terminées<br /></span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onSvgComplete<span style="color: #66cc66;">&#40;</span>pEvt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"complete"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Affiche le message "complete"<br /></span>
<br />
<span style="color: #808080; font-style: italic;">//On récupère notre clip<br /></span>
<span style="color: #000000; font-weight: bold;">var</span> MonClip:<span style="color: #0066CC;">MovieClip</span> = _Svg.<span style="color: #006600;">GetClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//On l'affiche<br /></span>
addChild<span style="color: #66cc66;">&#40;</span>MonClip<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div></div></div><br />
<br />
Voici le code dans sa totalité :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
package <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; <span style="color: #0066CC;">import</span> importSVG.<span style="color: #006600;">ImportSVG</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//Outil<br /></span>
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">ProgressEvent</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _Svg:ImportSVG;<br />
<br />
&nbsp; &nbsp;<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//Création de l'object<br /></span>
&nbsp; &nbsp;_Svg = <span style="color: #000000; font-weight: bold;">new</span> ImportSVG<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; &nbsp;_Svg.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"SVGComplete"</span>, onSvgComplete<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Ensemble des opérations terminées<br /></span>
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//On importe<br /></span>
&nbsp; &nbsp;_Svg.<span style="color: #006600;">Chargement</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"svg/Lama.svg"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//svg et svgz acceptés<br /></span>
&nbsp; <br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; <span style="color: #808080; font-style: italic;">//Ensemble des opérations terminées<br /></span>
&nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onSvgComplete<span style="color: #66cc66;">&#40;</span>pEvt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <br />
&nbsp; &nbsp;<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"complete"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//On récupère notre clip<br /></span>
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> MonClip:<span style="color: #0066CC;">MovieClip</span> = _Svg.<span style="color: #006600;">GetClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//On l'affiche<br /></span>
&nbsp; &nbsp;addChild<span style="color: #66cc66;">&#40;</span>MonClip<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div></div></div><br />
<br />
2/ Manipuler les MovieClip en fonction de leur nom<br />
<br />
Pour compléter cette nouvelle fonction je vais vous montrer comment manipuler les calques qui se trouvent à l'intérieur du MovieClip.<br />
D'abord dans la fonction "onSvgComplete()" nous allons controler combien de Calques principaux possède notre MovieClip :<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>MonClip.<span style="color: #006600;">numChildren</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;</div></div></div><br />
<br />
Cette fonction affiche "4" pour notre lama.<br />
<br />
Nous pouvons constater que les calques sont nommés par le code suivant :<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>MonClip.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>MonClip.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>MonClip.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>MonClip.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;</div></div></div><br />
<br />
Nous pouvons aussi constater que si nous utilisons un affichage partiel, les autres calques sont toujours présents même s'ils ne sont pas affichés. Il suffit alors de manipuler leur valeurs alpha pour controler leur visibilité.<br />
Par exemple je ne souhaite afficher que la tête :<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
_Svg.<span style="color: #006600;">AffichageCalque</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Lama Tete"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;</div></div></div><br />
<br />
Dans ma fonction onSvgComplete je souhaite réafficher le corps :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">//Ensemble des opérations terminées<br /></span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onSvgComplete<span style="color: #66cc66;">&#40;</span>pEvt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
<span style="color: #808080; font-style: italic;">//On récupère notre clip<br /></span>
<span style="color: #000000; font-weight: bold;">var</span> MonClip:<span style="color: #0066CC;">MovieClip</span> = _Svg.<span style="color: #006600;">GetClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//On l'affiche<br /></span>
addChild<span style="color: #66cc66;">&#40;</span>MonClip<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> lng:<span style="color: #0066CC;">int</span> = MonClip.<span style="color: #006600;">numChildren</span>;<br />
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>lng; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>MonClip.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span> == <span style="color: #ff0000;">"Lama Corps"</span><span style="color: #66cc66;">&#41;</span> MonClip.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;">1</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div></div></div><br />
<br />
<br />
2/ onTraitementProgress<br />
<br />
L'évènement onTraitementProgress envoie régulièrement des signaux lors du traitement du SVG/SVGZ car cela peut prendre parfois plusieurs secondes.<br />
<br />
Pour l'utiliser on ajoute l'écouteur suivant entre l'instanciation de la classe et le chargement :<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
_Svg.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"SVGTraitementProgress"</span>, onTraitementProgress<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Progression de la phase de traitement<br /></span>
&nbsp;</div></div></div><br />
<br />
Puis nous ajoutons la fonction qui est executé lorsqu'un signal en envoyé :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">//Progression de la phase de traitement<br /></span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onTraitementProgress<span style="color: #66cc66;">&#40;</span>pEvt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>pEvt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">Pourcentage</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Affiche le pourcentage de traitement effectué<br /></span>
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div></div></div><br />
Nous pourrions ainsi créer une barre de traitement.<br />
<br />
3/ Itérations et optimisation<br />
<br />
La fonction "onTraitementProgress" à posé un problème inhérent au fonctionnement de l'Api de dessin de flash. En effet lors d'une utilisation intensive de cette Api, toutes actions dans le programme est alors momentanément stoppées. Cela stoppe à la fois les animations affichées, l'exécution de code ou la diffusion d'évènements. Pour palier à ce problème, un système d'arrêts très brefs du traitement à été mis en place afin de reprendre la main. Ces arrêts brefs sont contrôlés par une fonction qui s'appel IterrationBP avec une valeur associée (BP = barre de progression). La valeur indiquée correspond à un nombre d'arrêts brefs. Une valeur de 15 correspond à un arrêt bref tout les 15 vecteurs traités. Et de cette manière la barre de progression se mets à jour tout les 15 vecteurs traités.<br />
<br />
Pour régler cette option vous devrez écrire le code suivant entre l'instanciation de la classe et le chargement du fichier :<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">//L'api de dessin flash bloque l'affichage durant le traitement. Une solution à été trouvé pour conserver la main mais demande plus de ressources<br /></span>
<span style="color: #808080; font-style: italic;">//Itération de la barre de progression<br /></span>
<span style="color: #808080; font-style: italic;">//Moins la valeur est élevée plus souvent l'affichage sera rafraîchi<br /></span>
<span style="color: #808080; font-style: italic;">//IterrationBP(int);//Defaut 30<br /></span>
_Svg.<span style="color: #006600;">IterationBP</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Généralement entre 15 et 40<br /></span>
&nbsp;</div></div></div><br />
<br />
<em class='bbc'>! Faites des test avec le Benchmark pour optimiser la valeur</em><br />
<br />
<strong class='bbc'>g/</strong> Simple décompression d'un svgz<br />
<br />
Si l'on souhaites simplement décompresser son fichier SVGZ et ainsi récupérer un fichier de type XML vous pouvez utiliser l'appel à fonction suivant :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<span style="color: #808080; font-style: italic;">//On décompresse seulement<br /></span>
<span style="color: #000000; font-weight: bold;">var</span> MonXML:<span style="color: #0066CC;">XML</span> = _Svg.<span style="color: #006600;">Decompresse</span> <span style="color: #66cc66;">&#40;</span>MonURLLoader<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Accepte un ByteArray provenant d'un SVGZ<br /></span>
&nbsp;</div></div></div><br />
<br />
! Pour rappel un fichier SVG est écrit en language XML, donc manipulable simplement avec l'AS3<br />
<br />
<strong class='bbc'>h/</strong> Traitement sans chargement du fichier<br />
<br />
Si vous avez déjà votre propre bibliothèque de chargement vous serez sans doute interressé par cette option qui vous permettra de continuer à l'utiliser.<br />
Cette option évite le chargement et passe directement à l'étape de traitement. Pour cela il faut l'alimenter avec données de type XML. Cette option se couple très bien avec la simple décompression d'un SVGZ.<br />
<br />
Voici le code à placer :<br />
<br />
<div class="code2"><div class='code'><div class="actionscript" style="font-family:monospace;"><br />
<br />
<span style="color: #808080; font-style: italic;">//on traite seulement (si on passe par notre propre function de chargement)<br /></span>
_Svg.<span style="color: #006600;">Analyse</span> <span style="color: #66cc66;">&#40;</span>MonXML<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//Accepte un XML (Rappel un format SVG est un XML)<br /></span>
<br />
&nbsp;</div></div></div><br />
<br />
------------------------------------------------------------------------------------------------------------------------------------<br />
<br />
Pour finir je vous propose de constater l'utilisation de cette bibliothèque sur un projet concret :<br />
<a href='http://www.kibodio.com/games/bouge_ta_boule' class='bbc_url' title='Lien externe' rel='nofollow external'>http://www.kibodio.c.&#46;&#46;/bouge_ta_boule</a><br />
<br />
Vous pouvez observer que la barre de chargement est suivi de la barre de traitement. C'est donc une manière simple d'extérioriser ses graphismes et de les mettre à jour rapidement.<br />
<br />
+++]]></description>
		<pubDate>Fri, 27 Jan 2012 15:59:34 +0000</pubDate>
		<guid isPermaLink="false">5</guid>
	</item>
	<item>
		<title><![CDATA[Respiration d'un personnage (sans code)]]></title>
		<link>http://forums.mediabox.fr/files/file/4-respiration-dun-personnage-sans-code/</link>
		<description><![CDATA[<strong class='bbc'>Une simple interpolation pour simuler la respiration d'un personnage.</strong><br />
Simple… tout part du torse, le mouvement se transmet ensuite à la tête…]]></description>
		<pubDate>Mon, 23 Jan 2012 11:43:54 +0000</pubDate>
		<guid isPermaLink="false">4</guid>
	</item>
</channel>
</rss>
