Rom__1
Messages postés3Date d'inscriptionmercredi 29 avril 2009StatutMembreDernière intervention30 décembre 2009
-
30 déc. 2009 à 14:49
Bonjour à tous,
Je cherche à appliquer individuellement une police au hasard sur chacun des mots contenus dans un tableau.
A chaque clic, une fonction s'occupe de choisir une police parmi 6 (cf dernière fonction), or pour l'instant, elle s'applique à l'ensemble des mots du tableau...
Voici mon code:
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import fl.transitions.Tween;
import fl.transitions.easing.Strong;
var words:Array=["life","magic","instinct","answer","mosdef","creation","wondering","why","sushi","police","advertising","never","serendipity"];
var texts:Array=[];
var couleur:ColorTransform = stage.transform.colorTransform;
var tab1 =new Array("Rosewood Std Regular","Contantia","Palace Script MT","ElHombre","Tunga","Tahoma");
var police="Arial";
trace(couleur);
for (var i:uint = 0; i<words.length; i++) {
var rX:Number=Math.random()*stage.stageWidth;
var rY:Number=Math.random()*stage.stageHeight;
texts[i]=createText(15+Math.round(Math.random()*10),words[i]);
addChild(texts[i]);
texts[i].x=Math.random()*stage.stageWidth;
texts[i].y=Math.random()*stage.stageHeight;
doTween(texts[i], Math.random()*5, rX, rY);
couleur.color = Math.random() * 0xFFFFFF; // couleur appliquée au hasard
texts[i].transform.colorTransform = couleur;
trace(texts[i]);
}
function createText(fontSize:uint, str:String):TextField {
var tf:TextField = new TextField();
tf.autoSize=TextFieldAutoSize.LEFT;
tf.selectable=false;
var tFormat:TextFormat=new TextFormat("Arial",fontSize);
tFormat.bold=true;
tFormat.font=police;
tf.defaultTextFormat=tFormat;
tf.text=str;
return tf;
}
function doTween(target:TextField, duration:Number, xPos:uint, yPos:uint):void {
new Tween(target,"x",Strong.easeInOut,target.x,xPos,duration,true);
new Tween(target,"y",Strong.easeInOut,target.y,yPos,duration,true);
new Tween(target,"alpha",Strong.easeOut,0,1,3,false); //gère la transparence de 0 à 1 sur 3s
//new Tween(target,"rotation",Strong.easeOut,0,90,3,false);
trace (target.y);
}
stage.addEventListener (MouseEvent.CLICK, declencheMouv);
stage.addEventListener (MouseEvent.CLICK, choixPolice);
function declencheMouv (e:MouseEvent){
for (var i:uint = 0; i<words.length; i++) {
removeChild(texts[i]); //efface l'ecran d'avant
var rX:Number=Math.random()*stage.stageWidth;
var rY:Number=Math.random()*stage.stageHeight;
texts[i]=createText(15+Math.round(Math.random()*10),words[i]);
texts[i].x=Math.random()*stage.stageWidth;
texts[i].y=Math.random()*stage.stageHeight;
doTween(texts[i], Math.random()*5, rX, rY);
couleur.color = Math.random() * 0xFFFFFF; // couleur appliquée au hasard
texts[i].transform.colorTransform = couleur;
addChild(texts[i]);
trace(words[i]);
trace(texts[i]);
}
}
function choixPolice (e:MouseEvent){
for(var k=0;k<6;k++){
police=tab1[Math.floor(Math.random()*6)];
}
}
trace(police);
Voilà ci quelqu'un pouviez se pencher sur la question ce serait vraiment sympa!