lundi 13 juin 2011

(as3) random color - couleur aléatoire

  1. import flash.display.Sprite;  
  2. import flash.events.MouseEvent;  
  3. import flash.display.MovieClip;  
  4. import fl.motion.Color;  
  5. import flash.utils.Timer;  
  6. import flash.events.TimerEvent;  
  7.   
  8. var Rect:Sprite = new Sprite();  
  9. Rect.graphics.beginFill(0x000000,1);  
  10. Rect.graphics.drawCircle(100,100,50);  
  11. Rect.graphics.endFill();  
  12.   
  13. addChild(Rect);  
  14. // un fois cliquer le couleur de btn_mc se change  
  15.   
  16. var timerCouleur:Timer = new Timer(300,0);  
  17. timerCouleur.addEventListener(TimerEvent.TIMER,changeCouleur);  
  18. timerCouleur.start();  
  19.   
  20. function changeCouleur(te:TimerEvent):void{  
  21. trace("changeCouleur");  
  22. var randCouleur:Color = new Color();  
  23. randCouleur.setTint(Math.random() * 0xFFFFFF,1);  
  24. Rect.transform.colorTransform = randCouleur;  

(as3) charger un fichier CSS dans flash

  1. /*******/ Fichier "style.css" /********** 
  2. h1{ 
  3.  font-size:24; 
  4.  color:#FF0000; 
  5.  font-family:Comic Sans MS; 
  6.  font-weight:bold; 
  7. } 
  8.  
  9. a { 
  10.  font-size:12; 
  11.  color:#2428db; 
  12.  font-family:Verdana; 
  13.  text-decoration:underline; 
  14. } 
  15. a:hover { 
  16.  text-decoration:none; 
  17.  font-weight:bold; 
  18. } 
  19. /*******/ Fichier "style.css" /**********  
  20.   
  21. import flash.display.Loader;  
  22. import flash.text.TextField;  
  23. import flash.text.StyleSheet;  
  24. import flash.net.URLLoader;  
  25. import flash.net.URLRequest;  
  26. import flash.events.TextEvent;  
  27. import flash.events.Event;  
  28. import flash.events.IOErrorEvent;  
  29.   
  30. var fichierCss:StyleSheet = new StyleSheet();  
  31. var chargerCss:URLLoader = new URLLoader();  
  32. var zoneText:TextField = new TextField;  
  33.   
  34. chargerCss.load(new URLRequest("style.css"));  
  35. chargerCss.addEventListener(Event.COMPLETE,parseCss);  
  36.   
  37.   
  38. function parseCss(e:Event):void{  
  39.  fichierCss.parseCSS(e.target.data);  
  40.  zoneText.styleSheet = fichierCss;  
  41.  zoneText.width = 400;  
  42.  zoneText.height = 100;  
  43.  zoneText.addEventListener(TextEvent.LINK,lienClique);  
  44.    
  45.  zoneText.htmlText = "<h1>Mon Titre</h1><img id="test_img" src="img.png"> <a href="event:lirePlus">Lire plus</a>   <a href="#">Lien Normal</a>";  
  46.  addChild(zoneText);  
  47.  // pour charge une image apartire de la tag <img> de HTML  
  48.  var chragerImg:Loader = zoneText.getImageReference("test_img") as Loader;  
  49.  chragerImg.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,noImage);  
  50.  chragerImg.x = 160;  
  51.  addChild(chragerImg);  
  52. }  
  53. function noImage(erreur:IOErrorEvent):void{  
  54.  trace("l'image (img.png) n'existe pas");  
  55.  }  
  56. function lienClique(e:TextEvent){  
  57.  trace(e.text);  
  58.  } 

(as3) Lien html dans flash

  1. import flash.text.TextField;  
  2. import flash.events.TextEvent;  
  3.   
  4. var zoneText:TextField = new TextField;  
  5. zoneText.htmlText = "<a href="event:client">Jack</a>   <a href="event:directeur">Leonardo</a>";  
  6. zoneText.addEventListener(TextEvent.LINK,lienClique);  
  7. addChild(zoneText);  
  8. function lienClique(e:TextEvent):void{  
  9.  switch(e.text){  
  10.   case "client":  
  11.    trace("vous avez choisi jack");  
  12.   break;  
  13.   case "directeur":  
  14.    trace("vous avez choisi Leonardo");  
  15.   break;  
  16.   }  
  17.  } 

(as3) dupliquer arriere plan - duplicate background

  1. import flash.display.MovieClip;  
  2. import flash.display.Bitmap;  
  3. import flash.display.Loader;  
  4. import flash.display.BitmapData;  
  5.   
  6. var img_ld:Loader = new Loader;  
  7. img_ld.contentLoaderInfo.addEventListener(Event.COMPLETE,imgComplete);  
  8. img_ld.load(new URLRequest("image.png"));  
  9.   
  10. function imgComplete(e:Event):void{  
  11. var bmp:BitmapData = new BitmapData(e.target.content.width,e.target.content.height,true,0xFFFFFF);  
  12. bmp.draw(e.target.content);  
  13. var spr:MovieClip = new MovieClip;  
  14. var matrix = new flash.geom.Matrix();  
  15. matrix.rotate(Math.PI/4);  
  16. spr.graphics.beginBitmapFill(bmp,matrix,true,true);  
  17. spr.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);  
  18. spr.graphics.endFill();  
  19. addChild(spr);